/* HANNA AI - Ultra Premium Chat Widget v3.0 */
/* Glassmorphism + Animated Gradients + Apple-level Design */

/* ============================================ */
/* ROOT VARIABLES */
/* ============================================ */
:root {
    --hanna-primary: #8B5CF6;
    --hanna-secondary: #06B6D4;
    --hanna-accent: #F472B6;
    --hanna-glow: rgba(139, 92, 246, 0.5);
    --hanna-glass: rgba(255, 255, 255, 0.1);
    --hanna-glass-border: rgba(255, 255, 255, 0.2);
}

/* ============================================ */
/* MAIN CONTAINER */
/* ============================================ */
.whatsapp-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    touch-action: none;
}

/* ============================================ */
/* FLOATING AVATAR BUTTON - ULTRA PREMIUM */
/* ============================================ */
.chat-toggle {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Multi-layer gradient background */
    background:
        linear-gradient(135deg,
            var(--hanna-primary) 0%,
            #7C3AED 25%,
            var(--hanna-secondary) 50%,
            var(--hanna-accent) 75%,
            var(--hanna-primary) 100%);
    background-size: 400% 400%;
    animation: gradientFlow 8s ease infinite, floatBounce 3s ease-in-out infinite;

    /* Glassmorphism border */
    border: 2px solid rgba(255, 255, 255, 0.3);

    /* Premium shadow stack */
    box-shadow:
        0 4px 20px rgba(139, 92, 246, 0.4),
        0 8px 40px rgba(139, 92, 246, 0.2),
        0 0 0 0 rgba(139, 92, 246, 0.3),
        inset 0 1px 1px rgba(255, 255, 255, 0.3);
}

/* Animated gradient flow */
@keyframes gradientFlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Subtle floating animation */
@keyframes floatBounce {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-6px); }
}

/* Outer glow ring - animated */
.chat-toggle::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--hanna-primary), var(--hanna-secondary), var(--hanna-accent));
    background-size: 400% 400%;
    animation: gradientFlow 8s ease infinite;
    z-index: -1;
    opacity: 0.6;
    filter: blur(12px);
}

/* Tooltip - Premium glassmorphism */
.chat-toggle::after {
    content: attr(data-tooltip);
    position: absolute;
    right: calc(100% + 16px);
    top: 50%;
    transform: translateY(-50%) translateX(10px);

    /* Glassmorphism */
    background: rgba(17, 24, 39, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);

    color: white;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;

    /* Border glow */
    border: 1px solid rgba(139, 92, 246, 0.3);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);

    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10001;
    pointer-events: none;
}

/* Tooltip arrow */
.chat-toggle[data-tooltip]::before {
    content: '';
    position: absolute;
    right: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    border: 8px solid transparent;
    border-left-color: rgba(17, 24, 39, 0.9);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 10002;
}

.chat-toggle:hover::after,
.chat-toggle:hover[data-tooltip]::before {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
}

.chat-toggle:hover {
    transform: scale(1.08) translateY(-3px);
    box-shadow:
        0 8px 30px rgba(139, 92, 246, 0.5),
        0 12px 50px rgba(139, 92, 246, 0.3),
        0 0 60px rgba(139, 92, 246, 0.2),
        inset 0 1px 1px rgba(255, 255, 255, 0.4);
    animation: gradientFlow 8s ease infinite;
}

/* ============================================ */
/* MODERN AI ICON - NEURAL NETWORK DESIGN */
/* ============================================ */
.chat-toggle .hanna-mini-avatar {
    display: none !important;
}

.chat-toggle .chat-icon {
    display: none !important;
}

.chat-toggle .chat-indicator {
    display: none !important;
}

/* New modern AI icon container */
.hanna-icon-modern {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.hanna-ai-icon {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 8px rgba(139, 92, 246, 0.4));
    transition: all 0.3s ease;
}

.chat-toggle:hover .hanna-ai-icon {
    transform: scale(1.1);
    filter: drop-shadow(0 4px 16px rgba(139, 92, 246, 0.6));
}

/* Neural pattern pulse animation */
.neural-pattern {
    animation: neuralPulse 3s ease-in-out infinite;
}

@keyframes neuralPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Sparkle animations */
.sparkle {
    animation: sparkleFloat 2s ease-in-out infinite;
}

.sparkle-1 {
    animation-delay: 0s;
}

