/* Chat Widget Styles */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: 'Rajdhani', sans-serif;
    /* Prevent being stuck at bottom */
    margin-bottom: env(safe-area-inset-bottom, 20px);
    transition: bottom 0.3s ease; /* Smooth transition if we change bottom */
}

/* Ensure chat widget stays above everything but below modals if any */
/* Also ensure it is not hidden by footer if necessary, though fixed position should handle it. 
   If the user means it disappears on scroll, fixed positioning is usually the answer. 
   However, maybe there is a z-index conflict or overflow issue on body/html */

.chat-toggle-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color, #00ffcc), var(--secondary-color, #0066ff));
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 255, 204, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
                box-shadow 0.3s ease;
    z-index: 1001;
    position: relative;
}

.chat-toggle-btn:hover {
    animation-play-state: paused;
    transform: scale(1.1) translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 255, 204, 0.7);
}

.chat-widget:not(.open) .chat-toggle-btn {
    animation: float 6s ease-in-out infinite;
}

@keyframes float {
    0% {
        box-shadow: 0 5px 15px 0px rgba(0,0,0,0.6);
        transform: translateY(0px);
    }
    50% {
        box-shadow: 0 25px 15px 0px rgba(0,0,0,0.2);
        transform: translateY(-20px);
    }
    100% {
        box-shadow: 0 5px 15px 0px rgba(0,0,0,0.6);
        transform: translateY(0px);
    }
}

.chat-toggle-btn .fa-times {
    display: none;
}

.chat-widget.open .chat-toggle-btn .fa-comment-dots {
    display: none;
}

.chat-widget:not(.open) .chat-toggle-btn .fa-comment-dots {
    animation: rotateIn 0.3s ease;
}

.chat-widget.open .chat-toggle-btn .fa-times {
    display: block;
    animation: rotateIn 0.3s ease;
}

@keyframes rotateIn {
    from { transform: rotate(-90deg); opacity: 0; }
    to { transform: rotate(0); opacity: 1; }
}

.chat-container {
    position: absolute;
    bottom: 90px;
    right: 0;
    width: 380px;
    height: 550px;
    background: rgba(10, 10, 26, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 255, 204, 0.3);
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6), 0 0 20px rgba(0, 255, 204, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
                transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.chat-widget.open .chat-container {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0) scale(1);
}

.chat-header {
    background: linear-gradient(135deg, rgba(0, 255, 204, 0.15), rgba(0, 102, 255, 0.15));
    padding: 18px 20px;
    border-bottom: 1px solid rgba(0, 255, 204, 0.3);
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
    position: sticky;
    top: 0;
    z-index: 1002;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary-color, #00ffcc), transparent);
}

.chat-header-icon {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color, #00ffcc), var(--secondary-color, #0066ff));
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.4);
    position: relative;
}

.chat-header-icon::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color, #00ffcc), transparent, var(--secondary-color, #0066ff));
    z-index: -1;
    animation: spin 4s linear infinite;
}

@keyframes spin {
    100% { transform: rotate(360deg); }
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header-title {
    color: var(--text-color, #ffffff);
    font-family: 'Orbitron', sans-serif;
    font-size: 17px;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.5px;
    text-shadow: 0 0 10px rgba(0, 255, 204, 0.3);
}

.chat-header-status {
    font-size: 13px;
    color: #00ffcc;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: #00ffcc;
    border-radius: 50%;
    box-shadow: 0 0 5px #00ffcc;
    animation: pulse 2s infinite;
}

.chat-close-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 18px;
    cursor: pointer;
    transition: color 0.3s ease, transform 0.3s ease;
    padding: 5px;
}

.chat-close-btn:hover {
    color: #ff3366;
    transform: scale(1.1) rotate(90deg);
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 204, 0.3);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 255, 204, 0.5);
}

.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: messageSlideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    letter-spacing: 0.3px;
}

