/* Chat Widget CSS - Cyber Theme */
:root {
    --cyber-primary: #00f3ff;
    --cyber-secondary: #00ff00;
    --cyber-bg: #0a0a0a;
    --cyber-panel: rgba(10, 10, 10, 0.95);
    --cyber-border: 1px solid var(--cyber-primary);
    --cyber-shadow: 0 0 10px rgba(0, 243, 255, 0.3);
    --cyber-text: #fff;
    --cyber-text-dim: #aaa;
    /* Safe area insets for notched devices */
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

#neuro-chat-widget {
    position: fixed;
    bottom: calc(20px + var(--safe-area-bottom));
    right: calc(20px + var(--safe-area-right));
    z-index: 10000;
    font-family: 'Exo', sans-serif;
    /* Prevent causing overflow - stay within viewport */
    max-width: calc(100vw - 40px);
}

/* Floating Toggle Button */
#neuro-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #003333, #000);
    border: 2px solid var(--cyber-primary);
    box-shadow: var(--cyber-shadow), 0 0 20px var(--cyber-primary);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
}

#neuro-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 0 30px var(--cyber-primary);
}

#neuro-chat-toggle i {
    font-size: 24px;
    color: var(--cyber-primary);
    z-index: 2;
}

#neuro-chat-toggle::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(0, 243, 255, 0.1), transparent);
    transform: rotate(45deg);
    animation: shine 3s infinite;
}

@keyframes shine {
    0% {
        transform: translateX(-100%) rotate(45deg);
    }

    100% {
        transform: translateX(100%) rotate(45deg);
    }
}

/* Chat Window */
#neuro-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    min-width: 300px;
    min-height: 400px;
    background: var(--cyber-panel);
    border: var(--cyber-border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(0, 243, 255, 0.05);
    transform-origin: bottom right;
    transform: scale(0);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    overflow: hidden;
    backdrop-filter: blur(10px);

    /* Allow resizing - requires overflow to be something other than visible */
    resize: both;
    overflow: auto;
}

#neuro-chat-window.open {
    transform: scale(1);
    opacity: 1;
}

