/**
 * SkyBot Chatbot Pro - Frontend Styles
 * Version: 22.4.2
 */

/* --- Main Variables & Root Container --- */
:root {
    --skybot-header-color: #007bff;
    --skybot-user-msg-color: #007bff;
    --skybot-icon-bottom-spacing: 25px;
    --skybot-icon-right-spacing: 25px;
}

#skybot-root {
    position: fixed;
    bottom: var(--skybot-icon-bottom-spacing);
    right: var(--skybot-icon-right-spacing);
    z-index: 10000;
    display: flex;
    flex-direction: column; /* This correctly places the teaser above the icon */
    align-items: flex-end;
    gap: 15px;
}

/* --- Chatbot Window & Core Layout --- */
#skybot-root #chatbot-window {
    position: absolute; /* Takes the window out of the flex flow to allow overlapping */
    bottom: 65px; /* MODIFIED: Raised to show icon underneath */
    right: 0;         /* Positions the window at the right of the root container */
    width: 370px;
    height: 550px;
    max-width: 90vw;
    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: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    z-index: 2; /* Ensures window is above the icon */
}
#skybot-root #chatbot-window.hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}
#skybot-root #chatbot-window.is-expanded {
    position: fixed;
    top: 2.5vh; /* MODIFIED: Adjusted top position to keep it centered */
    right: 25px;
    bottom: 80px; /* MODIFIED: Set bottom to ensure icon is visible */
    height: auto; /* MODIFIED: Height is now flexible */
    max-height: none; /* MODIFIED: Max-height is removed for flexible height */
}
#skybot-root .chatbot-view {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Header --- */
#skybot-root #chatbot-header {
    background: var(--skybot-header-color);
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#skybot-root #chatbot-header-left,
#skybot-root #chatbot-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
#skybot-root #chatbot-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}
#skybot-root #chatbot-header button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
    padding: 0.25rem;
    display:flex;
}
#skybot-root #chatbot-header button:hover {
    opacity: 1;
}
#skybot-root #chatbot-header-menu {
    position: absolute;
    top: 45px;
    left: 1rem;
    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;
}
#skybot-root #chatbot-header-menu button {
    width: 100%;
    padding: 0.75rem 1.5rem;
    color: #333;
    text-align: left;
    font-size: 1rem;
}
#skybot-root #chatbot-expand-btn .icon-compress {
    display: none;
}
#skybot-root #chatbot-window.is-expanded #chatbot-expand-btn .icon-expand {
    display: none;
}
#skybot-root #chatbot-window.is-expanded #chatbot-expand-btn .icon-compress {
    display: block;
}

/* --- Message Area --- */
#skybot-root #chatbot-messages {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    background-color: #f9f9f9;
}
#skybot-root .message-wrapper {
    display: flex;
    flex-direction: column;
    margin-bottom: 4px;
}
#skybot-root .bot-message-wrapper {
    align-items: flex-start;
}
#skybot-root .user-message-wrapper {
    align-items: flex-end;
}
#skybot-root .chat-message {
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 85%;
    line-height: 1.5;
    word-wrap: break-word;
}
#skybot-root .user-message {
    background-color: var(--skybot-user-msg-color);
    color: white;
    border-bottom-right-radius: 4px;
}
#skybot-root .bot-message {
    background-color: #e9ecef;
    color: #333;
    border-bottom-left-radius: 4px;
}
#skybot-root .system-message {
    align-self: center;
    background-color: #fff;
    border: 1px dashed #ccc;
    color: #555;
    font-size: 0.9em;
    text-align: center;
    max-width: 90%;
    padding: 8px 12px;
    border-radius: 8px;
    margin: 8px 0;
}

/* This was the original .bot-message a selector. It's now updated. */
#skybot-root .bot-message a {
    color: var(--skybot-header-color) !important; /* Makes links use your main brand color */
    text-decoration: underline !important;      /* Adds the underline */
    font-weight: 500 !important;                /* Makes links slightly bolder */
}

#skybot-root .message-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    margin-left: 10px;
}
#skybot-root .message-actions button {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #666;
    transition: all 0.2s;
}
#skybot-root .message-actions button:hover {
    background: #f5f5f5;
    color: #333;
    border-color: #ccc;
}
#skybot-root .message-actions button.selected {
    background-color: var(--skybot-header-color);
    color: white;
    border-color: var(--skybot-header-color);
}
#skybot-root .message-actions button.selected svg {
    stroke: white;
}
#skybot-root .message-actions svg {
    width: 16px;
    height: 16px;
}

/* --- MODIFIED: ADDED TTS BUTTON STYLES --- */
#skybot-root .message-actions .skybot-read-aloud-btn {
    /* Styles are inherited from .message-actions button */
}
#skybot-root .message-actions .skybot-read-aloud-btn.is-speaking {
    background-color: var(--skybot-header-color);
    color: white;
    border-color: var(--skybot-header-color);
}
#skybot-root .message-actions .skybot-read-aloud-btn.is-speaking svg {
    stroke: white;
}
/* --- END OF MODIFICATION --- */


