/* ==========================================================================
   Floating Container & Corner Positioning
   ========================================================================== */
.acworth-copilot-chatbot-floating-container {
    position: fixed !important;
    z-index: var(--chat-z-index, 99999) !important;
    display: flex !important;
    /* Default fallback: anchors button to bottom, window opens above */
    flex-direction: column-reverse !important;
    align-items: flex-end;
    bottom: var(--chat-offset-y, 20px) !important;
    right: var(--chat-offset-x, 20px) !important;
}

/* Position Variants based on Admin Settings */
.acworth-copilot-chatbot-floating-container.bottom-right {
    top: auto !important;
    left: auto !important;
    bottom: var(--chat-offset-y, 20px) !important;
    right: var(--chat-offset-x, 20px) !important;
    flex-direction: column-reverse !important; /* Button at bottom, window above */
    align-items: flex-end !important;
}

.acworth-copilot-chatbot-floating-container.bottom-left {
    top: auto !important;
    right: auto !important;
    bottom: var(--chat-offset-y, 20px) !important;
    left: var(--chat-offset-x, 20px) !important;
    flex-direction: column-reverse !important; /* Button at bottom, window above */
    align-items: flex-start !important;
}

.acworth-copilot-chatbot-floating-container.top-right {
    bottom: auto !important;
    left: auto !important;
    top: var(--chat-offset-y, 20px) !important;
    right: var(--chat-offset-x, 20px) !important;
    flex-direction: column !important; /* Button at top, window below */
    align-items: flex-end !important;
}

.acworth-copilot-chatbot-floating-container.top-left {
    bottom: auto !important;
    right: auto !important;
    top: var(--chat-offset-y, 20px) !important;
    left: var(--chat-offset-x, 20px) !important;
    flex-direction: column !important; /* Button at top, window below */
    align-items: flex-start !important;
}

/* Reverse bubble order when positioned on Left side */
.bottom-left .acworth-copilot-trigger-wrapper,
.top-left .acworth-copilot-trigger-wrapper {
    flex-direction: row-reverse;
}

/* ==========================================================================
   Trigger Wrapper & Prompt Bubble (Fade-In)
   ========================================================================== */
.acworth-copilot-trigger-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

/* Prompt Speech Bubble */
.acworth-copilot-prompt-bubble {
    background: #ffffff;
    color: #1a1a1a;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 14px;
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    pointer-events: none;
}

.acworth-copilot-prompt-bubble.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.acworth-copilot-prompt-close {
    background: transparent;
    border: none;
    color: #888;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.acworth-copilot-prompt-close:hover {
    color: #1a1a1a;
}

/* ==========================================================================
   Launcher Button Style & Icon Visibility Fix
   ========================================================================== */
.acworth-copilot-chatbot-toggle {
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    background-color: var(--button-bg-color, #0073AA) !important;
    color: var(--button-text-color, #ffffff) !important;
    border: none !important;
    cursor: pointer !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    box-sizing: border-box !important;
    position: relative;
}

.acworth-copilot-chatbot-toggle:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3) !important;
}

/* Strict Icon Toggle Logic - Prevents Overlay Mix */
.acworth-copilot-icon-open {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.acworth-copilot-icon-close {
    display: none !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* When the Chat Window is Open */
.acworth-copilot-chatbot-window.is-open ~ .acworth-copilot-trigger-wrapper .acworth-copilot-icon-open,
.acworth-copilot-window-is-open .acworth-copilot-icon-open {
    display: none !important;
}

.acworth-copilot-chatbot-window.is-open ~ .acworth-copilot-trigger-wrapper .acworth-copilot-icon-close,
.acworth-copilot-window-is-open .acworth-copilot-icon-close {
    display: flex !important;
}

/* Icon Sizing Inside Button */
.acworth-copilot-chatbot-toggle svg,
.acworth-copilot-chatbot-toggle img {
    width: 26px !important;
    height: 26px !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
    fill: currentColor !important;
    display: block !important;
}

/* Size Modifiers */
.acworth-copilot-chatbot-toggle.small { width: 48px !important; height: 48px !important; }
.acworth-copilot-chatbot-toggle.large { width: 70px !important; height: 70px !important; }

/* ==========================================================================
   Chat Popup Window Base Layout
   ========================================================================== */
.acworth-copilot-chatbot-window {
    display: flex !important;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    width: var(--chat-max-width, 420px);
    height: var(--chat-max-height, 680px);
    max-width: calc(100vw - 30px);
    max-height: calc(100vh - 100px);
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    margin-bottom: 12px;
    margin-top: 12px;
    flex-direction: column;
    transform-origin: var(--transform-origin-x, right) bottom;
}

.acworth-copilot-chatbot-window-header {
    background: var(--button-bg-color, #0073AA);
    color: var(--button-text-color, #ffffff);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.acworth-copilot-chatbot-window-header h4 {
    margin: 0;
    font-size: 16px;
    color: inherit;
}

.acworth-copilot-chatbot-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
}

.acworth-copilot-chatbot-iframe-wrap {
    flex: 1;
    width: 100%;
    height: 100%;
}

.acworth-copilot-chatbot-iframe-wrap iframe {
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
}

/* ==========================================================================
   Chat Window Animations (None, Fade, Bounce)
   ========================================================================== */
.acworth-copilot-chatbot-window[data-animation-style="none"] {
    transition: none !important;
}
.acworth-copilot-chatbot-window[data-animation-style="none"].is-open {
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

.acworth-copilot-chatbot-window[data-animation-style="fade"] {
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    transform: translateY(10px);
}
.acworth-copilot-chatbot-window[data-animation-style="fade"].is-open {
    visibility: visible !important;
    opacity: 1 !important;
    transform: translateY(0);
    pointer-events: auto !important;
}

.acworth-copilot-chatbot-window[data-animation-style="bounce"] {
    transition: opacity 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
                transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
                visibility 0.35s ease;
    transform: scale(0.8) translateY(20px);
}
.acworth-copilot-chatbot-window[data-animation-style="bounce"].is-open {
    visibility: visible !important;
    opacity: 1 !important;
    transform: scale(1) translateY(0);
    pointer-events: auto !important;
}

/* Embedded Mode Prompt Banner */
.acworth-copilot-embedded-prompt-banner {
    background: #f0f7fb;
    border-left: 4px solid var(--button-bg-color, #0073AA);
    color: #004065;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 15px;
    border-radius: 6px;
    margin-bottom: 12px;
}

/* Responsive Mobile Layout */
@media screen and (max-width: 600px) {
    .acworth-copilot-chatbot-window.is-open {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
        max-width: 100vw !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        /* Increased z-index to overlay on top of accessibility widgets and floating toolbars */
        z-index: 9999999 !important;
        margin: 0 !important;
        /* Bottom safe area spacing for mobile navigation bars */
        padding-bottom: env(safe-area-inset-bottom, 20px) !important;
        box-sizing: border-box !important;
    }

    /* Extra bottom padding inside iframe wrapper so input field sits comfortably */
    .acworth-copilot-chatbot-iframe-wrap {
        padding-bottom: 16px !important;
        box-sizing: border-box !important;
    }
}