/**
 * SkyBot Chatbot Pro - Frontend Styles
 * Version: 22.4.2 (Modernized)
 */

/* --- Main Variables & Root Container --- */
:root {
    /* Core Colors */
    --skybot-primary: #4f46e5;
    /* Indigo */
    --skybot-primary-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --skybot-secondary: #f3f4f6;
    --skybot-text-main: #1f2937;
    --skybot-text-light: #6b7280;
    --skybot-bg-glass: rgba(255, 255, 255, 0.85);

    /* Layout */
    --skybot-icon-bottom-spacing: 25px;
    --skybot-icon-right-spacing: 25px;

    /* Dynamic Overrides from PHP rely on these specific names being overwritten, 
       but we will map them to our new variables where possible or use them directly if needed. */
    --skybot-header-color: #4f46e5;
    /* Fallback */
    --skybot-user-msg-color: #4f46e5;
    /* Fallback */
}

#skybot-root {
    position: fixed;
    bottom: var(--skybot-icon-bottom-spacing);
    right: var(--skybot-icon-right-spacing);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 15px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- Chatbot Window & Core Layout --- */
#skybot-root #chatbot-window {
    position: absolute;
    bottom: 80px;
    /* Raised slightly */
    right: 0;
    width: 380px;
    /* Slightly wider */
    height: 600px;
    max-width: 90vw;
    max-height: calc(100vh - 120px);

    /* Modern Glassmorphism & Shadow */
    background-color: var(--skybot-bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 24px;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06),
        0 20px 25px -5px rgba(0, 0, 0, 0.1),
        0 8px 10px -6px rgba(0, 0, 0, 0.1);

    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    /* Smooth spring-like */
    z-index: 2;
}

#skybot-root #chatbot-window.hidden {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
    pointer-events: none;
    visibility: hidden;
    /* Ensure it doesn't block clicks */
}

#skybot-root #chatbot-window.is-expanded {
    position: fixed;
    top: 20px;
    right: 20px;
    bottom: 100px;
    height: auto;
    max-height: none;
    width: 400px;
}

#skybot-root .chatbot-view {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Header --- */
#skybot-root #chatbot-header {
    background: var(--skybot-primary-gradient);
    /* Fallback allows user override, but we prefer gradient usually. 
       If user set a color, we might want to respect it, or overlay a gradient on it. */
    background: linear-gradient(135deg, var(--skybot-header-color), #7c3aed);

    color: white;
    padding: 1.25rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#skybot-root #chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    /* Space between menu, logo, and text */
}

#skybot-root #chatbot-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#skybot-root #chatbot-header-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    /* Matches header text */
}

#skybot-root #chatbot-header-logo svg {
    width: 20px;
    height: 20px;
}

#skybot-root #chatbot-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
    letter-spacing: 0.01em;
}

#skybot-root #chatbot-header button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.9;
    transition: all 0.2s;
    padding: 0.4rem;
    border-radius: 8px;
    display: flex;
}

#skybot-root #chatbot-header button:hover {
    background: rgba(255, 255, 255, 0.25);
    opacity: 1;
    transform: translateY(-1px);
}

#skybot-root #chatbot-header-menu {
    position: absolute;
    top: 60px;
    left: 1rem;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
    z-index: 100;
    width: 200px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transform-origin: top left;
    transition: all 0.2s ease;
    animation: menu-pop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes menu-pop {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

#skybot-root #chatbot-header-menu button {
    width: 100%;
    padding: 0.75rem 1rem;
    color: var(--skybot-text-main);
    background: transparent;
    text-align: left;
    font-size: 0.95rem;
    border-radius: 8px;
    margin-bottom: 2px;
}

#skybot-root #chatbot-header-menu button:hover {
    background-color: var(--skybot-secondary);
    color: var(--skybot-header-color);
}

