.matrix-chatbot {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9998;
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    will-change: transform, bottom, right;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00ff41 0%, #00d634 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 255, 65, 0.4),
                0 0 40px rgba(0, 255, 65, 0.2);
    transition: all 0.3s ease;
    position: relative;
    animation: float 3s ease-in-out infinite;
    -webkit-tap-highlight-color: transparent;
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    will-change: transform;
}

@keyframes float {
    0%, 100% { transform: translate3d(0, 0px, 0); }
    50% { transform: translate3d(0, -10px, 0); }
}

/* Simplified animations for Android */
@keyframes floatSimple {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-8px); }
}

@keyframes ghostGlowSimple {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

@keyframes pulseSimple {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.3);
        opacity: 0;
    }
}

.ghost-icon {
    font-size: 28px;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8));
    animation: ghostGlow 2s ease-in-out infinite;
}

@keyframes ghostGlow {
    0%, 100% { filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8)); }
    50% { filter: drop-shadow(0 0 20px rgba(0, 255, 65, 1)); }
}

.pulse-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid rgba(0, 255, 65, 0.6);
    animation: pulse 2s cubic-bezier(0.24, 0, 0.38, 1) infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-15deg); }
    75% { transform: rotate(15deg); }
}

@keyframes attentionGlow {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(0, 255, 65, 0.3),
                    0 0 40px rgba(0, 255, 65, 0.2);
    }
    50% { 
        box-shadow: 0 0 30px rgba(0, 255, 65, 0.6),
                    0 0 60px rgba(0, 255, 65, 0.4),
                    0 0 80px rgba(0, 255, 65, 0.2);
    }
}

.chatbot-toggle.attention-seeking {
    animation: attentionGlow 1s ease-in-out infinite;
}

.chatbot-toggle.attention-seeking .ghost-icon {
    animation: wiggle 0.5s ease-in-out infinite;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 255, 65, 0.6),
                0 0 60px rgba(0, 255, 65, 0.3);
}

.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
    border: 2px solid #00ff41;
    border-radius: 15px;
    display: none;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8),
                0 0 80px rgba(0, 255, 65, 0.2);
    overflow: hidden;
}

body.ios-device .chatbot-window {
    position: fixed !important;
    left: 50% !important;
    right: auto !important;
    margin-left: -190px !important;
}

.chatbot-window.active {
    display: flex;
    animation: slideUp 0.3s ease-out;
}

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