/* Header */
.neuro-header {
    padding: 15px;
    background: rgba(0, 243, 255, 0.1);
    border-bottom: 1px solid rgba(0, 243, 255, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.neuro-title {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--cyber-primary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.neuro-status {
    width: 8px;
    height: 8px;
    background: var(--cyber-primary);
    border-radius: 50%;
    box-shadow: 0 0 5px var(--cyber-primary);
    animation: pulse 2s infinite;
}

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

    50% {
        transform: scale(1.5);
        opacity: 0.5;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.neuro-close {
    background: none;
    border: none;
    color: var(--cyber-text-dim);
    cursor: pointer;
    font-size: 16px;
    transition: color 0.2s;
}

.neuro-close:hover {
    color: #fff;
}

/* Messages Area */
.neuro-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
    width: 100%;
    box-sizing: border-box;
}

.neuro-messages::-webkit-scrollbar {
    width: 5px;
}

.neuro-messages::-webkit-scrollbar-thumb {
    background: var(--cyber-primary);
    border-radius: 2px;
}

.neuro-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

.message {
    max-width: 85%;
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    animation: fadeIn 0.3s ease-out;
    flex-shrink: 0;
    /* Prevent shrinking when container is full */

    /* Robust text wrapping */
    word-wrap: break-word;
    overflow-wrap: anywhere;
    /* Ensures even long seamless strings break */
    white-space: pre-line;
    /* Preserves explicit newlines */
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot {
    align-self: flex-start;
    background: rgba(0, 243, 255, 0.1);
    border-left: 3px solid var(--cyber-primary);
    color: #eee;
}

.message.user {
    align-self: flex-end;
    background: rgba(0, 255, 0, 0.1);
    border-right: 3px solid var(--cyber-secondary);
    color: #eee;
    text-align: right;
}

.message.system {
    align-self: center;
    background: rgba(255, 0, 0, 0.1);
    border: 1px solid rgba(255, 0, 0, 0.3);
    color: #ff6b6b;
    font-size: 12px;
    text-align: center;
    width: 100%;
}

.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 15px;
    align-self: flex-start;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--cyber-primary);
    border-radius: 50%;
    animation: bounce 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 bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Input Area */
.neuro-input-area {
    padding: 15px;
    background: rgba(0, 0, 0, 0.5);
    border-top: 1px solid rgba(0, 243, 255, 0.2);
    display: flex;
    gap: 10px;
    position: relative;
}

.neuro-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(0, 243, 255, 0.3);
    border-radius: 20px;
    padding: 10px 15px;
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

.neuro-input:focus {
    border-color: var(--cyber-primary);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.1);
}

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

.neuro-send:hover {
    transform: scale(1.1);
}

.neuro-send:disabled {
    background: #555;
    cursor: not-allowed;
    transform: none;
}

/* Limit Counter */
.limit-counter {
    position: absolute;
    top: -20px;
    right: 15px;
    font-size: 10px;
    color: var(--cyber-text-dim);
}

/* Auth Prompt */
.auth-prompt {
    text-align: center;
}

.auth-btn {
    margin-top: 10px;
    padding: 5px 15px;
    background: var(--cyber-primary);
    border: none;
    border-radius: 5px;
    color: #000;
    font-weight: bold;
    cursor: pointer;
    font-size: 12px;
}

.auth-btn:hover {
    box-shadow: 0 0 10px var(--cyber-primary);
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    #neuro-chat-widget {
        position: fixed;
        bottom: calc(15px + var(--safe-area-bottom, 0px));
        right: calc(15px + var(--safe-area-right, 0px));
        left: auto;
        top: auto;
        z-index: 10000;
        /* Ensure it never causes horizontal overflow */
        max-width: 60px;
    }

    /* Toggle button - fixed size and position on mobile */
    #neuro-chat-toggle {
        width: 55px;
        height: 55px;
        position: relative;
        flex-shrink: 0;
        /* Prevent any transform issues */
        transform: none !important;
    }

    #neuro-chat-toggle:hover {
        transform: none !important;
    }

    #neuro-chat-toggle:active {
        transform: scale(0.95) !important;
    }

    #neuro-chat-window {
        position: fixed;
        /* Fixed to viewport, not parent */
        bottom: calc(80px + var(--safe-area-bottom, 0px));
        right: 10px;
        left: 10px;
        /* Stretch to both sides with proper margins */
        width: calc(100vw - 20px);
        /* Explicit width to prevent overflow */
        height: calc(100vh - 160px);
        /* Full height minus space for toggle and top margin */
        max-height: calc(100vh - 160px);
        max-width: calc(100vw - 20px);
        min-width: unset;
        min-height: 300px;
        resize: none;
        /* Disable resizing on mobile */
        border-radius: 15px;
        transform-origin: bottom right;
    }

    #neuro-chat-window.open {
        transform: scale(1);
    }

    .neuro-header {
        padding: 12px 15px;
    }

    .neuro-title {
        font-size: 14px;
    }

    .neuro-messages {
        padding: 12px;
        gap: 12px;
    }

    .message {
        max-width: 90%;
        padding: 10px 12px;
        font-size: 14px;
    }

    .neuro-input-area {
        padding: 12px;
        gap: 8px;
    }

    .neuro-input {
        font-size: 16px;
        /* Prevent iOS zoom on focus */
        padding: 12px 15px;
        border-radius: 25px;
    }

    .neuro-send {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }

    .limit-counter {
        top: -18px;
        right: 12px;
        font-size: 9px;
    }
}

/* Extra small screens (phones in portrait) */
@media (max-width: 400px) {
    #neuro-chat-widget {
        bottom: 10px;
        right: 10px;
    }

    #neuro-chat-toggle {
        width: 50px;
        height: 50px;
    }

    #neuro-chat-toggle i {
        font-size: 20px;
    }

    #neuro-chat-window {
        bottom: 70px;
        right: 10px;
        left: 10px;
        height: calc(100vh - 140px);
        max-height: calc(100vh - 140px);
        border-radius: 12px;
    }

    .neuro-header {
        padding: 10px 12px;
    }

    .neuro-title {
        font-size: 13px;
        gap: 8px;
    }

    .neuro-messages {
        padding: 10px;
        gap: 10px;
    }

    .message {
        max-width: 92%;
        padding: 8px 10px;
        font-size: 13px;
    }

    .neuro-input-area {
        padding: 10px;
    }

    .neuro-input {
        padding: 10px 14px;
    }

    .neuro-send {
        width: 40px;
        height: 40px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #neuro-chat-window {
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
        bottom: 70px;
    }

    .neuro-messages {
        max-height: calc(100% - 120px);
    }
}