/* Ploko Chatbot Widget Styles */

/* Chat Widget Container */
#chat-widget-container {
    position: fixed;
    bottom: 50px;
    right: 50px;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    font-family: 'Geist Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

/* Left position variant */
#chat-widget-container.position-left {
    right: auto;
    left: 50px;
    bottom: 50px;
}

/* Chat Widget Header */
#chat-widget-header {
    color: white;
    padding: 15px 20px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 18px;
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
}

#chat-widget-header button {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s;
}

#chat-widget-header button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Chat Widget Body */
#chat-widget-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f8f9fa;
    scroll-behavior: smooth;
    min-height: 200px;
    max-height: calc(100% - 120px);
}

/* Custom scrollbar styling */
#chat-widget-body::-webkit-scrollbar {
    width: 6px;
}

#chat-widget-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

#chat-widget-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

#chat-widget-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

#chat-widget-body p {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    word-wrap: break-word;
    line-height: 1.4;
}

/* User messages */
#chat-widget-body p.user-message {
    background: #e9ecef;
    color: #333;
    margin-left: 20px;
}

/* Bot messages */
#chat-widget-body p.bot-message {
    background: var(--ploko-primary-color, #854fff);
    color: white;
    margin-right: 20px;
}

/* Welcome message */
#chat-widget-body p.welcome-message {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
    margin: 0 0 20px 0;
}

/* Chat Widget Footer */
#chat-widget-footer {
    padding: 20px 20px 15px 20px;
    border-top: 1px solid #ddd;
    background: white;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
    min-height: 60px;
    box-sizing: border-box;
    position: relative;
    z-index: 10;
}

/* Input container */
#chat-widget-input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    min-height: 50px;
    box-sizing: border-box;
    padding: 5px 0;
}

/* Branding */
#chat-widget-branding {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    font-size: 8px;
    color: #999;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 3px;
    line-height: 1.1;
    z-index: 100;
    pointer-events: none;
}

#chat-widget-branding a {
    color: var(--ploko-primary-color, #854fff);
    text-decoration: none;
}

#chat-widget-branding a:hover {
    text-decoration: underline;
}

#chat-widget-input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    outline: none;
    font-size: 16px; /* Prevent zoom on iOS */
    transition: background-color 0.3s;
    resize: none;
    min-height: 24px;
    max-height: 60px;
    font-family: inherit;
    line-height: 1.4;
    box-sizing: border-box;
    background-color: #f5f5f5;
}

#chat-widget-input:focus {
    background-color: #e8e8e8;
    box-shadow: none;
}

#chat-widget-send {
    background: var(--ploko-primary-color, #854fff);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
    min-width: 70px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-sizing: border-box;
}

#chat-widget-send:hover {
    background: var(--ploko-primary-color-dark, #6b3fd4);
    transform: translateY(-1px);
}

#chat-widget-send:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Chat Widget Button */
#chat-widget-button {
    position: fixed;
    bottom: 50px;
    right: 50px;
    background: white;
    color: var(--ploko-primary-color, #854fff);
    border: none;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    overflow: hidden;
    padding: 0;
    animation: pulse 2s infinite;
}

/* Toggle button fallback icon */
#chat-widget-button .fallback-icon {
    font-size: 24px;
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    color: var(--ploko-primary-color, #854fff);
}

#chat-widget-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.3);
    background: var(--ploko-primary-color, #854fff);
    color: white;
    border: none;
    animation: none;
}

#chat-widget-button:hover .fallback-icon {
    color: white;
}

/* Left position variant for button */
#chat-widget-button.position-left {
    right: auto;
    left: 50px;
}

/* Loading animation */
.chat-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px;
    background: #e9ecef;
    border-radius: 8px;
    margin: 10px 0;
    color: #666;
    font-size: 14px;
}

