/* Container */
#custom_chatbot {
    width: 100%;
    max-width: 100%;
    height: 500px;
    border: 1px solid #ccc;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    font-family: 'Tahoma', sans-serif;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    direction: rtl;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

/* Header */
#chat_header {
    background: linear-gradient(90deg, #9853b4, #ed76b3);
    color: #fff;
    padding: 12px;
    font-weight: bold;
    text-align: center;
}

/* Body */
#chat_body {
    flex: 1;
    padding: 10px;
    background: #f9f9f9;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

#chat_output::after {
    content: "";
    display: block;
    clear: both;
}

/* Messages */
#chat_output .user_msg,
#chat_output .bot_msg {
    margin-bottom: 10px;
    padding: 8px 12px;
    border-radius: 15px;
    max-width: 80%;
    clear: both;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 14px;
}

#chat_output .user_msg {
    background: #a528d4;
    color: #fff;
    float: right;
    text-align: right;
}

#chat_output .bot_msg {
    background: #e4e6eb;
    color: #333;
    float: left;
    text-align: right;
}

#chat_output .bot_msg a {
    color: #5e4b82;
    text-decoration: underline;
    word-break: break-all;
}

/* Typing indicator */
#chat_output .bot_msg.ccbot-typing {
    opacity: 0.9;
    font-style: italic;
    position: relative;
}

#chat_output .bot_msg.ccbot-typing::after {
    content: " ...";
    display: inline-block;
    animation: ccbot-blink 1.5s ease-in-out infinite;
}

@keyframes ccbot-blink {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 1; }
}

/* Input area */
#chat_input_area {
    display: flex;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid #ccc;
    background: #fff;
}

#chat_input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    resize: vertical;
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid #ccc;
    outline: none;
    font-size: 14px;
}

/* Send button */
#send_btn {
    background: #5b3497;
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 0 15px;
    cursor: pointer;
    font-weight: bold;
    transition: background .25s ease, opacity .2s ease;
}

#send_btn:hover {
    background: #3b3fc4;
}

#send_btn.is-loading,
#send_btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#send_btn:focus-visible,
#chat_input:focus-visible {
    outline: 2px solid #3b3fc4;
    outline-offset: 2px;
}

/* Mobile tweaks */
@media (max-width: 480px) {
    #custom_chatbot {
        height: 65vh;
        max-width: 100%;
        border-radius: 12px;
    }
    #chat_output .user_msg,
    #chat_output .bot_msg {
        max-width: 90%;
        font-size: 13px;
    }
}

/* --- Course cards in bot message --- */
#chat_output .bot_msg .ccbot-answer {
    margin-bottom: 8px;
}

#chat_output .bot_msg .ccbot-courses {
    margin-top: 6px;
    display: grid;
    grid-template-columns: 1 1;
    gap: 8px;
}

#chat_output .bot_msg .ccbot-course {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 8px;
}

#chat_output .bot_msg .ccbot-course-thumb {
    display: inline-block;
    width: 80px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 6px;
}

#chat_output .bot_msg .ccbot-course-thumb img {
    width: 100%;
    height: auto;
    display: block;
    margin-top: 5px;
}

#chat_output .bot_msg .ccbot-course-title {
    font-weight: 500;
    font-size: 12px;
    line-height: 1.5;
    display: inline-block;
    width: calc(100% - 90px);
    margin-bottom: 6px;
    float: left;
    height: 90px;
    align-content: center;
    justify-items: anchor-center;
}

#chat_output .bot_msg .ccbot-course-title a {
    text-decoration: none;
    border-bottom: 1px dashed transparent;
    display: block;
}

#chat_output .bot_msg .ccbot-course-title a:hover {
    border-bottom-color: #4e54c8;
}

#chat_output .bot_msg .ccbot-course-btn {
    display: inline-block;
    padding: 4px;
    font-size: 12px;
    border-radius: 8px;
    background: #a157b4;
    color: #fff;
    text-decoration: none;
    width: 50%;
    text-align: center;
    margin-top: 10px;
    font-size: 11px;
    font-weight: 300;

}

#chat_output .bot_msg .ccbot-course-btn:hover {
    background: #3b3fc4;
}

/* Single column on narrow phones */
@media (max-width: 420px) {
    #chat_output .bot_msg .ccbot-courses {
        grid-template-columns: 1;
    }
}
