/*
 * Stylesheet cho Chatbot Gemini.
 * Chứa các style chung, không thay đổi theo từng instance.
 * Các style động (width, height, color, position) được inject qua inline <style> trong PHP.
 */

/* Container chung cho tất cả các widget */
.chatbot-gemini-widget-container-custom {
    position: relative; /* Mặc định là relative cho shortcode widget */
    z-index: 9999; /* Z-index chung, có thể bị ghi đè */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    /* Các thuộc tính vị trí (bottom, right/left) sẽ được ghi đè bởi inline style cho default widget */
}

/* Container cho widget mặc định (fixed position) */
.default-widget-container {
    position: fixed; /* Bị ghi đè bởi inline style */
    z-index: 2147483647 !important; /* THAY ĐỔI: Tăng z-index của container mặc định lên giá trị tối đa để chắc chắn không bị che */
}

/* Container cho shortcode widget (inline/block element) */
.shortcode-widget-container {
    display: inline-block; /* Hoặc block, tùy thuộc vào cách bạn muốn nó hiển thị trong layout */
    /* Vị trí được xác định bởi vị trí của shortcode trong nội dung */
}


/* Nút bật tắt hộp chat (chỉ cho widget mặc định) */
.chatbot-gemini-toggle-button {
    background-color: #0073aa; /* Bị ghi đè bởi inline style */
    color: #fff;
    border: none;
    border-radius: 50%; /* Hình tròn */
    width: 60px;
    height: 60px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: background-color 0.3s ease, transform 0.3s ease;
    padding: 0;
    line-height: 1;
    flex-direction: column;
    z-index: 2147483647 !important; /* THAY ĐỔI: Z-index cao nhất */
    /* Vị trí tuyệt đối bên trong .default-widget-container */
    position: absolute;
    bottom: 0;
    right: 0; /* Bị ghi đè bởi inline style */
}

.chatbot-gemini-toggle-button:hover {
    background-color: #005a87; /* Bị ghi đè bởi inline style */
    transform: scale(1.05);
}

.chatbot-gemini-toggle-button .dashicons {
    font-size: 24px;
    margin-bottom: 2px;
}
.chatbot-gemini-toggle-button .chatbot-gemini-custom-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    margin-bottom: 2px;
}


/* Hộp chat chính */
.chatbot-gemini-widget {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    /* width và height sẽ được ghi đè bởi inline style */
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
    /* Vị trí ban đầu cho default widget (sẽ bị ghi đè) */
    position: absolute;
    bottom: calc(60px + 10px);
    right: 0;
    transform-origin: bottom right; /* Bị ghi đè bởi inline style cho responsive */
    z-index: 2147483647 !important; /* THAY ĐỔI: Z-index cao nhất, cùng với nút toggle */

    /* Thêm max-width và max-height để hạn chế kích thước trên màn hình lớn */
    max-width: 90vw; /* Không vượt quá 90% chiều rộng viewport */
    max-height: 90vh; /* Không vượt quá 90% chiều cao viewport */
}

/* Class để ẩn widget ban đầu bằng CSS */
.chatbot-gemini-widget.chatbot-gemini-initial-hide {
    display: none;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
}

/* Class để hiển thị shortcode widget ngay lập tức */
.chatbot-gemini-widget.chatbot-gemini-shortcode-initial-show {
    opacity: 1;
    transform: translateY(0) scale(1);
    display: flex;
    position: static; /* Đảm bảo nó không bị floating */
    z-index: auto; /* reset z-index */
}

.chatbot-gemini-widget.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    display: flex; /* Đảm bảo nó là flex khi visible */
}

.chatbot-gemini-widget.hidden { /* giữ lại hidden để JS có thể dùng nếu muốn ẩn hoàn toàn */
    display: none;
}


/* Header của hộp chat */
.chatbot-gemini-header {
    background-color: #0073aa; /* Bị ghi đè bởi inline style */
    color: #fff;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    flex-shrink: 0; /* Không cho phép shrink */
}

.bot-header-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    margin-right: 10px;
    object-fit: cover;
    border: 1px solid rgba(255,255,255,0.5);
}

.chatbot-gemini-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 500;
    color: #fff; /* Bị ghi đè bởi inline style */
    flex-grow: 1;
}

.chatbot-gemini-close-button {
    background: none;
    border: none;
    color: #fff; /* Bị ghi đè bởi inline style */
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
    transition: color 0.3s ease;
}

.chatbot-gemini-close-button:hover {
    color: #e0e0e0; /* Bị ghi đè bởi inline style */
}

.chatbot-gemini-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.chatbot-gemini-clear-button {
    background: none;
    border: none;
    color: #fff; /* Bị ghi đè bởi inline style */
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    transition: color 0.3s ease;
}
.chatbot-gemini-clear-button:hover {
    color: #e0e0e0; /* Bị ghi đè bởi inline style */
}

/* Body (khung hiển thị tin nhắn) */
.chatbot-gemini-body {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* font-size sẽ được ghi đè bởi inline style */
}

