/**
 * LiveChat Embedded Widget - Isolated Styles
 * 
 * All styles are namespaced with #lc-widget- to prevent conflicts with host website
 * No global styles or body/html modifications
 */

/* CSS Variables scoped to widget container */
#lc-widget-container {
    --lc-primary: #007bff;
    --lc-secondary: #0056b3;
    --lc-gradient: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    --lc-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --lc-z-index: 1000;
}

/* Container - does not affect host website */
#lc-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: var(--lc-z-index);
    font-family: var(--lc-font);
}

/* Chat Bubble */
#lc-widget-container .lc-chat-bubble {
    width: 64px;
    height: 64px;
    background: var(--lc-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    animation: lc-breathe 3s ease-in-out infinite;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#lc-widget-container .lc-chat-bubble.close-mode {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    box-shadow: 0 8px 32px rgba(220, 53, 69, 0.3);
    animation: none;
}

#lc-widget-container .lc-chat-bubble.close-mode:hover {
    background: linear-gradient(135deg, #c82333 0%, #bd2130 100%);
    box-shadow: 0 12px 40px rgba(220, 53, 69, 0.4);
}

#lc-widget-container .lc-chat-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.2) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

#lc-widget-container .lc-chat-bubble:hover::before {
    transform: translateX(100%);
}

#lc-widget-container .lc-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(0, 123, 255, 0.4);
}

#lc-widget-container .lc-chat-bubble:active {
    transform: scale(0.98);
    transition: all 0.1s ease;
}

/* Animations */
@keyframes lc-breathe {
    0%, 100% {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2), 0 0 0 20px rgba(0, 0, 0, 0.05);
        transform: scale(1.05);
    }
}

@keyframes lc-slideInUp {
    0% {
        transform: translateY(100%) scale(0.8);
        opacity: 0;
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes lc-slideOutDown {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(30px) scale(0.9);
        opacity: 0;
    }
}

@keyframes lc-messageSlideIn {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes lc-typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

@keyframes lc-shimmer {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(100%); }
    100% { transform: translateX(100%); }
}

/* Chat Window */
#lc-widget-container .lc-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-height: 520px;
    height: 520px;
    background: linear-gradient(135deg, #ffffff 0%, #ffffff 100%);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(255, 255, 255, 0.2);
    display: none !important;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(30px) scale(0.9);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    backdrop-filter: blur(20px);
}

#lc-widget-container .lc-chat-window.open {
    display: flex !important;
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    animation: lc-slideInUp 0.6s ease-out;
}

#lc-widget-container .lc-chat-window.closing {
    animation: lc-slideOutDown 0.5s ease-in forwards;
}

/* Chat Header */
#lc-widget-container .lc-chat-header {
    background: var(--lc-gradient);
    color: white;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

#lc-widget-container .lc-chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: translateX(-100%);
    animation: lc-shimmer 3s infinite;
}

#lc-widget-container .lc-header-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

#lc-widget-container .lc-assistant-status {
    font-size: 12px;
    opacity: 0.95;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

#lc-widget-container .lc-status-dot {
    width: 8px;
    height: 8px;
    background: #28a745;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(40, 167, 69, 0.5);
    animation: lc-pulse 2s ease-in-out infinite;
}

@keyframes lc-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

#lc-widget-container .lc-header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1;
}

#lc-widget-container .lc-end-chat-btn-header {
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
    font-family: var(--lc-font);
    font-weight: 500;
}

#lc-widget-container .lc-end-chat-btn-header:hover {
    background: rgba(200, 35, 51, 1);
    transform: scale(1.05);
}

#lc-widget-container .lc-status-indicator {
    font-size: 11px;
    opacity: 0.95;
    position: relative;
    padding-left: 12px;
    display: block;
    line-height: 1.4;
}

#lc-widget-container .lc-status-indicator::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #28a745;
}

#lc-widget-container .lc-status-indicator.online-mode::before {
    background: #28a745;
    box-shadow: 0 0 4px rgba(40, 167, 69, 0.5);
}

#lc-widget-container .lc-status-indicator.waiting-mode::before {
    background: #ffc107;
    box-shadow: 0 0 4px rgba(255, 193, 7, 0.5);
}

#lc-widget-container .lc-status-indicator.offline-mode::before {
    background: #6c757d;
    box-shadow: 0 0 4px rgba(108, 117, 125, 0.5);
}

#lc-widget-container .lc-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
}

#lc-widget-container .lc-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Messages Area */
#lc-widget-container .lc-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

#lc-widget-container .lc-message {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-end;
    animation: lc-messageSlideIn 0.4s ease-out;
}

