/* --- GEM Chat: Unified Stylesheet (Floating & Shortcode) --- */

/* ===================================================================
   1. COMMON BASE & SHARED STYLES
   These styles apply to both chat UIs.
=================================================================== */

/* Base container for shared styles */
.gem-chat-ui {
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    overflow: hidden;
}

/* Chat Output Area */
.gem-chat-ui .gem-chat-output {
    flex-grow: 1;
    overflow-y: auto;
    background-color: #f9f9f9;
    padding: 15px;
    border: none;
    margin-bottom: 0;
}
.gem-chat-ui .gem-chat-output:after {
    content: ""; display: table; clear: both;
}

/* Individual Messages (User, Bot, Error) */
.gem-chat-ui .gem-chat-message {
    margin-bottom: 12px;
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 85%;
    line-height: 1.5;
    word-wrap: break-word;
    clear: both;
}
.gem-chat-ui .gem-chat-message-bot {
    background-color: #e9e9eb;
    color: #333;
    border-bottom-left-radius: 4px;
    float: left;
}
.gem-chat-ui .gem-chat-message-user {
    background-color: #007bff;
    color: white;
    border-bottom-right-radius: 4px;
    float: right;
}
.gem-chat-ui .gem-chat-message-error {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
    float: left;
}

/* Text Formatting inside Messages */
.gem-chat-ui .gem-chat-message-bot p,
.gem-chat-ui .gem-chat-message-bot ul,
.gem-chat-ui .gem-chat-message-bot ol,
.gem-chat-ui .gem-chat-message-bot h3,
.gem-chat-ui .gem-chat-message-bot h4 {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}
.gem-chat-ui .gem-chat-message-bot > *:first-child { margin-top: 0; }
.gem-chat-ui .gem-chat-message-bot > *:last-child { margin-bottom: 0; }
.gem-chat-ui .gem-chat-message-bot ul,
.gem-chat-ui .gem-chat-message-bot ol {
    padding-left: 5px; list-style-type: none;
}

/* Suggestions */
.gem-chat-ui .gem-chat-suggestion {
    cursor: pointer;
    display: inline-block;
    color: #183665;
    background-color: transparent;
    transition: all 0.2s ease;
    font-weight: 600;
}
.gem-chat-ui .gem-chat-suggestion:hover {
    color: #e31f26;
}

/* Input Area */
.gem-chat-ui .gem-chat-input-area {
    display: flex;
    padding: 10px;
    border-top: 1px solid #e5e5e5;
    background-color: #fff;
    gap: 10px;
}
.gem-chat-ui .gem-chat-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
    transition: border-color 0.2s;
}
.gem-chat-ui .gem-chat-input:focus {
    outline: none;
    border-color: #007bff;
}
.gem-chat-ui .gem-chat-send-button {
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    flex-shrink: 0; /* Prevents button from shrinking */
}
.gem-chat-ui .gem-chat-send-button:hover {
    background-color: #0056b3;
}
.gem-chat-ui .gem-chat-send-button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Typing Indicator */
.gem-chat-ui .typing-indicator-wrapper {
    padding: 12px 15px;
    display: inline-block;
}
.gem-chat-ui .typing-indicator span {
    height: 8px; width: 8px;
    background-color: #8d949e;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: gem-chat-typing-blink 1.4s infinite both;
}
.gem-chat-ui .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.gem-chat-ui .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes gem-chat-typing-blink {
    0% { opacity: 0.2; } 20% { opacity: 1; } 100% { opacity: 0.2; }
}


/* ===================================================================
   2. FLOATING CHAT SPECIFIC STYLES
=================================================================== */

#gem-floating-chat-toggle {
    position: fixed;
    bottom: 50px; right: 10px;
    background-color: #183665; color: white;
    width: 50px; height: 50px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 98;
    transition: transform 0.2s ease-in-out;
}
#gem-floating-chat-toggle:hover { transform: scale(1.1); }

