/**
 * AI Chat Widget Styles
 */

:root {
    --spklc-primary: #6366f1;
    --spklc-primary-dark: #4f46e5;
    --spklc-white: #ffffff;
    --spklc-gray-50: #f9fafb;
    --spklc-gray-100: #f3f4f6;
    --spklc-gray-200: #e5e7eb;
    --spklc-gray-300: #d1d5db;
    --spklc-gray-400: #9ca3af;
    --spklc-gray-500: #6b7280;
    --spklc-gray-600: #4b5563;
    --spklc-gray-700: #374151;
    --spklc-gray-800: #1f2937;
    --spklc-success: #10b981;
    --spklc-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --spklc-radius: 16px;
    --spklc-ai-bg: #8b5cf6;
    --spklc-ai-text: #ffffff;
    --spklc-input-bg: #ffffff;
    --spklc-input-text: #1f2937;
}

/* Reset */
.spklc-widget, .spklc-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Widget Container */
.spklc-widget {
    position: fixed;
    z-index: 999999;
    font-size: 14px;
    line-height: 1.5;
}

.spklc-widget-bottom-right {
    bottom: 20px;
    right: 20px;
}

.spklc-widget-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Chat Bubble */
.spklc-chat-bubble {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--spklc-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4),
                0 0 0 0 rgba(99, 102, 241, 0.4);
    transition: transform 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

/* Pulsing rings for visibility */
.spklc-bubble-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 2px solid var(--spklc-primary);
    pointer-events: none;
    opacity: 0;
}

.spklc-ring-1 {
    width: 64px;
    height: 64px;
    animation: spklc-pulse-ring 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

.spklc-ring-2 {
    width: 64px;
    height: 64px;
    animation: spklc-pulse-ring 2s cubic-bezier(0.215, 0.61, 0.355, 1) 0.6s infinite;
}

.spklc-ring-3 {
    width: 64px;
    height: 64px;
    animation: spklc-pulse-ring 2s cubic-bezier(0.215, 0.61, 0.355, 1) 1.2s infinite;
}

@keyframes spklc-pulse-ring {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
    100% {
        transform: translate(-50%, -50%) scale(2.2);
        opacity: 0;
    }
}

/* Online status dot on bubble */
.spklc-bubble-status {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    background: #4ade80;
    border: 2px solid var(--spklc-white);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    animation: spklc-status-pulse 2s ease-in-out infinite;
}

@keyframes spklc-status-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(74, 222, 128, 0);
    }
}

.spklc-chat-bubble:hover {
    transform: scale(1.08);
    background: var(--spklc-primary-dark);
    box-shadow: 0 6px 30px rgba(99, 102, 241, 0.5),
                0 0 0 4px rgba(99, 102, 241, 0.15);
}

/* Hide pulsing rings on hover */
.spklc-chat-bubble:hover .spklc-bubble-ring {
    display: none;
}

/* Subtle float animation when idle */
.spklc-chat-bubble {
    animation: spklc-float 3s ease-in-out infinite;
}

@keyframes spklc-float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
}

.spklc-chat-bubble:hover {
    animation: none;
}

/* Left-positioned widget - label on the right side */
.spklc-widget-bottom-left .spklc-bubble-label {
    right: auto;
    left: 100%;
    margin-right: 0;
    margin-left: 12px;
    flex-direction: row-reverse;
}

.spklc-widget-bottom-left .spklc-chat-bubble:hover .spklc-bubble-label {
    transform: translateY(-50%) translateX(4px);
}

.spklc-widget-bottom-left .spklc-label-arrow {
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: none;
    border-right: 8px solid var(--spklc-primary);
    filter: drop-shadow(-2px 0 2px rgba(99, 102, 241, 0.2));
}

.spklc-bubble-icon {
    width: 30px;
    height: 30px;
    color: var(--spklc-white);
    transition: opacity 0.2s ease, transform 0.2s ease;
    position: relative;
    z-index: 2;
}

/* Live Support Label */
.spklc-bubble-label {
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    margin-right: 12px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    white-space: nowrap;
    z-index: 1000;
}

.spklc-chat-bubble:hover .spklc-bubble-label {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(-4px);
}

.spklc-label-text {
    background: var(--spklc-primary);
    color: var(--spklc-white);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
    letter-spacing: 0.3px;
}

.spklc-label-arrow {
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 8px solid var(--spklc-primary);
    filter: drop-shadow(2px 0 2px rgba(99, 102, 241, 0.2));
}

.spklc-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.spklc-widget.spklc-open .spklc-icon-chat {
    opacity: 0;
    transform: rotate(90deg);
}

.spklc-widget.spklc-open .spklc-icon-close {
    opacity: 1;
    transform: rotate(0);
}

.spklc-unread-count {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 22px;
    height: 22px;
    background: #ef4444;
    color: var(--spklc-white);
    font-size: 12px;
    font-weight: 600;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    animation: spklc-bounce 0.5s ease;
}

@keyframes spklc-bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Chat Window */
.spklc-chat-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--spklc-white);
    border-radius: var(--spklc-radius);
    box-shadow: var(--spklc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: spklc-slideUp 0.3s ease;
}