#lc-widget-container .lc-message.bot-message,
#lc-widget-container .lc-message.human-message,
#lc-widget-container .lc-message.system-message {
    justify-content: flex-start;
}

#lc-widget-container .lc-message.user-message {
    justify-content: flex-end;
}

#lc-widget-container .lc-message-content {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 20px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

#lc-widget-container .lc-message-content:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#lc-widget-container .bot-message .lc-message-content,
#lc-widget-container .human-message .lc-message-content {
    background: white;
    color: #333;
    border-bottom-left-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

#lc-widget-container .user-message .lc-message-content {
    background: var(--lc-gradient);
    color: white;
    border-bottom-right-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#lc-widget-container .user-message .lc-message-content p {
    color: white !important;
}

#lc-widget-container .user-message .lc-message-time {
    color: white !important;
}

#lc-widget-container .system-message .lc-message-content {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: white;
    border-radius: 20px;
    text-align: center;
    font-size: 13px;
}

#lc-widget-container .lc-message-content p {
    margin: 0 0 0.5em 0;
    font-size: 14px;
    line-height: 1.6;
}

#lc-widget-container .lc-message-content p:last-child {
    margin-bottom: 0;
}

#lc-widget-container .lc-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
}

/* Typing Indicator */
#lc-widget-container .lc-typing-indicator {
    padding: 0 20px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 13px;
}

#lc-widget-container .lc-typing-dots {
    display: flex;
    gap: 2px;
}

#lc-widget-container .lc-typing-dots span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: lc-typing 1.4s infinite;
}

#lc-widget-container .lc-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

#lc-widget-container .lc-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* Chat Input */
#lc-widget-container .lc-chat-input {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
    background: white;
    position: relative;
    z-index: 10;
}

#lc-widget-container .lc-message-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 25px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    transition: border-color 0.2s ease;
    font-family: var(--lc-font);
}

#lc-widget-container .lc-message-input:focus {
    border-color: var(--lc-primary);
}

#lc-widget-container .lc-send-btn {
    background: var(--lc-primary, #007bff) !important;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 1 !important;
    flex-shrink: 0;
}

#lc-widget-container .lc-send-btn svg {
    fill: white !important;
    opacity: 1 !important;
}

#lc-widget-container .lc-send-btn svg path {
    fill: white !important;
    opacity: 1 !important;
}

#lc-widget-container .lc-send-btn:hover {
    background: var(--lc-secondary, #0056b3) !important;
    transform: scale(1.05);
}

#lc-widget-container .lc-send-btn:active {
    transform: scale(0.95);
}

/* Restart Chat Button */
#lc-widget-container .lc-restart-chat-btn {
    width: 100%;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    border-radius: 25px;
    padding: 14px 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
    font-family: var(--lc-font);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

#lc-widget-container .lc-restart-chat-btn:hover {
    background: linear-gradient(135deg, #20c997 0%, #17a2b8 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(40, 167, 69, 0.4);
}

#lc-widget-container .lc-restart-chat-btn:active {
    transform: translateY(0);
}

/* Email Message Bubble */
#lc-widget-container .lc-email-message {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 12px;
    padding: 16px;
    margin: 12px 20px;
}

#lc-widget-container .lc-email-message-title {
    font-weight: 600;
    color: #856404;
    margin-bottom: 8px;
    font-size: 14px;
}

#lc-widget-container .lc-email-message-content {
    display: flex;
    gap: 8px;
    align-items: center;
}

#lc-widget-container .lc-email-field {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--lc-font);
    outline: none;
}

#lc-widget-container .lc-email-field:focus {
    border-color: var(--lc-primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

#lc-widget-container .lc-submit-email-btn {
    background: var(--lc-primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
    font-family: var(--lc-font);
    font-weight: 500;
    transition: all 0.2s ease;
}

#lc-widget-container .lc-submit-email-btn:hover {
    background: var(--lc-secondary);
    transform: translateY(-1px);
}

/* Quick Suggestions */
#lc-widget-container .lc-chat-suggestions {
    padding: 16px 20px;
    margin: 0;
}

#lc-widget-container .lc-suggestions-container {
    padding: 16px 20px;
    margin: 0;
}

#lc-widget-container .lc-suggestions-title {
    font-size: 13px;
    color: #666;
    margin-bottom: 12px;
    font-weight: 500;
}

#lc-widget-container .lc-suggestion-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
}

#lc-widget-container .lc-suggestions-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
}

#lc-widget-container .lc-suggestion-btn {
    background: #f5f5f5;
    border: none;
    border-radius: 12px;
    padding: 14px 18px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--lc-font);
    color: #333;
    text-align: left;
    font-weight: 400;
}