/* Định dạng tin nhắn chung */
.chatbot-gemini-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 0; /* Đã có gap ở container */
}
.message.user-message {
    justify-content: flex-end;
    flex-direction: row-reverse;
}
.message.bot-message {
    justify-content: flex-start;
    flex-direction: row;
}

.message-content-group {
    display: flex;
    flex-direction: column;
    max-width: calc(100% - 30px - 8px); /* Trừ đi chiều rộng avatar và gap */
    flex-grow: 1;
}
.message.user-message .message-content-group {
    align-items: flex-end;
}
.message.bot-message .message-content-group {
    align-items: flex-start;
}

.message-bubble {
    padding: 10px 15px;
    border-radius: 15px;
    word-break: break-word;
    word-wrap: break-word;
    max-width: 80%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* Định dạng tin nhắn của bot */
.message.bot-message .message-bubble {
    background-color: #e6f7ff;
    color: #333;
    border-bottom-left-radius: 0;
    align-self: flex-start;
}

/* Định dạng tin nhắn của người dùng */
.message.user-message .message-bubble {
    background-color: #0073aa; /* Bị ghi đè bởi inline style */
    color: #fff; /* Bị ghi đè bởi inline style */
    border-bottom-right-radius: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.bot-message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 5px;
}
.message.user-message .bot-message-avatar { display: none; }


.message-timestamp {
    font-size: 0.75em;
    color: #888;
    margin-top: 4px;
    white-space: nowrap;
}


/* Khu vực nhập liệu */
.chatbot-gemini-input-area {
    display: flex;
    padding: 10px 15px;
    border-top: 1px solid #eee;
    background-color: #fff;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.chatbot-gemini-input-area textarea {
    flex-grow: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 1em;
    outline: none;
    resize: none;
    overflow-y: auto;
    min-height: 40px;
    max-height: 120px;
}

.chatbot-gemini-input-area textarea:focus {
    border-color: #0073aa; /* Bị ghi đè bởi inline style */
}

.chatbot-gemini-send-button {
    background-color: #0073aa; /* Bị ghi đè bởi inline style */
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.3s ease;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
    overflow: hidden;
    position: relative;
}
.chatbot-gemini-send-button:hover {
    background-color: #005a87; /* Bị ghi đè bởi inline style */
}
.chatbot-gemini-send-button::before {
    font-family: dashicons;
    content: "\f474"; /* dashicons-arrow-right-alt2 (Mũi tên phải) */
    font-size: 20px;
    line-height: 1;
    color: #fff; /* Bị ghi đè bởi inline style */
    position: absolute;
    text-indent: 0;
}


.image-upload-button {
    cursor: pointer;
    background-color: transparent;
    color: #666;
    font-size: 20px;
    padding: 5px;
    line-height: 1;
    margin-right: 0;
    border-radius: 4px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}
.image-upload-button:hover {
    color: #0073aa; /* Bị ghi đè bởi inline style */
    background-color: transparent;
}
.image-upload-button .dashicons {
     color: inherit;
}

.chatbot-gemini-image-preview {
    display: flex;
    align-items: center;
    padding: 5px 15px;
    border-top: 1px solid #eee;
    background-color: #f0f0f0;
    gap: 10px;
    flex-shrink: 0;
    max-height: 110px; /* Slightly larger than image max-height + padding */
    overflow: hidden; /* Hide anything that overflows */
}
.chatbot-gemini-image-preview.hidden {
    display: none;
}

.chatbot-gemini-image-preview img {
    max-width: 100px;
    max-height: 100px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid #ccc;
    padding: 2px;
}

.remove-image-preview {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    margin-left: auto;
    padding: 0;
}
.remove-image-preview:hover {
    color: #333;
}


.user-message-image-wrapper {
    width: 150px;
    height: 150px;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    border-radius: 8px;
    background-color: rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 8px;
}
.user-message-image-wrapper img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}
.user-message-text-content {
    word-break: break-word;
    word-wrap: break-word;
    max-width: 100%;
    text-align: right;
}

/* Typing indicator */
.typing-indicator { display: flex; align-items: center; gap: 3px; padding: 8px 12px !important; min-height: 24px; }
.typing-indicator span { animation: bounce 1s infinite; opacity: 0.5; font-size: 24px; line-height: 1; }
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(-4px); opacity: 1; }
}

/* Markdown styling */
.chatbot-gemini-body p {
    margin-top: 0.8em;
    margin-bottom: 0.8em;
    word-break: break-word;
}
.chatbot-gemini-body p:first-child { margin-top: 0; }
.chatbot-gemini-body p:last-child { margin-bottom: 0; }