#skybot-root #typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 15px;
}
#skybot-root .typing-dot {
    width: 8px;
    height: 8px;
    background-color: #ccc;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}
#skybot-root .typing-dot:nth-child(1) { animation-delay: -0.32s; }
#skybot-root .typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing-bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }


/* --- Input Area --- */
#skybot-root #chatbot-input-container {
    display: flex;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid #ddd;
    background-color: #fff;
    align-items: flex-end;
    gap: 0.5rem;
}
#skybot-root #chatbot-input-actions {
    display: flex;
    align-items: center;
    padding-bottom: 5px; /* Aligns with textarea padding */
}
#skybot-root #chatbot-attachment-btn,
#skybot-root #chatbot-mic-btn {
    color: #888;
    transition: color 0.2s;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
}
#skybot-root #chatbot-attachment-btn:hover,
#skybot-root #chatbot-mic-btn:hover {
    color: #333;
}
#skybot-root #chatbot-input {
    flex-grow: 1;
    border: none; /* MODIFIED: Removed the border causing the vertical line */
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 1rem;
    line-height: 1.4;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    background-color: #f0f2f5; /* ADDED: A subtle background to the input */
}
#skybot-root #chatbot-send-btn {
    background-color: var(--skybot-header-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}
#skybot-root #chatbot-send-btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Smart Reply Styles --- */
#skybot-root #chatbot-smart-reply-container {
    padding: 0 1rem 0.75rem;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    background-color: #f9f9f9;
}
#skybot-root .smart-reply-btn {
    background-color: #ffffff;
    border: 1px solid #dcdfe3;
    color: #333;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
#skybot-root .smart-reply-btn:hover {
    background-color: #f0f2f5;
    border-color: #c8ced4;
    transform: translateY(-1px);
}

/* --- New: Email Prompt Form Styles --- */
#skybot-email-prompt-form {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}
#skybot-email-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 8px 10px;
    font-size: 0.95rem;
}
#skybot-email-submit-btn {
    background-color: var(--skybot-header-color);
    color: #fff;
    border: none;
    border-radius: 5px;
    padding: 8px 15px;
    cursor: pointer;
    font-weight: 500;
    transition: opacity 0.2s;
}
#skybot-email-submit-btn:hover {
    opacity: 0.85;
}


/* --- Icon & Teaser --- */
#chatbot-container {
    position: relative;
    z-index: 1;
    transition: opacity 0.3s ease;
}

#skybot-root #chatbot-icon {
    background: var(--skybot-header-color);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
#skybot-root #chatbot-icon svg {
    width: 28px;
    height: 28px;
}

/* --- UPDATED TEASER STYLES --- */
#skybot-root #chatbot-proactive-teaser {
    position: relative;
    background-color: #fff;
    color: #333;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 1.25rem;
    width: 280px;
    cursor: pointer;
    line-height: 1.5;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}
#skybot-root #chatbot-proactive-teaser:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}
#skybot-root #chatbot-proactive-teaser::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 24px; /* Aligns with the center of the icon below */
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #fff; /* Matches the teaser background */
}
#skybot-root #chatbot-teaser-close-btn {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    font-size: 22px;
    font-weight: 300;
    line-height: 1;
    color: #b0b0b0;
    transition: color 0.2s;
}
#skybot-root #chatbot-teaser-close-btn:hover {
    color: #333;
}


/* --- Utility & Shortcode --- */
#skybot-root .hidden {
    display: none !important;
}
.skybot-shortcode-wrapper {
    background-color: #f0f4f9;
    border: 1px solid #d1dce8;
    border-radius: 12px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 2em 0;
}
.skybot-shortcode-input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 1rem;
    min-height: 80px;
    resize: vertical;
}
.skybot-shortcode-button {
    background-color: var(--skybot-header-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    align-self: flex-start;
}
.skybot-shortcode-button:hover {
    opacity: 0.85;
}


/* --- Mobile --- */
@media (max-width: 480px) {
    #skybot-root {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        gap: 0;
        pointer-events: none;
    }
    #skybot-root > * {
        pointer-events: auto;
    }
    #skybot-root #chatbot-window {
        width: 100%;
        height: 100%;
        border-radius: 0;
        right: 0;
        bottom: 0;
    }
    #skybot-root #chatbot-window.is-expanded {
        top: 0;
        right: 0;
    }
    #skybot-root #chatbot-icon {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 10001;
    }
    #skybot-root #chatbot-window.hidden + #chatbot-container #chatbot-icon {
        position: static;
    }
    #skybot-root #chatbot-proactive-teaser {
        display: none !important;
    }
}

/* --- ADDED: Voice Input Active State --- */
#skybot-root #chatbot-mic-btn.is-listening {
    color: #ff4136; /* Red to indicate recording */
}

/* --- CLICKABLE LINK FIX --- */
/* This ensures all links in bot messages are clickable and styled correctly */
#skybot-root .bot-message a:hover {
    opacity: 0.8; /* Adds a nice hover effect */
}