#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: 1.5rem;
    overflow-y: auto;
    background-color: rgba(249, 250, 251, 0.6);
    /* Very sheer background */
    scrollbar-width: thin;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#skybot-root .message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: message-slide-up 0.3s ease-out forwards;
}

@keyframes message-slide-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#skybot-root .bot-message-wrapper {
    align-self: flex-start;
}

#skybot-root .user-message-wrapper {
    align-self: flex-end;
}

#skybot-root .chat-message {
    padding: 12px 18px;
    border-radius: 18px;
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 0.95rem;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

#skybot-root .user-message {
    background: var(--skybot-user-msg-color);
    /* Fallback */
    background: linear-gradient(135deg, var(--skybot-user-msg-color), #6366f1);
    color: white;
    border-bottom-right-radius: 4px;
}

#skybot-root .bot-message {
    background-color: #ffffff;
    color: var(--skybot-text-main);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

#skybot-root .system-message {
    align-self: center;
    background-color: rgba(0, 0, 0, 0.02);
    border: 1px dashed #ccc;
    color: var(--skybot-text-light);
    font-size: 0.85rem;
    text-align: center;
    max-width: 90%;
    padding: 6px 12px;
    border-radius: 8px;
}

#skybot-root .bot-message a {
    color: var(--skybot-header-color) !important;
    text-decoration: none !important;
    font-weight: 600 !important;
    border-bottom: 1px solid transparent;
    /* Animated underline prep */
    transition: border-color 0.2s;
}

#skybot-root .bot-message a:hover {
    border-bottom-color: currentColor;
}

#skybot-root .message-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    margin-left: 4px;
    opacity: 0;
    transition: opacity 0.3s;
}

#skybot-root .bot-message-wrapper:hover .message-actions {
    opacity: 1;
}

#skybot-root .message-actions button {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #9ca3af;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

#skybot-root .message-actions button:hover {
    background: #f9fafb;
    color: var(--skybot-header-color);
    transform: scale(1.1);
}

#skybot-root .message-actions button.selected,
#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 button.selected svg,
#skybot-root .message-actions .skybot-read-aloud-btn.is-speaking svg {
    stroke: white;
}

/* --- Typing Indicator --- */
#skybot-root #typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 18px;
    background: white;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

#skybot-root .typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--skybot-text-light);
    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);
        opacity: 0.5;
    }

    40% {
        transform: scale(1.0);
        opacity: 1;
    }
}

/* --- Input Area (Gemini Style) --- */
#skybot-root #chatbot-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 16px;
    padding: 8px 12px;
    background-color: #f0f4f9;
    /* Light Gray for 'Smart' Light Theme */
    border-radius: 24px;
    border: 1px solid transparent;
    transition: background-color 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

#skybot-root #chatbot-input-container:focus-within {
    background-color: #e9ecef;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    /* Softer shadow */
}

#skybot-root #chatbot-input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-bottom: 0;
}

/* Right Actions Container (Mic / Send) */
#skybot-root #chatbot-right-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 40px;
    /* Reserve space for stability */
    justify-content: flex-end;
}

#skybot-root #chatbot-attachment-btn,
#skybot-root #chatbot-mic-btn {
    color: #5f6368;
    background: transparent;
    padding: 6px;
    border-radius: 50%;
    transition: all 0.2s;
    margin: 0;
    width: 32px;
    /* Smaller size */
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #1f2937;
    /* The "One Circle" Border logic */
}

#skybot-root #chatbot-attachment-btn:hover,
#skybot-root #chatbot-mic-btn:hover {
    color: var(--skybot-header-color);
    background: rgba(0, 0, 0, 0.05);
    border-color: var(--skybot-header-color);
}

#skybot-root #chatbot-input {
    flex-grow: 1;
    border: none;
    border-radius: 0;
    padding: 8px 6px;
    font-size: 0.95rem;
    line-height: 1.5;
    background-color: transparent;
    color: #1f2937;
    /* Dark text for visibility */
    max-height: 120px;
    box-shadow: none;
}

