body {
    touch-action: manipulation;
    /* Prevents double-tap to zoom */
}

/* Chat Container */
.support-chat-wrapper {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Outfit', sans-serif;
    touch-action: manipulation;
    /* Prevent double tap zoom */
}

/* Floating Button */
.chat-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 122, 255, 0.4);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border: none;
    outline: none;
    pointer-events: all;
    visibility: visible;
}

.chat-trigger.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.5) rotate(-20deg);
    pointer-events: none;
}

.chat-trigger:hover {
    transform: scale(1.1) translateY(-5px);
}

.chat-trigger i {
    width: 28px;
    height: 28px;
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 550px;
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(60px) saturate(200%);
    backdrop-filter: blur(60px) saturate(200%);
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    display: flex;
    /* Always flex, control visibility via visibility/opacity */
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform-origin: bottom right;
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8) translateY(40px) rotate(2deg);
    pointer-events: none;
}

.chat-window.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0) rotate(0deg);
    pointer-events: all;
}

/* Chat Header */
.chat-header {
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.chat-header h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-status {
    font-size: 0.8rem;
    color: #4cd964;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #4cd964;
    border-radius: 50%;
}

.close-chat {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: none;
    /* Hide for Firefox */
    -ms-overflow-style: none;
    /* Hide for IE/Edge */
}

.chat-messages::-webkit-scrollbar {
    display: none;
    /* Hide for Chrome/Safari */
}

.message {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.message a {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
    transition: opacity 0.2s;
}

.message a:hover {
    opacity: 0.8;
}

.message.bot {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    animation: botMessageIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message.user {
    align-self: flex-end;
    background: var(--accent-gradient);
    color: white;
    border-bottom-right-radius: 4px;
    animation: userMessageIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes botMessageIn {
    from {
        opacity: 0;
        transform: translateX(-20px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes userMessageIn {
    from {
        opacity: 0;
        transform: translateX(20px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.typing-indicator {
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    display: none;
    align-self: flex-start;
    gap: 6px;
    margin: 8px 0 16px 24px;
    /* Added margins to prevent "clamping" */
    animation: botMessageIn 0.3s ease-out;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    display: block;
    animation: typing 1s infinite alternate;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    from {
        opacity: 0.3;
    }

    to {
        opacity: 1;
    }
}

/* Chat Input Area */
.chat-footer {
    padding: 16px;
    border-top: 1px solid var(--glass-border);
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    border: 1px solid var(--glass-border);
    transition: border-color 0.3s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent-primary);
}

.chat-input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    padding: 10px 0;
    font-size: 16px;
    /* Crucial: 16px or more prevents iOS zoom */
}

.send-message {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.send-message:hover {
    transform: scale(1.05);
}

.send-message:active {
    transform: scale(0.95);
}

/* Mobile Version */
@media (max-width: 768px) {
    .support-chat-wrapper {
        bottom: 16px;
        right: 16px;
    }

    .chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        z-index: 10001;
    }

    .chat-window.active {
        display: flex;
    }
}