.typing-dots {
    display: flex;
    gap: 3px;
    margin-left: 8px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Pulse animation for toggle button */
@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 6px 12px rgba(133, 79, 255, 0.3);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    #chat-widget-container {
        width: calc(100vw - 6px);
        height: calc(100vh - 6px);
        bottom: 3px;
        right: 3px;
        left: 3px;
        top: 3px;
        max-height: none;
        max-width: none;
        border-radius: 8px;
        position: fixed;
        box-sizing: border-box;
        transform: none;
        will-change: auto;
        overflow: hidden;
    }
    
    #chat-widget-container.position-left {
        right: 3px;
        left: 3px;
        bottom: 3px;
        top: 3px;
    }
    
    #chat-widget-body {
        max-height: calc(100% - 135px);
        overflow-y: auto;
    }
    
    #chat-widget-button {
        bottom: 3px;
        right: 3px;
    }
    
    #chat-widget-button.position-left {
        right: 3px;
        left: 3px;
    }
}

@media (max-width: 480px) {
    #chat-widget-container {
        width: calc(100vw - 6px);
        height: calc(100vh - 6px);
        bottom: 3px;
        right: 3px;
        left: 3px;
        top: 3px;
        border-radius: 8px;
        position: fixed;
        box-sizing: border-box;
        max-width: none;
        max-height: none;
        transform: none;
        will-change: auto;
        overflow: hidden;
    }
    
    #chat-widget-header {
        padding: 15px;
        font-size: 16px;
    }
    
    #chat-widget-body {
        padding: 15px;
    }
    
    #chat-widget-footer {
        padding: 15px 15px 15px 15px;
        position: relative;
        z-index: 10;
        flex-shrink: 0;
        gap: 10px;
    }
    
    #chat-widget-send {
        background: var(--ploko-primary-color, #854fff) !important;
        color: white !important;
        border: none !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        padding: 10px 16px !important;
        border-radius: 0 !important;
        cursor: pointer !important;
        transition: all 0.3s !important;
        min-width: 60px !important;
    }
    
    #chat-widget-send:hover {
        background: var(--ploko-primary-color-dark, #6b3fd4) !important;
        color: white !important;
        transform: translateY(-1px) !important;
    }
    
    #chat-widget-send:disabled {
        background: #ccc !important;
        color: #666 !important;
        cursor: not-allowed !important;
        transform: none !important;
    }
    
    /* Force send button text to be dynamic */
    #chat-widget-send:not(:disabled) {
        background: var(--ploko-primary-color, #854fff) !important;
        color: white !important;
    }
    
    /* Additional mobile send button fixes */
    #chat-widget-send {
        background: var(--ploko-primary-color, #854fff) !important;
        color: white !important;
        border: none !important;
    }
    
    /* Ensure primary color is applied */
    #chat-widget-send:not(:disabled):not(:hover) {
        background: var(--ploko-primary-color, #854fff) !important;
    }
    
    /* Force mobile send button to use dynamic color */
    @media (max-width: 768px) {
        #chat-widget-send {
            background: var(--ploko-primary-color, #854fff) !important;
            color: white !important;
        }
        
        #chat-widget-send:hover {
            background: var(--ploko-primary-color-dark, #6b3fd4) !important;
        }
        
        #chat-widget-send:not(:disabled) {
            background: var(--ploko-primary-color, #854fff) !important;
        }
    }
}

/* iPhone specific fixes */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        #chat-widget-container {
            width: calc(100vw - 6px);
            height: calc(100vh - 6px);
            top: 3px;
            bottom: 3px;
            left: 3px;
            right: 3px;
            transform: none;
            overflow: hidden;
        }
    }
}

/* iOS Safari specific */
@media screen and (max-width: 768px) and (-webkit-min-device-pixel-ratio: 2) {
    #chat-widget-container {
        width: calc(100vw - 6px);
        height: calc(100vh - 6px);
        top: 3px;
        bottom: 3px;
        left: 3px;
        right: 3px;
        -webkit-overflow-scrolling: touch;
        transform: none;
        overflow: hidden;
    }
}