#skybot-root #chatbot-input::placeholder {
    color: #9ca3af;
}

#skybot-root #chatbot-input:focus {
    box-shadow: none;
    border: none;
    outline: none;
    background-color: transparent;
}

#skybot-root #chatbot-send-btn {
    background: transparent;
    color: var(--skybot-header-color);
    /* Visible send icon */
    width: 32px;
    /* Smaller size */
    height: 32px;
    box-shadow: none;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #1f2937;
    /* Match other icons */
    border-radius: 50%;
}

#skybot-root #chatbot-send-btn:hover:not([disabled]) {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

#skybot-root #chatbot-send-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5;
}

#skybot-root #chatbot-send-btn[disabled] {
    opacity: 0.3;
    cursor: default;
    background: transparent;
}

/* --- Footer Disclaimer --- */
#skybot-root #skybot-footer-disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: #6b7280;
    padding: 8px 0 12px;
    width: 100%;
    margin-top: 0;
}

#skybot-root #skybot-footer-disclaimer a {
    color: #6b7280;
    text-decoration: underline;
    font-weight: 500;
}

#skybot-root #skybot-footer-disclaimer a:hover {
    color: var(--skybot-header-color);
}

/* --- Smart Reply Styles --- */
#skybot-root #chatbot-smart-reply-container {
    padding: 0 1.5rem 1rem;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    background-color: transparent;
}

#skybot-root .smart-reply-btn {
    background-color: #fff;
    border: 1px solid var(--skybot-header-color);
    color: var(--skybot-header-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

#skybot-root .smart-reply-btn:hover {
    background-color: var(--skybot-header-color);
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* --- Email Prompt Form Styles --- */
#skybot-email-prompt-form {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.5);
    padding: 10px;
    border-radius: 12px;
}

#skybot-email-input {
    flex-grow: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.9rem;
    outline: none;
}

#skybot-email-submit-btn {
    background-color: var(--skybot-header-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
}

/* --- Icon & Teaser --- */
#chatbot-container {
    position: relative;
    z-index: 1;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#skybot-root #chatbot-icon {
    background: var(--skybot-header-color);
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.2), transparent), var(--skybot-header-color);
    color: white;
    width: 60px;
    /* Larger icon */
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#skybot-root #chatbot-icon:hover {
    transform: scale(1.1);
}

#skybot-root #chatbot-icon svg {
    width: 32px;
    height: 32px;
}

#skybot-root #chatbot-proactive-teaser {
    position: relative;
    background-color: #fff;
    color: var(--skybot-text-main);
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    padding: 1.25rem 2.5rem 1.25rem 1.25rem;
    /* Extra padding right for close btn */
    width: 300px;
    cursor: pointer;
    line-height: 1.5;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    border: 1px solid rgba(0, 0, 0, 0.04);
    animation: teaser-bounce 1s infinite alternate ease-in-out;
}

@keyframes teaser-bounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-5px);
    }
}

#skybot-root #chatbot-proactive-teaser:hover {
    animation-play-state: paused;
    transform: translateY(-5px);
}

#skybot-root #chatbot-proactive-teaser::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 30px;
    width: 14px;
    height: 14px;
    background: #fff;
    transform: rotate(45deg);
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    border-right: 1px solid rgba(0, 0, 0, 0.04);
}

#skybot-root #chatbot-teaser-close-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    padding: 0;
}

#skybot-root #chatbot-teaser-close-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

/* --- Utility & Shortcode --- */
#skybot-root .hidden {
    display: none !important;
}

/* --- Tablet (Portrait/Small Laptops) --- */
@media (max-width: 768px) {
    #skybot-root #chatbot-window {
        width: 360px;
        /* Slightly narrower if needed, or keep standard */
        right: 20px;
        bottom: 90px;
    }
}