#lc-widget-container .lc-suggestion-btn:hover {
    background: #e8e8e8;
    transform: translateX(4px);
}

#lc-widget-container .lc-email-input-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
    width: 100%;
}

#lc-widget-container .lc-email-field {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 14px;
    outline: none;
    font-family: var(--lc-font);
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

#lc-widget-container .lc-email-field:focus {
    border-color: var(--lc-primary);
}

#lc-widget-container .lc-email-submit-btn {
    background: var(--lc-primary, #007bff);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--lc-font);
    font-weight: 500;
    white-space: nowrap;
    width: 100%;
    box-sizing: border-box;
}

#lc-widget-container .lc-email-submit-btn:hover {
    background: var(--lc-secondary, #0056b3);
    transform: translateY(-1px);
}

#lc-widget-container .lc-email-submit-btn:active {
    transform: translateY(0);
}

#lc-widget-container .lc-submit-email-btn {
    background: var(--lc-button-color, var(--lc-primary));
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--lc-font);
}

#lc-widget-container .lc-submit-email-btn:hover {
    background: var(--lc-button-hover-color, var(--lc-secondary));
}

/* Action Buttons */
#lc-widget-container .lc-action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 20px;
    margin-bottom: 15px;
    animation: lc-messageSlideIn 0.4s ease-out;
    align-items: flex-start; /* Align to left */
    max-width: 85%; /* Match message bubble width */
}

#lc-widget-container .lc-action-btn {
    background: var(--lc-primary, #007bff);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--lc-font);
    text-decoration: none;
    text-align: center;
    display: inline-block; /* Changed from block to inline-block */
    box-shadow: 0 2px 6px rgba(0, 123, 255, 0.2);
    white-space: nowrap; /* Prevent text wrapping */
    width: auto; /* Auto width instead of full width */
}

#lc-widget-container .lc-action-btn:hover {
    background: var(--lc-secondary, #0056b3);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
}

#lc-widget-container .lc-action-btn:active {
    transform: translateY(0);
}

/* Scrollbar */
#lc-widget-container .lc-chat-messages::-webkit-scrollbar {
    width: 4px;
}

#lc-widget-container .lc-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#lc-widget-container .lc-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

#lc-widget-container .lc-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Restart Chat Button */
#lc-widget-container .lc-restart-chat-btn {
    width: 100%;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 16px 24px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
    font-family: var(--lc-font);
}

#lc-widget-container .lc-restart-chat-btn:hover {
    background: linear-gradient(135deg, #20c997 0%, #17a2b8 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

#lc-widget-container .lc-restart-chat-btn:active {
    transform: translateY(0);
}

/* Responsive Design */
@media (max-width: 768px) {
    #lc-widget-container {
        bottom: 15px;
        right: 15px;
    }
    
    #lc-widget-container .lc-chat-bubble {
        width: 56px;
        height: 56px;
    }
    
    #lc-widget-container .lc-chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: auto;
        width: 100% !important;
        height: 70vh !important;
        max-height: 600px;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
    }
    
    #lc-widget-container .lc-chat-header {
        padding: 20px;
    }
    
    #lc-widget-container .lc-chat-messages {
        padding: 15px;
    }
    
    #lc-widget-container .lc-message-content {
        max-width: 85%;
        font-size: 15px;
    }
    
    #lc-widget-container .lc-chat-input {
        padding: 15px 20px 20px;
    }
    
    #lc-widget-container .lc-message-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 14px 18px;
    }
    
    #lc-widget-container .lc-send-btn {
        width: 46px;
        height: 46px;
    }
    
    #lc-widget-container .lc-chat-actions {
        padding: 6px 15px;
    }
    
    #lc-widget-container .lc-email-input {
        padding: 10px 15px;
    }
    
    #lc-widget-container .lc-email-field {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

@media (max-width: 480px) {
    #lc-widget-container .lc-chat-window {
        height: 80vh !important;
        max-height: 100vh;
        border-radius: 15px 15px 0 0;
    }
    
    #lc-widget-container .lc-chat-header {
        padding: 16px;
    }
    
    #lc-widget-container .lc-header-info h3 {
        font-size: 15px;
    }
    
    #lc-widget-container .lc-chat-messages {
        padding: 12px;
    }
    
    #lc-widget-container .lc-message-content {
        max-width: 90%;
        padding: 12px 16px;
        font-size: 14px;
    }
    
    #lc-widget-container .lc-chat-input {
        padding: 12px 16px 16px;
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #lc-widget-container .lc-chat-window {
        height: 85vh !important;
    }
}
