.ai-result-container {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    padding: 30px;
    margin-top: 30px;
    box-shadow: 0 20px 60px rgba(102, 126, 234, 0.3);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    color: white;
}

.result-header h3 {
    font-size: 1.8rem;
    font-weight: 800;
    margin: 0;
}

.btn-save-plan {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid white;
    color: white;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 600;
    transition: all 0.3s;
    cursor: pointer;
}

.btn-save-plan:hover {
    background: white;
    color: #667eea;
}

.result-content {
    background: white;
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.chat-section {
    background: white;
    border-radius: 16px;
    padding: 25px;
    margin-top: 20px;
}

.chat-header {
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.chat-header h5 {
    margin: 0;
    font-weight: 700;
    color: #333;
}

.chat-messages {
    max-height: 400px;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 12px;
    margin-bottom: 20px;
}

.chat-message {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
}

.chat-message.user {
    justify-content: flex-end;
    /* Align right */
}

.chat-message.ai {
    justify-content: flex-start;
    /* Align left */
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    min-width: 0;
}

.chat-message.user .message-wrapper {
    align-items: flex-end;
}

.chat-message.ai .message-wrapper {
    align-items: flex-start;
}

.message-bubble {
    padding: 12px 18px;
    border-radius: 18px;
    position: relative;
    line-height: 1.5;
    word-break: break-word;
    /* Prevent overflow */
    max-width: 100%;
}

.chat-message.user .message-bubble {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.ai .message-bubble {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.message-actions {
    display: flex;
    flex-direction: column;
    /* Stack buttons vertically */
    gap: 8px;
    /* Increase gap */
    margin-top: 8px;
    width: 100%;
    /* Full width of wrapper */
}

.btn-use-message {
    background: #f0f0f0;
    border: none;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    color: #666;
}

.btn-use-message:hover {
    background: #667eea;
    color: white;
}

.chat-input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 100%;
}

.chat-input {
    flex: 1;
    min-width: 0;
    border-radius: 12px;
    border: 2px solid #e0e0e0;
    padding: 12px;
    resize: none;
    transition: border 0.3s;
}

.chat-input:focus {
    border-color: #667eea;
    outline: none;
}

.chat-input-container .btn {
    border-radius: 12px;
    padding: 12px 24px;
    font-weight: 600;
}

.chat-action-btn {
    overflow-wrap: anywhere;
}

.message-actions .d-flex {
    max-width: 100%;
    min-width: 0;
}

.message-actions .btn-use-message {
    max-width: 100%;
}

@media (min-width: 576px) {
    /* WHY: Step 2 chat buttons use a Bootstrap responsive width utility that is not available in v5.1, so restore desktop auto sizing to keep the input visible. */
    .chat-input-container .btn {
        width: auto !important;
        flex: 0 0 auto;
        padding: 10px 16px;
        font-size: 0.875rem;
        line-height: 1.25;
    }
}

@media (max-width: 767.98px) {
    .result-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .message-wrapper {
        max-width: 85%;
    }

    .chat-input-container {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-input-container textarea,
    .chat-input-container .btn {
        width: 100%;
    }

    .chat-input-container .btn {
        min-height: 44px;
        white-space: normal !important;
        padding: 12px 16px;
    }

    .message-actions .d-flex {
        flex-direction: column;
        align-items: stretch;
    }

    .message-actions .btn-use-message {
        width: 100%;
        white-space: normal !important;
        overflow-wrap: anywhere;
        text-align: left;
    }
}