.chatbot-gemini-body strong {
    font-weight: 700;
    color: #000;
}
.chatbot-gemini-body em {
    font-style: italic;
    color: #555;
}
.chatbot-gemini-body a {
    color: #005a87; /* Bị ghi đè bởi inline style */
    text-decoration: underline;
    font-weight: normal;
}
.chatbot-gemini-body ul, .chatbot-gemini-body ol {
    padding-left: 25px;
    margin-top: 0.8em;
    margin-bottom: 0.8em;
    line-height: 1.4;
}
.chatbot-gemini-body ul {
    list-style-type: disc;
    list-style-position: outside;
}
.chatbot-gemini-body ol {
    list-style-type: decimal;
    list-style-position: outside;
}
.chatbot-gemini-body li {
    margin-bottom: 0.5em;
    padding-left: 5px;
}
.chatbot-gemini-body h3, .chatbot-gemini-body h4 {
    font-weight: bold;
    line-height: 1.3;
    margin-top: 1em;
    margin-bottom: 0.5em;
}
.chatbot-gemini-body h3 {
    font-size: 1.2em;
    color: #111;
}
.chatbot-gemini-body h4 {
    font-size: 1.1em;
    color: #222;
}
.chatbot-gemini-body blockquote {
    border-left: 4px solid #0073aa; /* Bị ghi đè bởi inline style */
    margin: 0.8em 0;
    padding: 0.5em 15px;
    color: #555;
    font-style: italic;
    background-color: #f0f0f0; /* Bị ghi đè bởi inline style */
    border-radius: 0 5px 5px 0;
}
.chatbot-gemini-body blockquote p {
    margin: 0;
}

/* Handover buttons */
.handover-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 15px;
    padding: 5px 0;
    border-top: 1px dashed #e0e0e0;
    width: 100%;
    align-self: flex-start;
}
.handover-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 15px;
    background-color: #0073aa; /* Bị ghi đè bởi inline style */
    color: #fff !important;
    border: none;
    border-radius: 5px;
    text-decoration: none !important;
    font-weight: 600;
    transition: background-color 0.2s ease;
}
.handover-button:hover {
    background-color: #005a87; /* Bị ghi đè bởi inline style */
    color: #fff !important;
}
.handover-button .dashicons {
    margin-right: 8px;
    font-size: 18px;
    color: #fff; /* Bị ghi đè bởi inline style */
}
.handover-button .channel-icon {
    margin-right: 8px;
    width: 24px;
    height: 24px;
    vertical-align: middle;
}

/* Branding */
.chatbot-gemini-branding {
    flex-shrink: 0;
    padding: 5px 15px;
    background-color: #f0f0f0;
    font-size: 0.75em;
    text-align: center;
    border-top: 1px solid #eee;
    color: #777;
}
.chatbot-gemini-branding.hidden {
    display: none;
}
.chatbot-gemini-branding a {
    color: #777;
    text-decoration: none;
}
.chatbot-gemini-branding a:hover {
    text-decoration: underline;
}

/* Responsive cho màn hình nhỏ (chỉ áp dụng các quy tắc chung, các giá trị động đã ở inline style) */
@media (max-width: 768px) {
    /* Các quy tắc cụ thể cho default-widget-container sẽ ở inline style */
    .chatbot-gemini-toggle-button {
        width: 50px;
        height: 50px;
        font-size: 14px;
        z-index: 2147483647 !important; /* THAY ĐỔI: Tăng z-index của nút bật tắt lên cao nhất */
        /* Đảm bảo nút nằm trên cùng so với widget */
    }
    .chatbot-gemini-toggle-button .dashicons {
        font-size: 20px;
    }
    .chatbot-gemini-toggle-button .chatbot-gemini-custom-icon {
        width: 20px;
        height: 20px;
    }
    .chatbot-gemini-widget {
        transform-origin: center bottom !important; /* THAY ĐỔI: Đổi gốc transform cho hiệu ứng mở/đóng trên mobile */
        z-index: 2147483647 !important; /* THAY ĐỔI: Z-index cao nhất, cùng với nút toggle */
        position: fixed !important; /* Đảm bảo nó luôn fixed trên mobile */
        
        /* Đảm bảo chiếm toàn bộ chiều rộng/chiều cao khả dụng trên mobile */
        top: 15px !important; 
        left: 10px !important;
        right: 10px !important;
        bottom: auto !important; /* Không cố định bottom */
        width: calc(100% - 20px) !important;
        height: calc(100vh - 85px - var(--wp-toolbar-height, 0px)) !important; /* Adjust height for full screen, consider admin bar */
        
        opacity: 0 !important; /* Đảm bảo nó bị ẩn ban đầu */
        transform: translateY(20px) scale(0.95) !important; /* Đảm bảo nó bị biến đổi ban đầu */
        transition: opacity 0.3s ease, transform 0.3s ease !important; /* Đảm bảo transition hoạt động */
    }
    /* Đảm bảo widget hiển thị đúng khi mở trên mobile */
    .chatbot-gemini-widget.visible {
        display: flex !important; /* Luôn hiển thị flex khi visible trên mobile */
        opacity: 1 !important; /* Đảm bảo opacity 1 khi visible */
        transform: translateY(0) scale(1) !important; /* Đảm bảo transform về trạng thái ban đầu khi visible */
    }
    .chatbot-gemini-body {
        /* Điều chỉnh padding hoặc kích thước font nếu cần */
        padding: 10px; /* Nhỏ hơn một chút trên mobile */
    }
}