.spklc-widget-bottom-right .spklc-chat-window {
    right: 0;
}

.spklc-widget-bottom-left .spklc-chat-window {
    left: 0;
}

@keyframes spklc-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.spklc-chat-window.spklc-embedded {
    position: relative;
    bottom: auto;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: var(--spklc-radius);
}

/* Header */
.spklc-chat-header {
    background: var(--spklc-primary);
    color: var(--spklc-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.spklc-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.spklc-header-avatar,
.spklc-header-avatar-placeholder {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spklc-header-avatar {
    object-fit: cover;
}

.spklc-header-avatar-placeholder svg {
    width: 28px;
    height: 28px;
    fill: var(--spklc-white);
}

.spklc-header-title {
    display: block;
    font-weight: 600;
    font-size: 16px;
}

.spklc-header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    opacity: 0.9;
}

.spklc-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--spklc-gray-400);
}

.spklc-header-status.spklc-online .spklc-status-dot {
    background: #4ade80;
}

.spklc-header-status.spklc-offline .spklc-status-dot {
    background: var(--spklc-gray-400);
}

.spklc-header-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.spklc-header-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.spklc-header-close svg {
    width: 18px;
    height: 18px;
    color: var(--spklc-white);
}

/* Consent Screen */
.spklc-consent-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    background: var(--spklc-gray-50);
}

.spklc-consent-content {
    text-align: center;
    max-width: 300px;
}

.spklc-consent-content h3 {
    font-size: 20px;
    color: var(--spklc-gray-800);
    margin-bottom: 12px;
}

.spklc-consent-content p {
    color: var(--spklc-gray-600);
    margin-bottom: 24px;
    font-size: 14px;
}

.spklc-consent-form {
    text-align: left;
}

.spklc-input-group {
    margin-bottom: 12px;
}

.spklc-input-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--spklc-gray-300);
    border-radius: 10px;
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.spklc-input-group input:focus {
    outline: none;
    border-color: var(--spklc-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.spklc-consent-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 16px 0;
    cursor: pointer;
    font-size: 13px;
    color: var(--spklc-gray-600);
}

.spklc-consent-checkbox input {
    margin-top: 2px;
    accent-color: var(--spklc-primary);
}

.spklc-consent-btn {
    width: 100%;
    padding: 14px;
    background: var(--spklc-primary);
    color: var(--spklc-white);
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.spklc-consent-btn:hover {
    background: var(--spklc-primary-dark);
}

.spklc-consent-btn:disabled {
    background: var(--spklc-gray-300);
    cursor: not-allowed;
}

/* Messages Area */
.spklc-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--spklc-gray-50);
    display: flex;
    flex-direction: column;
}

.spklc-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message */
.spklc-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: spklc-fadeIn 0.3s ease;
}

@keyframes spklc-fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.spklc-message.spklc-visitor {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.spklc-message.spklc-admin,
.spklc-message.spklc-ai {
    align-self: flex-start;
}

.spklc-message.spklc-system {
    align-self: center;
    max-width: 90%;
}

.spklc-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}

.spklc-message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

.spklc-message.spklc-visitor .spklc-message-bubble {
    background: var(--spklc-primary);
    color: var(--spklc-white);
    border-bottom-right-radius: 4px;
}

.spklc-message.spklc-admin .spklc-message-bubble,
.spklc-message.spklc-ai .spklc-message-bubble {
    background: var(--spklc-white);
    color: var(--spklc-gray-800);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.spklc-message.spklc-ai .spklc-message-bubble {
    background: var(--spklc-ai-bg, #8b5cf6);
    color: var(--spklc-ai-text, #ffffff);
    border: none;
}

.spklc-message.spklc-system .spklc-message-bubble {
    background: transparent;
    color: var(--spklc-gray-500);
    font-size: 12px;
    text-align: center;
    padding: 8px;
}

.spklc-message-text {
    margin: 0;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.spklc-message-text .spklc-auto-link {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

.spklc-message-text strong {
    font-weight: 600;
}

.spklc-message-time {
    font-size: 11px;
    margin-top: 4px;
    opacity: 0.7;
}

.spklc-message.spklc-visitor .spklc-message-time {
    text-align: right;
}

/* File Message */
.spklc-message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    margin-top: 8px;
}

.spklc-file-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--spklc-gray-200);
    border-radius: 8px;
}

.spklc-file-info {
    flex: 1;
    min-width: 0;
}

.spklc-file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.spklc-file-size {
    font-size: 12px;
    opacity: 0.7;
}

.spklc-message-image img {
    max-width: 200px;
    border-radius: 8px;
    cursor: pointer;
}

/* Typing Indicator */
.spklc-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
}

.spklc-typing-dots {
    display: flex;
    gap: 4px;
}

.spklc-typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--spklc-gray-400);
    border-radius: 50%;
    animation: spklc-typingDot 1.4s infinite ease-in-out;
}