.sparkle-2 {
    animation-delay: 0.5s;
}

.sparkle-3 {
    animation-delay: 1s;
}

@keyframes sparkleFloat {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.3);
    }
}

/* ============================================ */
/* ONLINE INDICATOR - PREMIUM */
/* ============================================ */
.chat-toggle .online-dot {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #10B981 0%, #34D399 100%);
    border-radius: 50%;
    border: 3px solid white;
    box-shadow:
        0 2px 8px rgba(16, 185, 129, 0.5),
        0 0 0 0 rgba(16, 185, 129, 0.4);
    animation: onlinePulseGlow 2s ease-in-out infinite;
}

@keyframes onlinePulseGlow {
    0%, 100% {
        transform: scale(1);
        box-shadow:
            0 2px 8px rgba(16, 185, 129, 0.5),
            0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    50% {
        transform: scale(1.1);
        box-shadow:
            0 2px 8px rgba(16, 185, 129, 0.5),
            0 0 0 8px rgba(16, 185, 129, 0);
    }
}

/* ============================================ */
/* NOTIFICATION BADGE */
/* ============================================ */
.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: linear-gradient(135deg, #EF4444 0%, #F87171 100%);
    color: white;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    border: 2px solid white;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.5);
    animation: badgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10;
}

.chat-badge.hidden { display: none !important; }

@keyframes badgePop {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

/* ============================================ */
/* CHAT WINDOW - GLASSMORPHISM */
/* ============================================ */
.chat-window {
    position: absolute;
    bottom: 88px;
    right: 0;
    width: min(420px, calc(100vw - 48px));
    height: min(560px, calc(100vh - 140px));
    max-height: 75vh;

    /* Glassmorphism background */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);

    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(139, 92, 246, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);

    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;

    /* Resize support */
    resize: both;
    min-width: 340px;
    min-height: 420px;
}

.whatsapp-chat-widget .chat-window.active {
    display: flex !important;
    animation: windowSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes windowSlideIn {
    0% {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ============================================ */
/* CHAT HEADER - PREMIUM GRADIENT */
/* ============================================ */
.chat-header {
    background:
        linear-gradient(135deg,
            var(--hanna-primary) 0%,
            #7C3AED 40%,
            var(--hanna-secondary) 100%);
    background-size: 200% 200%;
    animation: headerGradient 10s ease infinite;

    color: white;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
}

@keyframes headerGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Shimmer effect on header */
.chat-header::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.15),
        transparent
    );
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

.chat-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
    z-index: 2;
}

/* ============================================ */
/* AVATAR IN HEADER */
/* ============================================ */
.chat-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
    border: 3px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 2;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Online indicator on header avatar */
.chat-avatar::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, #10B981, #34D399);
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.5);
}

/* ============================================ */
/* CHAT INFO */
/* ============================================ */
.chat-info {
    z-index: 2;
}

