/* Bubblibot Frontend Styles */

.bubblibot-widget {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

/* Position-specific styles */
.bubblibot-widget.position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.bubblibot-widget.position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.bubblibot-widget.position-bottom-center {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.bubblibot-widget.position-right-center {
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
}

.bubblibot-widget.position-left-center {
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
}

.bubblibot-toggle {
    width: 60px;
    height: 60px;
    background: #0073aa;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bubblibot-toggle:hover {
    transform: scale(1.1);
}

.bubblibot-toggle svg {
    width: 30px;
    height: 30px;
    color: white;
}

.bubblibot-window {
    position: absolute;
    width: clamp(350px, 25vw, 450px); /* Dynamic width: min 350px, max 25% of viewport width, max 450px */
    height: clamp(400px, 95vh, 95vh); /* Dynamic height: min 400px, max 95% of viewport height */
    background: var(--bubblibot-window-bg, #ffffff);
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Window positioning based on widget position - beside toggle for more vertical space */
.position-bottom-right .bubblibot-window {
    bottom: 1vh; /* Small margin from bottom - 1% of viewport */
    right: 80px;
    max-height: 95vh; /* Use 95% of viewport height */
}

.position-bottom-left .bubblibot-window {
    bottom: 1vh; /* Small margin from bottom - 1% of viewport */
    left: 80px;
    max-height: 95vh; /* Use 95% of viewport height */
}

.position-bottom-center .bubblibot-window {
    bottom: 1vh; /* Small margin from bottom - 1% of viewport */
    left: 50%;
    transform: translateX(-50%) translateX(-175px); /* Offset to position beside centered toggle */
    max-height: 95vh; /* Use 95% of viewport height */
}

.position-right-center .bubblibot-window {
    top: 50%;
    right: 80px;
    transform: translateY(-50%);
    max-height: 95vh; /* Use 95% of viewport height */
}

.position-left-center .bubblibot-window {
    top: 50%;
    left: 80px;
    transform: translateY(-50%);
    max-height: 95vh; /* Use 95% of viewport height */
}

.bubblibot-header {
    background: #0073aa;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bubblibot-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
}

.bubblibot-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.bubblibot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bubblibot-window-bg, #ffffff);
}

.bubblibot-message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

.bubblibot-message-content {
    padding: 10px 15px;
    border-radius: 15px;
    max-width: 80%;
    line-height: 1.4;
}

.bubblibot-message-content a {
    color: #0073aa;
    text-decoration: underline;
    word-break: break-word;
    position: relative;
    display: inline-block;
    padding: 0 2px;
}

.bubblibot-user {
    align-items: flex-end;
}

.bubblibot-user .bubblibot-message-content {
    background: #0073aa;
    color: white;
}

.bubblibot-user .bubblibot-message-content a {
    color: #ffffff;
    text-decoration: underline;
}

.bubblibot-bot {
    align-items: flex-start;
}

.bubblibot-bot .bubblibot-message-content {
    background: #f0f0f0;
    color: #333;
}

.bubblibot-bot .bubblibot-message-content a {
    font-weight: 500;
}

.bubblibot-bot .bubblibot-message-content a:hover {
    text-decoration: none;
    background-color: rgba(0, 115, 170, 0.1);
    border-radius: 2px;
}

.bubblibot-error .bubblibot-message-content {
    background: #ff6b6b;
    color: white;
}

.bubblibot-input-container {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}

.bubblibot-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
}

.bubblibot-input:focus {
    border-color: #0073aa;
}

.bubblibot-send {
    background: #0073aa;
    color: white;
    border: none;
    padding: 12px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.bubblibot-send:hover {
    background: #006291;
}

.bubblibot-typing {
    padding: 10px 15px;
    display: flex;
    gap: 5px;
}

.bubblibot-typing span {
    width: 8px;
    height: 8px;
    background: #0073aa;
    border-radius: 50%;
    display: inline-block;
    animation: typing 1s infinite ease-in-out;
}

.bubblibot-typing span:nth-child(1) { animation-delay: 0.1s; }
.bubblibot-typing span:nth-child(2) { animation-delay: 0.2s; }
.bubblibot-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Mobile responsiveness - FULL SCREEN EXPERIENCE */
@media (max-width: 480px) {
    /* Override all positions on mobile to use bottom-right */
    .bubblibot-widget {
        bottom: 20px !important;
        right: 10px !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        /* Add safe area support for iOS devices */
        bottom: max(20px, env(safe-area-inset-bottom, 20px)) !important;
    }
    
    /* FULL SCREEN CHAT WINDOW ON MOBILE */
    .bubblibot-widget .bubblibot-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
        max-height: none !important;
        border-radius: 0 !important;
        z-index: 999999 !important;
        transform: none !important;
        /* Smooth transition when opening */
        transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
    }
    
    /* Hide the widget toggle when chat is open */
    .bubblibot-widget.chat-open .bubblibot-toggle {
        display: none !important;
    }
    
    /* Mobile-optimized header */
    .bubblibot-window .bubblibot-header {
        padding: 15px 20px !important;
        background: var(--bubblibot-primary-color, #0073aa) !important;
        color: white !important;
        position: relative;
        /* Add safe area padding for notched devices */
        padding-top: max(15px, env(safe-area-inset-top, 15px)) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .bubblibot-window .bubblibot-header h3 {
        margin: 0 !important;
        font-size: 18px !important;
        font-weight: 600 !important;
        text-align: center !important;
    }
    
    .bubblibot-window .bubblibot-close {
        position: absolute !important;
        right: 20px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        background: none !important;
        border: none !important;
        color: white !important;
        font-size: 28px !important;
        cursor: pointer !important;
        padding: 0 !important;
        line-height: 1 !important;
        width: 32px !important;
        height: 32px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 16px !important;
        transition: background-color 0.2s ease !important;
    }
    
    .bubblibot-window .bubblibot-close:hover {
        background-color: rgba(255, 255, 255, 0.1) !important;
    }
    
    /* Full height messages area */
    .bubblibot-window .bubblibot-messages {
        flex: 1 !important;
        padding: 20px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        /* Account for input area */
        margin-bottom: 0 !important;
        /* Better spacing for mobile */
        padding-bottom: 20px !important;
    }
    
    /* Mobile-optimized message bubbles */
    .bubblibot-message {
        margin-bottom: 16px !important;
    }
    
    .bubblibot-message-content {
        padding: 12px 16px !important;
        border-radius: 18px !important;
        max-width: 85% !important;
        line-height: 1.4 !important;
    }
    
    /* User messages - right aligned */
    .bubblibot-user .bubblibot-message-content {
        background: var(--bubblibot-primary-color, #0073aa) !important;
        color: white !important;
        margin-left: auto !important;
    }
    
    /* Bot messages - left aligned */
    .bubblibot-bot .bubblibot-message-content {
        background: #f0f0f0 !important;
        color: #333 !important;
        margin-right: auto !important;
    }
    
    /* Fixed input area at bottom */
    .bubblibot-window .bubblibot-input-container {
        position: sticky !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: white !important;
        padding: 15px 20px !important;
        border-top: 1px solid #eee !important;
        display: flex !important;
        gap: 12px !important;
        align-items: center !important;
        /* Add safe area padding for home indicator */
        padding-bottom: max(15px, env(safe-area-inset-bottom, 15px)) !important;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1) !important;
    }
    
    .bubblibot-window .bubblibot-input {
        flex: 1 !important;
        padding: 12px 16px !important;
        border: 1px solid #ddd !important;
        border-radius: 25px !important;
        outline: none !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        background: #f8f9fa !important;
        transition: border-color 0.2s ease !important;
    }
    
    .bubblibot-window .bubblibot-input:focus {
        border-color: var(--bubblibot-primary-color, #0073aa) !important;
        background: white !important;
    }
    
    .bubblibot-window .bubblibot-send {
        background: var(--bubblibot-primary-color, #0073aa) !important;
        color: white !important;
        border: none !important;
        padding: 14px !important;
        border-radius: 50% !important;
        cursor: pointer !important;
        font-size: 16px !important;
        font-weight: 500 !important;
        transition: background-color 0.2s ease !important;
        width: 48px !important;
        height: 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }
    
    .bubblibot-window .bubblibot-send:hover {
        background: var(--bubblibot-primary-color-dark, #006291) !important;
    }
    
    /* Typing indicator adjustments */
    .bubblibot-window .bubblibot-typing {
        padding: 12px 16px !important;
        margin: 0 20px 16px 20px !important;
        background: #f0f0f0 !important;
        border-radius: 18px !important;
        width: fit-content !important;
    }
    
    /* Lead form adjustments for mobile */
    .bubblibot-lead-form .bubblibot-message-content {
        max-width: 100% !important;
        margin: 0 !important;
        padding: 20px !important;
        border-radius: 12px !important;
    }
    
    .bubblibot-form-field {
        margin-bottom: 16px !important;
    }
    
    .bubblibot-form-field input,
    .bubblibot-form-field textarea {
        padding: 12px 16px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        border-radius: 8px !important;
    }
    
    .bubblibot-form-buttons {
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    .bubblibot-form-submit,
    .bubblibot-form-cancel {
        padding: 14px 20px !important;
        font-size: 16px !important;
        border-radius: 8px !important;
        font-weight: 500 !important;
    }
    
    /* Agent avatar adjustments */
    .bubblibot-agent .bubblibot-message-content {
        margin-left: 35px !important;
    }
    
    .bubblibot-agent-message-avatar {
        width: 28px !important;
        height: 28px !important;
    }
    
    .bubblibot-bot.has-avatar .bubblibot-message-content {
        margin-left: 35px !important;
    }
    
    .bubblibot-bot-message-avatar {
        width: 28px !important;
        height: 28px !important;
    }
    
    /* Enhanced toggle button for mobile */
    .bubblibot-toggle {
        width: 56px !important;
        height: 56px !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
        transition: transform 0.2s ease, box-shadow 0.2s ease !important;
    }
    
    .bubblibot-toggle:active {
        transform: scale(0.95) !important;
    }
    
    .bubblibot-toggle svg {
        width: 26px !important;
        height: 26px !important;
    }
}

/* iPhone specific adjustments - more aggressive positioning */
@media (max-width: 480px) and (max-height: 896px) {
    .bubblibot-widget {
        bottom: 35px !important; /* Higher position for iPhone */
        right: 15px !important;
    }
    
    .bubblibot-widget .bubblibot-window {
        bottom: 105px !important;
        right: -15px !important; /* Offset to align with screen edge */
    }
    
    .bubblibot-window {
        bottom: 105px;
        width: calc(100vw - 30px);
        right: 15px;
        left: 15px;
        max-width: calc(100vw - 30px);
    }
}

/* Additional mobile adjustments for very small screens */
@media (max-width: 375px) {
    .bubblibot-widget {
        bottom: 25px !important;
        right: 15px !important;
        /* Extra margin for smaller screens */
        bottom: max(25px, calc(env(safe-area-inset-bottom, 0px) + 10px)) !important;
    }
    
    .bubblibot-widget .bubblibot-window {
        bottom: 95px !important;
        bottom: calc(95px + env(safe-area-inset-bottom, 0px)) !important;
        right: -15px !important; /* Offset to align with screen edge */
    }
    
    .bubblibot-window {
        width: calc(100vw - 30px);
        right: 15px;
        left: 15px;
        bottom: calc(95px + env(safe-area-inset-bottom, 0px));
        max-width: calc(100vw - 30px);
    }
}

/* Dynamic scaling for large screens */
@media (min-width: 1200px) {
    .bubblibot-window {
        width: clamp(380px, 28vw, 500px); /* Larger on big screens */
        height: 95vh; /* Use 95% of viewport height */
        max-height: 95vh; /* Consistent with height */
    }
}

@media (min-width: 1600px) {
    .bubblibot-window {
        width: clamp(420px, 30vw, 550px); /* Even larger on very big screens */
        height: 95vh; /* Use 95% of viewport height */
        max-height: 95vh; /* Consistent with height */
    }
}

/* Cap height only for truly large screens (2560×1440 and above) */
@media (min-width: 2560px) {
    .bubblibot-window {
        height: clamp(400px, 60vh, 900px); /* Cap at 900px for very large displays */
        max-height: 900px; /* Fixed maximum for ultra-wide/large displays */
    }
}

/* Ensure minimum size on smaller desktops */
@media (max-width: 1024px) and (min-width: 481px) {
    .bubblibot-window {
        width: 350px; /* Fixed width on smaller desktops */
        height: clamp(400px, 95vh, 95vh); /* Use 95% of viewport height with minimum */
        max-height: 95vh; /* Consistent with height */
    }
}

/* Scrollbar styling */
.bubblibot-messages::-webkit-scrollbar {
    width: 6px;
}

.bubblibot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.bubblibot-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.bubblibot-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Lead Capture Form Styles */
.bubblibot-lead-form .bubblibot-message-content {
    background: #f8f9fa !important;
    border: 2px solid var(--bubblibot-primary-color, #0073aa);
    border-radius: 10px;
    padding: 20px;
    max-width: 100%;
}

.bubblibot-contact-form {
    width: 100%;
}

.bubblibot-form-field {
    margin-bottom: 15px;
}

.bubblibot-form-field label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.bubblibot-form-field input,
.bubblibot-form-field textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
    font-family: inherit;
}

.bubblibot-form-field input:focus,
.bubblibot-form-field textarea:focus {
    outline: none;
    border-color: var(--bubblibot-primary-color, #0073aa);
    box-shadow: 0 0 0 2px rgba(var(--bubblibot-primary-color-rgb, 0, 115, 170), 0.1);
}

.bubblibot-form-field input:required,
.bubblibot-form-field textarea:required {
    border-left: 3px solid var(--bubblibot-primary-color, #0073aa);
}

.bubblibot-form-field textarea {
    resize: vertical;
    min-height: 60px;
}

.bubblibot-form-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.bubblibot-form-submit,
.bubblibot-form-cancel {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
}

.bubblibot-form-submit {
    background: var(--bubblibot-primary-color, #0073aa);
    color: white;
}

.bubblibot-form-submit:hover {
    background: var(--bubblibot-primary-color-dark, #006291);
}

.bubblibot-form-submit:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.bubblibot-form-cancel {
    background: #f0f0f0;
    color: #666;
    border: 1px solid #ddd;
}

.bubblibot-form-cancel:hover {
    background: #e0e0e0;
    color: #333;
}

/* Mobile responsiveness for form */
@media (max-width: 480px) {
    .bubblibot-lead-form .bubblibot-message-content {
        padding: 15px;
    }
    
    .bubblibot-form-buttons {
        flex-direction: column;
    }
    
    .bubblibot-form-submit,
    .bubblibot-form-cancel {
        flex: none;
    }
}

/* Handoff animations and styles */
.bubblibot-handoff {
    align-items: flex-start;
}

.bubblibot-connecting {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: #E3F2FD;
    border-radius: 10px;
    margin: 10px 0;
    border-left: 4px solid #2196F3;
    animation: connecting-pulse 2s infinite;
}

.bubblibot-connecting-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #E3F2FD;
    border-top: 2px solid #2196F3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.bubblibot-connecting-text {
    color: #1976D2;
    font-weight: 500;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes connecting-pulse {
    0%, 100% { 
        background: #E3F2FD;
        border-left-color: #2196F3;
    }
    50% { 
        background: #BBDEFB;
        border-left-color: #1976D2;
    }
}

.bubblibot-connecting-dots::after {
    content: '...';
    animation: connecting-dots 1.5s infinite;
}

@keyframes connecting-dots {
    0%, 33% { opacity: 0.3; }
    34%, 66% { opacity: 0.6; }
    67%, 100% { opacity: 1; }
}

/* Agent joined message styling */
.bubblibot-agent-joined {
    align-items: flex-start;
}

.bubblibot-agent-joined .bubblibot-message-content {
    position: relative;
    padding: 15px !important;
    display: flex;
    align-items: center;
    gap: 12px;
    /* Colors will be inherited from bot message styling via dynamic CSS */
}

.bubblibot-agent-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.bubblibot-agent-info {
    flex: 1;
}

.bubblibot-agent-name {
    font-weight: bold;
    margin-bottom: 4px;
}

.bubblibot-agent-message {
    margin: 0;
}

/* Mobile responsiveness for agent joined message */
@media (max-width: 480px) {
    .bubblibot-agent-joined .bubblibot-message-content {
        padding: 12px !important;
        gap: 10px;
    }
    
    .bubblibot-agent-avatar {
        width: 32px;
        height: 32px;
    }
    
    .bubblibot-agent-name {
        font-size: 14px;
    }
    
    .bubblibot-agent-message {
        font-size: 13px;
    }
}

/* Timeout form specific styling */
.bubblibot-timeout-form {
    margin-top: 10px;
}

.bubblibot-timeout-form .bubblibot-form-header {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px 8px 0 0;
    padding: 15px;
    margin: 0;
}

.bubblibot-timeout-form .bubblibot-form-header h4 {
    margin: 0 0 5px 0;
    color: #856404;
    font-size: 16px;
}

.bubblibot-timeout-form .bubblibot-form-header p {
    margin: 0;
    color: #856404;
    font-size: 14px;
}

.bubblibot-timeout-form .bubblibot-form-content {
    background: white;
    border: 1px solid #ffeaa7;
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 15px;
}

/* Agent form specific styling */
.bubblibot-agent-form {
    margin-top: 10px;
}

.bubblibot-agent-form .bubblibot-form-header {
    background: rgba(var(--bubblibot-primary-color-rgb, 0, 115, 170), 0.1);
    border: 1px solid var(--bubblibot-primary-color, #0073aa);
    border-radius: 8px 8px 0 0;
    padding: 15px;
    margin: 0;
}

.bubblibot-agent-form .bubblibot-form-header h4 {
    margin: 0 0 5px 0;
    color: var(--bubblibot-primary-color-dark, #006291);
    font-size: 16px;
}

.bubblibot-agent-form .bubblibot-form-header p {
    margin: 0;
    color: var(--bubblibot-primary-color-dark, #006291);
    font-size: 14px;
}

.bubblibot-agent-form .bubblibot-form-content {
    background: white;
    border: 1px solid var(--bubblibot-primary-color, #0073aa);
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 15px;
}

/* Human acknowledgment message styling */
.bubblibot-human-ack .bubblibot-message-content {
    background: #e3f2fd !important;
    border: 1px solid #bbdefb !important;
    color: #0d47a1 !important;
    font-style: italic;
    opacity: 0.9;
}

/* Agent message styling */
.bubblibot-agent {
    position: relative;
}

.bubblibot-agent .bubblibot-message-content {
    margin-left: 35px; /* Make room for avatar */
    position: relative;
    /* Colors will be inherited from bot message styling via dynamic CSS */
}

.bubblibot-agent-message-avatar {
    position: absolute;
    top: 0;
    left: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    background: #f1f8e9;
    z-index: 1;
}

/* Default avatar when no image is available */
.bubblibot-agent-message-avatar.default-avatar {
    background: #4caf50;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* Bot message avatar styling */
.bubblibot-bot.has-avatar {
    position: relative;
}

.bubblibot-bot.has-avatar .bubblibot-message-content {
    margin-left: 35px; /* Make room for avatar */
    position: relative;
}

.bubblibot-bot-message-avatar {
    position: absolute;
    top: 0;
    left: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    background: #e3f2fd;
    z-index: 1;
}

/* Default bot avatar when no image is available but avatar is enabled */
.bubblibot-bot-message-avatar.default-avatar {
    background: #2196f3;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* Mobile responsiveness for agent messages */
@media (max-width: 480px) {
    .bubblibot-agent .bubblibot-message-content {
        margin-left: 30px;
    }
    
    .bubblibot-agent-message-avatar {
        width: 24px;
        height: 24px;
    }
    
    .bubblibot-agent-message-avatar.default-avatar {
        font-size: 10px;
    }
    
    /* Bot avatar mobile styles */
    .bubblibot-bot.has-avatar .bubblibot-message-content {
        margin-left: 30px;
    }
    
    .bubblibot-bot-message-avatar {
        width: 24px;
        height: 24px;
    }
    
    .bubblibot-bot-message-avatar.default-avatar {
        font-size: 10px;
    }
}

/* Markdown formatting styles for chat messages */
.bubblibot-message-content h1,
.bubblibot-message-content h2,
.bubblibot-message-content h3 {
    line-height: 1.3;
    margin-top: 8px;
    margin-bottom: 4px;
}

.bubblibot-message-content h1:first-child,
.bubblibot-message-content h2:first-child,
.bubblibot-message-content h3:first-child {
    margin-top: 0;
}

.bubblibot-message-content h1:last-child,
.bubblibot-message-content h2:last-child,
.bubblibot-message-content h3:last-child {
    margin-bottom: 0;
}

/* Ensure numbered list items have proper spacing */
.bubblibot-message-content div[style*="margin: 4px 0"] {
    line-height: 1.4;
}

/* Mobile adjustments for headers */
@media (max-width: 480px) {
    .bubblibot-message-content h1 {
        margin: 6px 0 4px 0 !important;
    }
    
    .bubblibot-message-content h2 {
        margin: 6px 0 3px 0 !important;
    }
    
    .bubblibot-message-content h3 {
        margin: 6px 0 3px 0 !important;
    }
}

/* iOS specific adjustments */
@supports (padding: max(0px)) {
    @media (max-width: 480px) {
        .bubblibot-widget {
            /* Use max() to ensure minimum distance from bottom */
            bottom: max(20px, env(safe-area-inset-bottom, 20px)) !important;
        }
        
        .bubblibot-widget .bubblibot-window {
            bottom: calc(90px + env(safe-area-inset-bottom, 0px)) !important;
        }
        
        .bubblibot-window {
            bottom: calc(90px + env(safe-area-inset-bottom, 0px));
        }
    }
    
    @media (max-width: 375px) {
        .bubblibot-widget {
            bottom: max(25px, calc(env(safe-area-inset-bottom, 0px) + 10px)) !important;
        }
        
        .bubblibot-widget .bubblibot-window {
            bottom: calc(95px + env(safe-area-inset-bottom, 0px)) !important;
        }
        
        .bubblibot-window {
            bottom: calc(95px + env(safe-area-inset-bottom, 0px));
        }
    }
}

/* Fallback for older iOS versions */
@media (max-width: 480px) and (-webkit-min-device-pixel-ratio: 2) {
    .bubblibot-widget {
        bottom: 30px !important; /* Extra margin for iOS */
    }
    
    .bubblibot-widget .bubblibot-window {
        bottom: 100px !important;
    }
    
    .bubblibot-window {
        bottom: 100px;
    }
}

/* Debug styles for mobile (remove in production) */
@media (max-width: 480px) {
    .bubblibot-toggle {
        /* Ensure button is always clickable */
        z-index: 10000;
        /* Add subtle shadow to make it more visible */
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
}

/* Prevent background scrolling when mobile chat is open */
body.bubblibot-mobile-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

.bubblibot-bot-message-avatar,
.bubblibot-agent-message-avatar {
    /* Make sure oversize images cannot spill out */
    overflow: hidden;
}

.bubblibot-bot-message-avatar img,
.bubblibot-agent-message-avatar img {
    /* Force avatar images to fit the 28×28 (or 24×24 on mobile) wrapper */
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}