.chatbot-header {
    background: linear-gradient(90deg, #00ff41 0%, #00d634 100%);
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.chatbot-header h3 {
    color: #000;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 18px;
    text-transform: uppercase;
    letter-spacing: 2px;
    z-index: 2;
    position: relative;
}

.version {
    font-size: 12px;
    opacity: 0.8;
    font-weight: 400;
}

.matrix-rain {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"><text y="10" font-family="monospace" font-size="10" fill="%23000" opacity="0.1">10101</text></svg>');
    animation: matrixRain 10s linear infinite;
    opacity: 0.3;
}

@keyframes matrixRain {
    from { transform: translateY(-100%); }
    to { transform: translateY(100%); }
}

.close-btn {
    background: transparent;
    border: none;
    color: #000;
    font-size: 28px;
    cursor: pointer;
    z-index: 2;
    transition: transform 0.2s;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    transform: scale(1.2) rotate(90deg);
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #0a0a0a;
    font-family: 'Roboto Mono', monospace;
}

.chatbot-messages::-webkit-scrollbar {
    width: 8px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #00ff41;
    border-radius: 4px;
}

.bot-message, .user-message {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 8px;
    animation: messageAppear 0.3s ease-out;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.bot-message {
    background: linear-gradient(135deg, rgba(0, 255, 65, 0.1) 0%, rgba(0, 255, 65, 0.05) 100%);
    border-left: 3px solid #00ff41;
    color: #00ff41;
}

.user-message {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-left: 3px solid #fff;
    color: #fff;
    margin-left: 20px;
}

.message-prefix {
    font-weight: bold;
    color: #00ff41;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: block;
    margin-bottom: 5px;
}

.user-message .message-prefix {
    color: #fff;
}

.message-text {
    font-size: 14px;
    line-height: 1.5;
}

.typing-effect .message-text {
    animation: typing 1s steps(40, end);
}

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

.chatbot-input-area {
    padding: 15px;
    background: #1a1a1a;
    border-top: 1px solid rgba(0, 255, 65, 0.3);
    display: flex;
    gap: 10px;
}

.chat-input {
    flex: 1;
    background: #0a0a0a;
    border: 1px solid rgba(0, 255, 65, 0.3);
    color: #00ff41;
    padding: 10px 15px;
    border-radius: 25px;
    font-family: 'Roboto Mono', monospace;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.chat-input::placeholder {
    color: rgba(0, 255, 65, 0.4);
}

.chat-input:focus {
    border-color: #00ff41;
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.2);
}

.send-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00ff41 0%, #00d634 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.5);
}

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

.send-icon {
    color: #000;
    font-size: 18px;
    font-weight: bold;
}

.loading-dots {
    display: inline-block;
}

.loading-dots::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60% { content: '...'; }
    80%, 100% { content: ''; }
}

@media (max-width: 480px) {
    .chatbot-window {
        width: 90vw !important;
        max-height: 85vh;
        right: 5vw !important;
        bottom: 80px;
        border-radius: 12px;
    }
    
    body.ios-device .chatbot-window {
        width: 90vw !important;
        left: 50% !important;
        right: auto !important;
        margin-left: -45vw !important;
    }
    
    body.android-device .chatbot-window {
        position: fixed !important;
        height: calc(100vh - 150px);
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
        bottom: 75px;
    }
    
    .chatbot-toggle {
        position: absolute !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 50px;
        height: 50px;
        z-index: 9998 !important;
    }
    
    .ghost-icon {
        font-size: 24px;
    }
    
    .chatbot-header {
        padding: 12px;
    }
    
    .chatbot-header h3 {
        font-size: 16px;
    }
    
    .chatbot-messages {
        padding: 15px;
        font-size: 13px;
    }
    
    .message-text {
        font-size: 13px;
    }
    
    .chatbot-input-area {
        padding: 12px;
        gap: 8px;
    }
    
    .chat-input {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .send-btn {
        width: 40px;
        height: 40px;
    }
    
    .send-icon {
        font-size: 16px;
    }
    
    .quick-questions {
        padding: 8px;
        max-height: 50px;
    }
    
    .quick-questions button {
        padding: 3px 6px;
        font-size: 10px;
    }
}

@media (max-width: 375px) {
    .chatbot-window {
        width: 92vw !important;
        max-height: 85vh;
        right: 4vw !important;
        bottom: 80px;
    }
    
    body.ios-device .chatbot-window {
        width: 92vw !important;
        left: 50% !important;
        right: auto !important;
        margin-left: -46vw !important;
    }
    
    body.android-device .chatbot-window {
        position: fixed !important;
        height: calc(100vh - 140px);
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
        bottom: 75px;
    }
    
    .chatbot-toggle {
        position: fixed !important;
        right: 8px !important;
        bottom: 8px !important;
        width: 50px;
        height: 50px;
    }
    
    .ghost-icon {
        font-size: 26px;
    }
    
    .chatbot-header h3 {
        font-size: 14px;
        letter-spacing: 1px;
    }
    
    .chatbot-messages {
        padding: 12px;
    }
    
    .bot-message, .user-message {
        padding: 10px;
        margin-bottom: 12px;
    }
    
    .message-prefix {
        font-size: 11px;
    }
    
    .message-text {
        font-size: 12px;
        line-height: 1.4;
    }
}

@media (max-width: 320px) {
    .chatbot-window {
        width: 94vw !important;
        max-height: 85vh;
        right: 3vw !important;
        bottom: 75px;
        border-radius: 10px;
    }
    
    body.ios-device .chatbot-window {
        width: 94vw !important;
        left: 50% !important;
        right: auto !important;
        margin-left: -47vw !important;
    }
    
    body.android-device .chatbot-window {
        position: fixed !important;
        height: calc(100vh - 130px);
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
        bottom: 70px;
    }
    
    .chatbot-toggle {
        position: fixed !important;
        right: 5px !important;
        bottom: 5px !important;
        width: 48px;
        height: 48px;
    }
    
    .ghost-icon {
        font-size: 24px;
    }
    
    .chatbot-header {
        padding: 10px;
    }
    
    .chatbot-header h3 {
        font-size: 13px;
    }
    
    .close-btn {
        font-size: 24px;
        width: 26px;
        height: 26px;
    }
    
    .chatbot-input-area {
        padding: 10px;
    }
    
    .chat-input {
        padding: 7px 10px;
        font-size: 13px;
    }
    
    .send-btn {
        width: 36px;
        height: 36px;
    }
    
    .send-icon {
        font-size: 14px;
    }
}

/* Landscape mode for phones */
@media (max-height: 500px) and (orientation: landscape) {
    .chatbot-window {
        height: calc(100vh - 60px);
        bottom: 55px;
    }
    
    .chatbot-toggle {
        bottom: 10px;
        right: 10px;
        width: 45px;
        height: 45px;
    }
    
    .ghost-icon {
        font-size: 24px;
    }
    
    .chatbot-header {
        padding: 8px 12px;
    }
    
    .chatbot-header h3 {
        font-size: 14px;
    }
    
    .chatbot-messages {
        padding: 10px;
    }
    
    .chatbot-input-area {
        padding: 8px;
    }
    
    .chat-input {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .send-btn {
        width: 35px;
        height: 35px;
    }
    
    .quick-questions {
        display: none; /* Hide quick questions in landscape to save space */
    }
}

/* Ensure chatbot doesn't overlap with mobile navigation */
@media (max-width: 768px) {
    .matrix-chatbot {
        z-index: 9997; /* Below mobile menu which is usually 10000+ */
        bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
        right: 15px !important;
        position: fixed !important;
        transform: translate3d(0, 0, 0) !important;
        -webkit-transform: translate3d(0, 0, 0) !important;
        will-change: auto !important;
    }
    
    .chatbot-window {
        max-height: calc(100vh - 100px);
        max-width: calc(100vw - 20px);
    }
    
    /* Prevent text selection issues on mobile */
    .chatbot-messages {
        -webkit-touch-callout: text;
        -webkit-user-select: text;
        -khtml-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
    
    /* Improve tap targets */
    .close-btn,
    .send-btn,
    .chatbot-toggle {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Fix iOS Safari input zoom */
    .chat-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    @supports (-webkit-touch-callout: none) {
        /* iOS specific fixes */
        .chatbot-window {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}

/* Fix for notched phones (iPhone X and later) */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .chatbot-window {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}

/* Ensure smooth scrolling on mobile */
.chatbot-messages {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* iOS specific fixes */
@media (max-width: 768px) {
    body.ios-device .chatbot-window {
        height: 80vh !important;
        max-height: 600px !important;
        position: fixed !important;
        left: 50% !important;
        right: auto !important;
        margin-left: -45vw !important;
    }
}

/* Ensure chatbot button stays visible on all devices */
@media screen and (max-height: 600px) {
    .matrix-chatbot {
        bottom: 10px !important;
        right: 10px !important;
    }
    
    .chatbot-toggle {
        width: 45px !important;
        height: 45px !important;
    }
    
    .ghost-icon {
        font-size: 22px !important;
    }
}

/* Fix for server-portal page specifically */
body.server-portal-page .matrix-chatbot,
body[class*="server-portal"] .matrix-chatbot {
    position: fixed !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 25px) !important;
    right: 20px !important;
    z-index: 9999 !important;
}

body.server-portal-page .chatbot-toggle,
body[class*="server-portal"] .chatbot-toggle {
    position: relative !important;
    right: 0 !important;
    bottom: 0 !important;
}

/* Ensure visibility on mobile for server portal */
@media (max-width: 768px) {
    body.server-portal-page .matrix-chatbot,
    body[class*="server-portal"] .matrix-chatbot {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 30px) !important;
        right: 15px !important;
    }
}

/* Fix virtual keyboard issues */
@media (max-width: 768px) {
    .chatbot-window.keyboard-open {
        height: calc(100vh - 350px); /* Adjust when keyboard is open */
    }
}

/* Android-specific fixes for position fixed issues */
@supports not (-webkit-touch-callout: none) {
    /* Not iOS = likely Android */
    .matrix-chatbot {
        position: fixed !important;
        will-change: auto !important;
    }
    
    /* Keep animations but optimize for Android */
    .chatbot-toggle {
        animation: floatSimple 3s ease-in-out infinite !important;
        transform: translate3d(0, 0, 0);
        -webkit-transform: translate3d(0, 0, 0);
    }
    
    .ghost-icon {
        animation: ghostGlowSimple 2s ease-in-out infinite !important;
    }
    
    .pulse-ring {
        animation: pulseSimple 2s cubic-bezier(0.24, 0, 0.38, 1) infinite !important;
    }
    
    @media (max-width: 768px) {
        .matrix-chatbot {
            bottom: 25px !important;
            right: 15px !important;
            position: fixed !important;
        }
        
        /* Use simpler animations on Android mobile */
        .chatbot-toggle {
            animation: floatSimple 3s ease-in-out infinite !important;
        }
    }
}

/* Alternative Android detection using aspect-ratio */
@media (pointer: coarse) and (hover: none) and (max-width: 768px) {
    /* Touch devices without hover = mobile */
    @supports not (-webkit-touch-callout: none) {
        /* Not iOS = Android */
        .matrix-chatbot {
            position: fixed !important;
            bottom: 30px !important;
            right: 15px !important;
            transform: none !important;
            -webkit-transform: none !important;
        }
        
        .chatbot-toggle {
            position: relative !important;
            animation: floatSimple 3s ease-in-out infinite !important;
        }
    }
}