/* --- Mobile (Smartphones) --- */
@media (max-width: 480px) {
    #skybot-root {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        gap: 0;
        pointer-events: none;
        /* Let clicks pass through to site when chat is closed/icon only */
        z-index: 2147483647;
        /* Max Z-index */
    }

    #skybot-root>* {
        pointer-events: auto;
    }

    /* Force full screen overrides both default and .is-expanded */
    #skybot-root #chatbot-window,
    #skybot-root #chatbot-window.is-expanded {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        height: 100% !important;
        max-width: none;
        max-height: none;
        border-radius: 0;
        margin: 0;
        transform: none !important;
        /* Disable transform scales on mobile for performance/bugs */
    }

    /* Hide expand button on mobile as it's always full screen */
    #skybot-root #chatbot-expand-btn {
        display: none !important;
    }

    /* Adjust header padding for mobile */
    #skybot-root #chatbot-header {
        padding: 1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
        /* Safe area for iPhone notch */
    }

    /* Adjust input area for mobile */
    #skybot-root #chatbot-input-container {
        margin: 0 10px 10px 10px;
        /* Less margin */
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        /* Safe area for home bar */
    }

    /* Ensure icon is accessible */
    #skybot-root #chatbot-icon {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 2147483648;
    }

    /* Fix Teaser Position on Mobile */
    #skybot-root #chatbot-proactive-teaser {
        position: fixed !important;
        bottom: 150px !important;
        /* Huge gap to guarantee no overlap */
        right: 20px !important;
        width: 280px !important;
        max-width: calc(100vw - 40px) !important;
        z-index: 2147483648 !important;
    }
}

/* --- ADDED: Voice Input Active State --- */
#skybot-root #chatbot-mic-btn.is-listening {
    color: #ef4444;
    /* Red */
    background: rgba(239, 68, 68, 0.1);
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* --- Inline Chat Images --- */
.chat-uploaded-image {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 8px;
    display: block;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.chat-uploaded-image:hover {
    transform: scale(1.02);
}

/* --- Image Preview Styles --- */
#skybot-root #chatbot-image-preview-container {
    padding: 0 1rem;
    background: transparent;
    display: none;
    /* Hidden by default */
    margin-bottom: 0.5rem;
}

#skybot-root #chatbot-image-preview-container.has-image {
    display: flex;
}

.skybot-preview-wrapper {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.skybot-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.skybot-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.skybot-preview-remove:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* --- Advanced Thinking Indicator --- */
#skybot-root #skybot-thinking-indicator {
    padding: 12px 18px;
    background: transparent;
    border-radius: 12px;
    margin-bottom: 10px;
    margin-top: 10px;
    align-self: flex-start;
    animation: fade-in 0.3s ease;
}

.skybot-thinking-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    color: var(--skybot-header-color);
    font-weight: 700;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.skybot-logo-icon {
    width: 20px;
    height: 20px;
}

.skybot-thinking-steps {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-left: 4px;
}

.thinking-step {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--skybot-text-light);
    transition: all 0.3s ease;
    opacity: 0.7;
}

.thinking-step.active {
    color: var(--skybot-text-main);
    opacity: 1;
    font-weight: 500;
}

.thinking-step.done {
    color: var(--skybot-text-light);
    opacity: 0.6;
    /* text-decoration: line-through; Optional: or just dim it */
}

.thinking-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.thinking-icon.sparkle {
    animation: sparkle-pulse 1.5s infinite;
}

.thinking-icon.check {
    color: #10b981;
    /* Green */
    font-weight: bold;
}

@keyframes sparkle-pulse {
    0% {
        transform: scale(1);
        opacity: 1;
        filter: brightness(1);
    }

    50% {
        transform: scale(1.2);
        opacity: 0.8;
        filter: brightness(1.2);
    }

    100% {
        transform: scale(1);
        opacity: 1;
        filter: brightness(1);
    }
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}