.spklc-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.spklc-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes spklc-typingDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.spklc-typing-text {
    font-size: 13px;
    color: var(--spklc-gray-500);
}

/* AI Thinking Indicator */
.spklc-thinking-message .spklc-message-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.spklc-thinking-message .spklc-thinking-dots {
    display: flex;
    gap: 4px;
}

.spklc-thinking-message .spklc-thinking-dots span {
    width: 8px;
    height: 8px;
    background: currentColor;
    border-radius: 50%;
    animation: spklc-thinkingDot 1.4s infinite ease-in-out;
}

.spklc-thinking-message .spklc-thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.spklc-thinking-message .spklc-thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.spklc-thinking-message .spklc-thinking-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes spklc-thinkingDot {
    0%, 80%, 100% { 
        transform: scale(0.6); 
        opacity: 0.5; 
    }
    40% { 
        transform: scale(1); 
        opacity: 1; 
    }
}

.spklc-thinking-text {
    font-size: 13px;
    font-style: italic;
    opacity: 0.9;
    color: black;
}

/* Input Area */
.spklc-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: var(--spklc-white);
    border-top: 1px solid var(--spklc-gray-200);
}

.spklc-attach-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--spklc-gray-500);
    border-radius: 8px;
    transition: background 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}

.spklc-attach-btn:hover {
    background: var(--spklc-gray-100);
    color: var(--spklc-primary);
}

.spklc-attach-btn svg {
    width: 20px;
    height: 20px;
}

.spklc-input-wrapper {
    flex: 1;
    background: var(--spklc-input-bg, var(--spklc-gray-100));
    border-radius: 20px;
    padding: 8px 16px;
}

#spklc-input {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--spklc-input-text, var(--spklc-gray-800));
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    max-height: 100px;
    min-height: 24px;
}

#spklc-input:focus {
    outline: none;
}

#spklc-input::placeholder {
    color: var(--spklc-gray-400);
}

.spklc-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--spklc-primary);
    color: var(--spklc-white);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.spklc-send-btn:hover {
    background: var(--spklc-primary-dark);
    transform: scale(1.05);
}

.spklc-send-btn:disabled {
    background: var(--spklc-gray-300);
    cursor: not-allowed;
    transform: none;
}

.spklc-send-btn svg {
    width: 20px;
    height: 20px;
}

/* Rating Screen */
.spklc-rating-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--spklc-white);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    z-index: 10;
}

.spklc-rating-content {
    text-align: center;
    max-width: 280px;
}

.spklc-rating-content h3 {
    font-size: 18px;
    color: var(--spklc-gray-800);
    margin-bottom: 20px;
}

.spklc-rating-stars {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.spklc-rating-stars button {
    font-size: 32px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--spklc-gray-300);
    transition: color 0.2s ease, transform 0.2s ease;
    padding: 4px;
}

.spklc-rating-stars button:hover,
.spklc-rating-stars button.spklc-active {
    color: #fbbf24;
    transform: scale(1.2);
}

#spklc-rating-feedback {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--spklc-gray-300);
    border-radius: 10px;
    resize: none;
    height: 80px;
    font-size: 14px;
    margin-bottom: 16px;
}

#spklc-rating-feedback:focus {
    outline: none;
    border-color: var(--spklc-primary);
}

.spklc-rating-submit {
    width: 100%;
    padding: 12px;
    background: var(--spklc-primary);
    color: var(--spklc-white);
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
}

.spklc-rating-submit:hover {
    background: var(--spklc-primary-dark);
}

.spklc-rating-skip {
    background: none;
    border: none;
    color: var(--spklc-gray-500);
    cursor: pointer;
    font-size: 14px;
}

.spklc-rating-skip:hover {
    color: var(--spklc-gray-700);
}

/* Powered By */
.spklc-powered-by {
    padding: 8px;
    text-align: center;
    font-size: 11px;
    color: var(--spklc-gray-400);
    background: var(--spklc-gray-50);
    border-top: 1px solid var(--spklc-gray-100);
}

/* Embedded Styles */
.spklc-widget-embedded {
    border-radius: var(--spklc-radius);
    overflow: hidden;
    box-shadow: var(--spklc-shadow);
}

.spklc-widget-embedded .spklc-chat-window {
    position: relative;
    bottom: auto;
    width: 100%;
    height: 100%;
    border-radius: 0;
}

/* Mobile Styles */
@media (max-width: 480px) {
    .spklc-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .spklc-chat-bubble {
        width: 58px;
        height: 58px;
    }

    .spklc-bubble-ring {
        display: none;
    }

    .spklc-bubble-icon {
        width: 26px;
        height: 26px;
    }

    /* Hide label on mobile - always show bubble without label */
    .spklc-bubble-label {
        display: none;
    }
}

/* Scrollbar */
.spklc-messages-area::-webkit-scrollbar {
    width: 6px;
}

.spklc-messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.spklc-messages-area::-webkit-scrollbar-thumb {
    background: var(--spklc-gray-300);
    border-radius: 3px;
}

.spklc-messages-area::-webkit-scrollbar-thumb:hover {
    background: var(--spklc-gray-400);
}