#gem-floating-chat-container {
    position: fixed;
    bottom: 10px; right: 10px;
    width: 400px; max-width: 90vw;
    height: 450px; max-height: 90vh;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 99;
}
#gem-floating-chat-container.hidden { display: none; }
#gem-floating-chat-container .gem-chat-header {
    background-color: #0073aa; color: white;
    padding: 10px 15px;
    display: flex; justify-content: space-between; align-items: center;
}
/* Đoạn CSS mới, chung cho cả hai loại chat */
.gem-chat-header-controls {
    display: inline-flex; /* Dùng inline-flex để nằm cạnh logo */
    align-items: center; 
    gap: 15px;
    margin-left: 15px; /* Tạo khoảng cách với logo PVI */
}
.gem-chat-header-icon {
    cursor: pointer; 
    font-size: 20px; 
    font-weight: bold;
    line-height: 1; 
    transition: transform 0.2s ease, color 0.2s ease;
    color: white;
}
.gem-chat-header-icon:hover { 
    transform: scale(1.2); 
    color: #f0f0f0;
}
/* Style riêng cho nút đóng để to hơn một chút */
#gem-floating-chat-close, #gem-shortcode-chat-close { font-size: 24px; }

/* Fullscreen mode for floating chat */
#gem-floating-chat-container.fullscreen-mode {
    width: 100vw; height: 100vh;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 0;
    max-width: 100%; max-height: 100%;
    z-index: 100;
}


/* ===================================================================
   3. SHORTCODE CHAT SPECIFIC STYLES
=================================================================== */

.gem-chat-shortcode-box {
    background-color: #ffffff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    height: 70vh; /* Default height for inline box */
}
.gem-chat-body-no-scroll { overflow: hidden; }

/* Shortcode View Modes */
.gem-chat-shortcode-box.gem-chat-window-view {
    position: fixed; bottom: 20px; right: 20px;
    width: 400px; 
    height: 65vh; 
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    z-index: 999;
}

/* NEW: Fullscreen mode for shortcode chat */
.gem-chat-shortcode-box.gem-chat-fullscreen {
    position: fixed;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Mobile optimization */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0;
    max-width: 100%;
    max-height: 100%;
    z-index: 2147483647; /* Max Z-Index */
}


/* Shortcode Header */
.gem-chat-shortcode-header {
    background: linear-gradient(135deg, #00338D 0%, #005a87 100%);
    color: white; padding: 12px 18px;
    display: flex; justify-content: space-between; align-items: center;
}
.gem-chat-shortcode-box:not(.gem-chat-fullscreen) .gem-chat-shortcode-header {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}
.gem-chat-shortcode-header-left { display: flex; align-items: center; }
.gem-chat-header-logo {
    width: 40px; height: 40px; border-radius: 50%;
    margin-right: 12px; cursor: pointer;
    border: 2px solid rgba(255,255,255,0.5);
}
.gem-chat-header-title { margin: 0; font-size: 16px; font-weight: 600; }
.gem-chat-header-status { margin: 0; font-size: 13px; opacity: 0.9; }
.gem-chat-online-indicator {
    display: inline-block; width: 8px; height: 8px;
    background-color: #28a745; border-radius: 50%;
    margin-right: 5px;
}
.gem-chat-pvi-logo { max-height: 40px; width: auto; }

/* Shortcode send button SVG */
.gem-chat-shortcode-box .gem-chat-send-button svg {
    width: 20px; height: 20px; fill: white;
}

/* ===================================================================
   5. SHORTCODE WINDOW TOGGLE ICON STYLES
=================================================================== */

#gem-shortcode-window-toggle {
    /* display: none; /* Mặc định ẩn, JS sẽ điều khiển */
    position: fixed;
    bottom: 20px; /* Vị trí giống chat window */
    right: 20px;
    background-color: #183665; 
    color: white;
    width: 50px; 
    height: 50px;
    border-radius: 50%;
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: 24px; 
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 2147483647; /* Max Z-Index */
    transition: transform 0.2s ease-in-out;
}