.chat-info h4 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-info .chat-subtitle {
    margin: 2px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
    font-weight: 500;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.status-dot.online {
    background: #10B981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.status-dot.offline {
    background: #EF4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

.status-dot.connecting {
    background: #F59E0B;
    animation: pulse 1.5s infinite;
}

#chatStatusText {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.9;
}

/* ============================================ */
/* HEADER BUTTONS */
/* ============================================ */
.chat-close, .chat-clear {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.chat-close:hover, .chat-clear:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

/* ============================================ */
/* MESSAGES AREA */
/* ============================================ */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto !important;
    overflow-x: hidden;
    background: linear-gradient(180deg, #F8FAFC 0%, #F1F5F9 100%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* Important for flex scroll */
    max-height: 400px;
    /* Reset any inherited text styles */
    text-shadow: none !important;
    -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.5);
}

/* ============================================ */
/* MESSAGE BUBBLES */
/* ============================================ */
.message {
    display: flex;
    max-width: 88%;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.received {
    align-self: flex-start;
}

.message.sent {
    align-self: flex-end;
}

.message-content {
    padding: 14px 18px;
    border-radius: 20px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Received messages */
.message.received .message-content {
    background: white;
    border-bottom-left-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Sent messages */
.message.sent .message-content {
    background: linear-gradient(135deg, var(--hanna-primary), #7C3AED);
    color: white;
    border-bottom-right-radius: 6px;
}

/* Force text color in received messages - CRITICAL for visibility */
.message.received .message-content,
.message.received .message-content p,
.message.received .message-content strong,
.message.received .message-content span,
.message.received .message-content * {
    color: #1F2937 !important;
    text-shadow: none !important;
    letter-spacing: normal;
}

.message-content p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

/* Markdown formatting in messages */
.message-content strong {
    font-weight: 700;
}

.message-content em {
    font-style: italic;
}

.message-content ul {
    margin: 8px 0;
    padding-left: 20px;
    list-style: none;
}

.message-content ul li {
    margin: 6px 0;
    position: relative;
    padding-left: 8px;
}

.message-content ul li::before {
    content: "•";
    position: absolute;
    left: -12px;
    color: var(--hanna-primary);
    font-weight: bold;
}

.message.sent .message-content ul li::before {
    color: rgba(255, 255, 255, 0.8);
}

/* Reset all text styles in messages to prevent inheritance */
.message-content,
.message-content * {
    text-shadow: none !important;
    letter-spacing: normal;
}

.message.sent .message-content p {
    color: white !important;
}

.message-time {
    font-size: 11px;
    color: #94A3B8;
    margin-top: 6px;
    display: block;
}

.message.sent .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* AI indicator */
.message.received.real-reply .message-content {
    border-left: 3px solid #10B981;
}

.message-origin {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

/* ============================================ */
/* TYPING INDICATOR */
/* ============================================ */
.typing-indicator .message-content {
    padding: 16px 20px;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
}

.typing-dots span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--hanna-primary), var(--hanna-secondary));
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================ */
/* INPUT AREA */
/* ============================================ */
.chat-input {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-input input {
    flex: 1;
    border: 2px solid #E2E8F0;
    border-radius: 24px;
    padding: 14px 20px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
    background: #F8FAFC;
}

.chat-input input:focus {
    border-color: var(--hanna-primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
}

.chat-input input::placeholder {
    color: #94A3B8;
}

.chat-input button {
    background: linear-gradient(135deg, var(--hanna-primary), #7C3AED);
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.chat-input button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.chat-input button svg {
    color: white;
    width: 20px;
    height: 20px;
}

/* ============================================ */
/* DARK THEME */
/* ============================================ */
body.dark-theme .chat-window {
    background: rgba(17, 24, 39, 0.95) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

body.dark-theme .chat-messages {
    background: linear-gradient(180deg, #0F172A 0%, #1E293B 100%) !important;
}

body.dark-theme .message.received .message-content {
    background: #1E293B !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: #E2E8F0 !important;
}

body.dark-theme .message.received .message-content p,
body.dark-theme .message.received .message-content strong,
body.dark-theme .message.received .message-content span,
body.dark-theme .message.received .message-content * {
    color: #E2E8F0 !important;
}

body.dark-theme .chat-input {
    background: #111827 !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

body.dark-theme .chat-input input {
    background: #1E293B !important;
    border-color: #374151 !important;
    color: white !important;
}

body.dark-theme .chat-input input::placeholder {
    color: #6B7280 !important;
}

body.dark-theme .message-time {
    color: #6B7280 !important;
}

/* ============================================ */
/* RESPONSIVE */
/* ============================================ */
@media (max-width: 768px) {
    .whatsapp-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    .chat-toggle {
        width: 64px;
        height: 64px;
    }

    .chat-toggle .hanna-mini-avatar {
        width: 44px;
        height: 44px;
    }

    .chat-window {
        width: calc(100vw - 32px);
        height: 500px;
        bottom: 84px;
        right: 0;
        border-radius: 20px;
    }
}

@media (max-width: 480px) {
    .chat-window {
        height: 75vh;
        max-height: 500px;
    }

    .chat-header {
        padding: 14px 16px;
    }

    .chat-avatar {
        width: 44px;
        height: 44px;
    }

    .chat-info h4 {
        font-size: 15px;
    }
}

/* ============================================ */
/* ANIMATION FOR NEW MESSAGE */
/* ============================================ */
.chat-toggle.has-new-messages {
    animation: newMessageAttention 1s ease-in-out;
}

@keyframes newMessageAttention {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.15) rotate(-5deg); }
    50% { transform: scale(1.15) rotate(5deg); }
    75% { transform: scale(1.15) rotate(-3deg); }
}

/* Pulse animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
