/**
 * SkyBot Chatbot Pro - Frontend Styles
 * Version: 10.4.1
 *
 * This version includes a more robust positioning context to prevent
 * the chatbot from moving to the wrong corner of the screen.
 */

/* --- Main Variables & Container --- */
:root {
    --skybot-header-color: #007bff;
    --skybot-user-msg-color: #007bff;
    --skybot-icon-bottom-spacing: 25px; /* Default value */
    --skybot-icon-right-spacing: 25px; /* Default value */
}

/* This is the main fixed container that holds all chatbot elements */
#skybot-root {
    position: fixed;
    bottom: var(--skybot-icon-bottom-spacing);
    right: var(--skybot-icon-right-spacing);
    z-index: 10000;
}

#chatbot-container {
    position: relative;
}

#chatbot-icon {
    background: var(--skybot-header-color);
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
#chatbot-icon:hover { 
    transform: scale(1.1); 
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3); 
}
#chatbot-icon svg { 
    width: 32px; 
    height: 32px; 
}

#chatbot-window {
    position: absolute; /* Positioned relative to the #skybot-root container */
    bottom: 75px;
    right: 0;
    width: 370px;
    max-width: 90vw;
    height: 550px;
    max-height: calc(100vh - 120px);
    background-color: #ffffff;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: opacity 0.3s ease, transform 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#chatbot-window.hidden { 
    opacity: 0; 
    transform: scale(0.8); 
    pointer-events: none; 
}

/* --- Header --- */
#chatbot-header {
    background: var(--skybot-header-color);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: center; /* Center title by default */
    align-items: center;
    position: relative;
    flex-shrink: 0;
}
#chatbot-header h3 { 
    margin: 0; 
    font-size: 1.2rem; 
    font-weight: 600; 
}
#chatbot-header-menu-toggle {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
}
#chatbot-header-actions { 
    display: flex; 
    align-items: center; 
    position: absolute; 
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
}
#chatbot-header-actions button {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#chatbot-header-actions button:hover { 
    opacity: 1; 
}
#chatbot-header-actions button#chatbot-end-chat-btn {
    font-size: 28px;
}

#chatbot-header-menu {
    position: absolute;
    top: 55px;
    left: 10px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    padding: 0.5rem 0;
    z-index: 100;
    width: 200px;
}
#chatbot-header-menu button {
    display: block;
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    color: #333;
    text-align: left;
    font-size: 1rem;
    cursor: pointer;
}
#chatbot-header-menu button:hover {
    background-color: #f5f5f5;
}

/* --- Views (Email, Chat, Survey) --- */
.chatbot-view {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: #fff;
}
.hidden { display: none !important; }

/* Email Capture View */
#chatbot-email-capture { 
    padding: 2rem 1.5rem; 
    text-align: center; 
    justify-content: center; 
}
#chatbot-email-capture h4 { font-size: 1.5rem; margin: 0 0 0.5rem 0; color: #333; }
#chatbot-email-capture p { margin: 0 0 1.5rem 0; color: #666; }
#chatbot-email-input { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 8px; margin-bottom: 1rem; font-size: 1rem; box-sizing: border-box; }
#chatbot-start-chat-btn { width: 100%; padding: 12px; border: none; border-radius: 8px; background-color: var(--skybot-header-color); color: white; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background-color 0.2s; }
#chatbot-email-error { color: #dc3545; font-size: 0.9rem; margin-top: 0.5rem; height: 1em; }

/* Conversation View */
#chatbot-conversation-view { 
    overflow: hidden; 
}
#chatbot-messages { 
    flex-grow: 1; 
    padding: 1rem; 
    overflow-y: auto; 
    background-color: #f9f9f9; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
}
.chat-message { 
    padding: 10px 15px; 
    border-radius: 18px; 
    max-width: 85%; 
    line-height: 1.5; 
    word-wrap: break-word; 
}
.user-message { 
    background-color: var(--skybot-user-msg-color); 
    color: white; 
    align-self: flex-end; 
    border-bottom-right-radius: 4px; 
}
.bot-message { 
    background-color: #e9ecef; 
    color: #333; 
    align-self: flex-start; 
    border-bottom-left-radius: 4px; 
}
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 15px;
}
.typing-indicator span { 
    width: 8px; 
    height: 8px; 
    background-color: #ccc; 
    border-radius: 50%; 
    animation: typing-bounce 1.4s infinite ease-in-out both; 
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

#chatbot-input-container { 
    display: flex; 
    padding: 1rem; 
    border-top: 1px solid #ddd; 
    background-color: #fff; 
    align-items: center; 
    flex-shrink: 0;
}
#chatbot-input { 
    flex-grow: 1; 
    border: 1px solid #ccc; 
    border-radius: 20px; 
    padding: 10px 15px; 
    font-size: 1rem; 
    outline: none; 
    transition: border-color 0.2s; 
}
#chatbot-input:focus { 
    border-color: var(--skybot-header-color); 
}
#chatbot-send-btn { 
    background-color: var(--skybot-header-color); 
    color: #fff; 
    border: none; 
    border-radius: 50%; 
    width: 40px; 
    height: 40px; 
    margin-left: 10px; 
    cursor: pointer; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    transition: background-color 0.2s; 
    flex-shrink: 0;
}
#chatbot-send-btn:hover { 
    opacity: 0.8; 
}
#chatbot-send-btn svg { 
    width: 20px; 
    height: 20px; 
}

/* Survey View */
#chatbot-survey-view { 
    padding: 2rem 1.5rem; 
    text-align: center; 
    justify-content: center; 
}
#chatbot-survey-view h4 { font-size: 1.2rem; margin: 0 0 1rem 0; color: #333; }
#chatbot-survey-actions { display: flex; justify-content: center; gap: 1rem; margin-bottom: 1rem; }
.survey-thumb-btn { background: none; border: none; cursor: pointer; font-size: 36px; transition: transform 0.2s; }
.survey-thumb-btn:hover { transform: scale(1.2); }
#chatbot-survey-view p { color: #666; visibility: hidden; }
#chatbot-back-to-chat-btn {
    background: none;
    border: none;
    color: #666;
    text-decoration: underline;
    cursor: pointer;
    margin-top: 1rem;
    font-size: 0.9em;
}

/* Disclaimer */
#chatbot-disclaimer {
    text-align: center;
    padding: 0.5rem 1rem;
    font-size: 0.8em;
    color: #888;
    background-color: #f9f9f9;
    border-top: 1px solid #ddd;
    flex-shrink: 0;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 480px) {
    #skybot-root {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
    }
    #chatbot-window {
        width: 100%;
        height: 100%;
        border-radius: 0;
        right: 0;
        bottom: 0;
    }
    #chatbot-icon {
        position: fixed; /* Keep icon in corner even when window is open */
        bottom: 20px;
        right: 20px;
        z-index: 10001; /* Above the fullscreen window */
    }
    #chatbot-window.hidden + #chatbot-container #chatbot-icon {
        position: static; /* Let icon return to normal flow when window is closed */
    }
}