@keyframes messageSlideIn {
    from { opacity: 0; transform: translateY(15px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.message.bot {
    align-self: flex-start;
    background: rgba(0, 255, 204, 0.08);
    border: 1px solid rgba(0, 255, 204, 0.2);
    color: var(--text-color, #ffffff);
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), inset 0 0 10px rgba(0, 255, 204, 0.05);
    backdrop-filter: blur(5px);
}

.message.bot::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 15px;
    height: 15px;
    background: radial-gradient(circle at top left, transparent 15px, rgba(0, 255, 204, 0.2) 16px);
    border-bottom-right-radius: 15px;
    z-index: -1;
}

.message.bot p {
    margin: 0 0 10px 0;
}

.message.bot p:last-child {
    margin-bottom: 0;
}

.message.bot ul, .message.bot ol {
    margin: 5px 0 10px 20px;
    padding: 0;
}

.message.bot li {
    margin-bottom: 5px;
}

.message.bot a {
    color: var(--primary-color, #00ffcc);
    text-decoration: none;
}

.message.bot a:hover {
    text-decoration: underline;
}

.message.bot code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.message.bot pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
}

.message.bot pre code {
    background: transparent;
    padding: 0;
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(0, 102, 255, 0.25), rgba(0, 255, 204, 0.15));
    border: 1px solid rgba(0, 102, 255, 0.3);
    color: var(--text-color, #ffffff);
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), inset 0 0 10px rgba(0, 102, 255, 0.1);
    backdrop-filter: blur(5px);
}

.message.user::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px;
    width: 15px;
    height: 15px;
    background: radial-gradient(circle at top right, transparent 15px, rgba(0, 102, 255, 0.3) 16px);
    border-bottom-left-radius: 15px;
    z-index: -1;
}

.message.user p {
    margin: 0;
}

.message.error {
    align-self: center;
    background: rgba(255, 51, 102, 0.1);
    border: 1px solid rgba(255, 51, 102, 0.3);
    color: #ff3366;
    font-size: 12px;
    text-align: center;
}

.typing-indicator {
    display: none;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 204, 0.1);
    width: fit-content;
    margin-left: 10px;
    margin-bottom: 15px;
    animation: fadeIn 0.3s ease;
}

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

.typing-dot {
    width: 6px;
    height: 6px;
    background: rgba(0, 255, 204, 0.7);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.chat-input-container {
    padding: 18px;
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid rgba(0, 255, 204, 0.2);
    display: flex;
    gap: 12px;
    align-items: center;
    position: relative;
}

.chat-input-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary-color, #00ffcc), transparent);
}

.chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(0, 255, 204, 0.3);
    border-radius: 25px;
    padding: 14px 20px;
    color: var(--text-color, #ffffff);
    font-family: 'Rajdhani', sans-serif;
    font-size: 15px;
    outline: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

.chat-input:focus {
    border-color: var(--primary-color, #00ffcc);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.3), inset 0 2px 5px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.chat-send-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color, #00ffcc), var(--secondary-color, #0066ff));
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 5px 15px rgba(0, 255, 204, 0.4);
    position: relative;
    overflow: hidden;
}

.chat-send-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.3s ease;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 255, 204, 0.6);
}

.chat-send-btn:hover:not(:disabled)::after {
    transform: translate(-50%, -50%) scale(1.5);
}

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

.chat-send-btn:disabled {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.2);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 255, 204, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(0, 255, 204, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 255, 204, 0); }
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .chat-container {
        width: calc(100vw - 40px);
        height: 500px;
        bottom: 80px;
        right: 20px;
        border-radius: 15px;
    }
    
    .chat-toggle-btn {
        width: 55px;
        height: 55px;
        font-size: 24px;
    }
    
    .chat-header {
        padding: 15px;
    }
    
    .chat-input-container {
        padding: 15px;
    }
    
    .chat-input {
        padding: 12px 15px;
    }
    
    .chat-send-btn {
        width: 45px;
        height: 45px;
        font-size: 16px;
    }
}