#gem-shortcode-window-toggle:hover { 
    transform: scale(1.1); 
}

/* Utility class để ẩn phần tử một cách an toàn */
.gem-chat-hidden {
    display: none !important;
}

/* ===================================================================
   4. RESPONSIVE STYLES (Primarily for Floating Chat)
=================================================================== */
@media (max-width: 768px) {
    /* Make floating chat and shortcode window chat take over the screen on mobile */
    #gem-floating-chat-container:not(.fullscreen-mode),
    .gem-chat-shortcode-box.gem-chat-window-view {
        width: 100vw; 
        height: 100vh; 
        height: 100dvh; /* Dynamic Viewport Height for mobile */
        top: 0; left: 0; right: 0; bottom: 0;
        border-radius: 0; box-shadow: none;
        max-width: 100%; max-height: 100%;
        padding-bottom: env(safe-area-inset-bottom); /* iOS Home Bar fix */
        z-index: 2147483647; /* Max Z-Index */
    }
    
    /* Ensure shortcode window view is correctly positioned */
    .gem-chat-shortcode-box.gem-chat-window-view {
        position: fixed;
        z-index: 2147483647; /* Max Z-Index */
    }

    /* Prevent body from scrolling when mobile chat is open */
    body.gem-chat-body-no-scroll-mobile {
        overflow: hidden;
    }

    /* Unify toggle button positions for better UX */
	#gem-floating-chat-toggle,
	#gem-shortcode-window-toggle {
		bottom: 20px;
		right: 20px;
	}

    /* Hide zoom buttons on mobile as they are redundant */
    #gem-floating-chat-zoom, #gem-shortcode-chat-zoom {
        display: none;
    }

    /* Increase message width on mobile for better readability */
    .gem-chat-ui .gem-chat-message {
        max-width: 90%;
    }
}

/* ===================================================================
   6. CONTACT MENU STYLES (MULTI-CHANNEL WIDGET)
=================================================================== */
.gem-contact-menu {
    position: fixed;
    bottom: 80px; /* Above the toggle button */
    right: 20px;
    width: 300px;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.2);
    z-index: 1000;
    overflow: hidden;
    transform-origin: bottom right;
    animation: gem-menu-pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gem-contact-menu.hidden {
    display: none;
}

@keyframes gem-menu-pop-in {
    from { opacity: 0; transform: scale(0.8) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.gem-contact-header {
    background: linear-gradient(135deg, #00338D 0%, #005a87 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gem-contact-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.gem-contact-close {
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
}
.gem-contact-close:hover { opacity: 1; }

.gem-contact-list {
    padding: 10px;
}

.gem-contact-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 5px;
    border-radius: 8px;
    text-decoration: none;
    color: #333;
    transition: background-color 0.2s;
    cursor: pointer;
    border: 1px solid transparent;
}

.gem-contact-item:hover {
    background-color: #f5f7fa;
    border-color: #e1e4e8;
}

.gem-contact-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-right: 15px;
    background-color: #eee;
    border-radius: 50%;
    /* No emoji overlap */
}

.gem-contact-text {
    font-weight: 500;
    font-size: 15px;
}

/* Specific Colors for Channels */
.gem-zalo .gem-contact-icon { background-color: #E6F0FF; }
.gem-phone .gem-contact-icon { background-color: #E6FFEC; font-size: 18px; }
.gem-sms .gem-contact-icon { background-color: #FFF4E6; font-size: 18px; }
.gem-ai-chat .gem-contact-icon { background-color: #E6F4FF; font-size: 22px; }

/* Responsive for Mobile */
@media (max-width: 768px) {
    .gem-contact-menu {
        bottom: 80px;
        right: 10px;
        width: calc(100vw - 20px); /* Full width minus margins */
        max-width: 350px;
    }
}