/* Messages App */
.messages-list {
    padding: 0;
    margin-bottom: 0;

    .message-item {
        display: flex;
        align-items: center;
        padding: 15px 20px;
        border-bottom: 1px solid var(--border-color);
        cursor: pointer;
        transition: background-color 0.2s;
        background: var(--bg-primary);

        &:hover {
            background-color: var(--bg-secondary);
        }

        .message-avatar {
            width: 50px;
            height: 50px;
            border-radius: 25px;
            background: linear-gradient(45deg, #34c759, #30d158);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            margin-right: 15px;
            font-size: 16px;
        }

        .message-content {
            flex: 1;

            .message-header {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-bottom: 4px;

                .contact-name {
                    font-size: 16px;
                    font-weight: 600;
                    color: var(--text-primary);
                }

                .message-time {
                    font-size: 12px;
                    color: var(--text-secondary);
                }
            }

            .message-preview {
                display: flex;
                justify-content: space-between;
                align-items: center;

                p {
                    font-size: 14px;
                    color: var(--text-secondary);
                    margin: 0;
                    flex: 1;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }

                .unread-badge {
                    background: #ff3b30;
                    color: white;
                    border-radius: 10px;
                    padding: 2px 6px;
                    font-size: 12px;
                    font-weight: bold;
                    min-width: 18px;
                    text-align: center;
                    margin-left: 8px;
                }
            }
        }
    }
}

/* Conversation View */
.conversation-view {
    height: 100%;
    display: flex;
    flex-direction: column;
    margin-bottom: 25px;
    overflow: hidden;

    .conversation-header {
        background: #34c759;
        color: white;
        padding: 15px 20px;
        display: flex;
        align-items: center;
        gap: 15px;
        flex-shrink: 0;

        .back-button {
            background: none;
            border: none;
            color: white;
            font-size: 16px;
            cursor: pointer;
            padding: 5px 10px;
            border-radius: 4px;
            transition: background-color 0.2s;

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

        h2 {
            font-size: 18px;
            font-weight: 600;
        }
    }

    .messages-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        box-sizing: border-box;
        overflow-y: auto;
        overflow-x: hidden;
        min-height: 0;
        /* Force hardware acceleration for smoother scrolling */
        transform: translateZ(0);
        -webkit-overflow-scrolling: touch;
        /* Hide scrollbar but keep functionality */
        scrollbar-width: none !important;
        /* scrollbar-color: rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.1); */

        /* Ultra-thin scrollbar for webkit browsers */
        /* &::-webkit-scrollbar {
            width: 2px;
            height: 2px;
        }

        &::-webkit-scrollbar-track {
            background: rgba(0, 0, 0, 0.1);
            border-radius: 1px;
        }

        &::-webkit-scrollbar-thumb {
            background: rgba(0, 0, 0, 0.3);
            border-radius: 1px;
            min-height: 20px;

            &:hover {
                background: rgba(0, 0, 0, 0.5);
            }
        } */

        .message-bubble {
            max-width: 70%;
            padding: 12px 16px;
            border-radius: 18px;
            position: relative;
            word-wrap: break-word;
            flex-shrink: 0;
            margin-bottom: 8px;

            &.user {
                background: var(--message-bubble-user);
                color: var(--message-text-user);
                align-self: flex-end;
                border-bottom-right-radius: 4px;
            }

            &.contact {
                background: var(--message-bubble-contact);
                color: var(--message-text-contact);
                align-self: flex-start;
                border-bottom-left-radius: 4px;
            }

            p {
                margin: 0 0 4px 0;
                font-size: 16px;
                line-height: 1.4;
            }

            .message-timestamp {
                font-size: 11px;
                opacity: 0.7;
                display: block;
                margin-top: 4px;
            }
        }
    }

    .message-input-form {
        background: rgba(255, 255, 255, 0.15);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
        display: flex;
        align-items: center;
        padding: 8px;
        flex-shrink: 0;
        margin-bottom: 0;
        position: absolute;
        bottom: 32px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 24px);
        border-radius: 20px;

        .message-input {
            flex: 1;
            padding: 10px 16px;
            border: none;
            border-radius: 18px;
            font-size: 16px;
            outline: none;
            background: #eee;
            color: var(--text-primary);
            min-height: 36px;
            max-height: 120px;
            line-height: 1.4;
            resize: none;
            overflow-y: auto;
            box-shadow: none;
            transition: background-color 0.2s;
            font-family: inherit;

            &:focus {
                background: #f8f8f8;
            }

            &::placeholder {
                color: var(--text-secondary);
                opacity: 0.7;
            }
        }

        .send-button {
            width: 40px !important;
            height: 40px !important;
            border-radius: 50%;
            background: var(--accent-color);
            color: white;
            border: none;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
            box-shadow: 0 2px 8px rgba(0, 122, 255, 0.2);
            transition: all 0.2s ease;
            flex-shrink: 0;
            padding: 0;
            margin-left: 8px !important;
            cursor: pointer;

            &:hover {
                transform: scale(1.05);
                box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
            }

            &:active {
                transform: scale(0.95);
            }

            svg {
                display: block;
                width: 22px;
                height: 22px;
                stroke: currentColor;
            }

            img {
                display: block;
                width: 22px;
                height: 22px;
                pointer-events: none;
            }
        }
    }
}

/* Dark theme adjustments */
[data-theme="dark"] {
    .conversation-view {
        .messages-container {
            scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1);

            &::-webkit-scrollbar-track {
                background: rgba(255, 255, 255, 0.1);
            }

            &::-webkit-scrollbar-thumb {
                background: rgba(255, 255, 255, 0.3);

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

    .message-input-form {
        background: rgba(0, 0, 0, 0.25);
        border: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);

        .message-input {
            background: rgba(255, 255, 255, 0.05);
            color: var(--text-primary);

            &:focus {
                background: rgba(255, 255, 255, 0.08);
            }
        }
    }
}