/* AI Chatbot Styles for Castaneda Networks - Enhanced Version */

/* Chatbot Bubble */
.chatbot-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #00D9FF, #7B2CBF);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 217, 255, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
    color: #0A0E27;
}

.chatbot-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(0, 217, 255, 0.6);
}

.chatbot-bubble.hidden {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

.chatbot-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(135deg, #00D9FF, #7B2CBF);
    opacity: 0;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.5;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}


/* Unread badge */
.chatbot-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #EF4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
    animation: badgePop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes badgePop {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Chatbot Window */
.chatbot-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 100px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999;
    overflow: hidden;
}

.chatbot-window.open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

.chatbot-window.minimized {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
}

/* Chatbot Header */
.chatbot-header {
    background: linear-gradient(135deg, #00D9FF, #7B2CBF);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 16px 16px 0 0;
}

.chatbot-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.chatbot-header-info h3 {
    margin: 0;
    color: white;
    font-size: 16px;
    font-weight: 700;
}

.chatbot-status {
    margin: 4px 0 0 0;
    color: rgba(255, 255, 255, 0.9);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatbot-status.offline {
    color: rgba(255, 255, 255, 0.7);
}

.status-indicator {
    width: 8px;
    height: 8px;
    background: #10B981;
    border-radius: 50%;
    animation: blink 2s infinite;
}

.chatbot-status.offline .status-indicator {
    background: #EF4444;
    animation: none;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-header-actions {
    display: flex;
    gap: 8px;
}

.chatbot-action-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.chatbot-action-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

#chatbot-close:hover {
    transform: rotate(90deg) scale(1.1);
}

/* Welcome Message */
.chatbot-welcome {
    background: linear-gradient(135deg, rgba(0, 217, 255, 0.1), rgba(123, 44, 191, 0.1));
    border: 2px dashed rgba(0, 217, 255, 0.3);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    margin: 16px;
}

.welcome-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.chatbot-welcome h4 {
    margin: 0 0 12px 0;
    color: #0A0E27;
    font-size: 18px;
}

.chatbot-welcome p {
    margin: 0 0 16px 0;
    color: #4a5568;
    font-size: 14px;
    line-height: 1.6;
}

.welcome-note {
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 8px;
    padding: 12px;
    font-size: 13px;
    color: #92400e;
    line-height: 1.5;
}

.welcome-note strong {
    color: #78350f;
}

/* Messages Container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f7fafc;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Scroll to Bottom Button */
.scroll-to-bottom {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #00D9FF, #7B2CBF);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 217, 255, 0.4);
    transition: all 0.2s;
    z-index: 10;
}

.scroll-to-bottom:hover {
    transform: translateX(-50%) scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 217, 255, 0.6);
}

/* Message Styles */
.chatbot-message {
    display: flex;
    gap: 10px;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00D9FF, #7B2CBF);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
    align-self: flex-start;
}

.message-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 75%;
}

.message-content {
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    line-height: 1.6;
    color: #0A0E27;
    font-size: 14px;
    word-wrap: break-word;
}

.message-content p {
    margin: 0 0 10px 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

.message-content a {
    color: #00D9FF;
    text-decoration: none;
    font-weight: 600;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.message-link svg {
    opacity: 0.7;
}

.message-content strong {
    color: #7B2CBF;
    font-weight: 700;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-wrapper {
    align-items: flex-end;
}

.user-message .message-content {
    background: linear-gradient(135deg, #00D9FF, #7B2CBF);
    color: white;
    border-radius: 12px 12px 2px 12px;
}

.user-message .message-content strong {
    color: white;
    font-weight: 800;
}

.bot-message .message-content {
    border-radius: 12px 12px 12px 2px;
}

/* Message Meta (time & actions) */
.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
}

.message-time {
    font-size: 11px;
    color: #a0aec0;
}

.message-action {
    background: none;
    border: none;
    color: #a0aec0;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0;
}

.message-wrapper:hover .message-action {
    opacity: 1;
}

.message-action:hover {
    background: rgba(0, 217, 255, 0.1);
    color: #00D9FF;
}

.message-feedback.active {
    color: #10B981;
    opacity: 1;
}

/* Typing Indicator */
.typing-indicator .message-content {
    padding: 16px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #cbd5e0;
    border-radius: 50%;
    animation: typingAnimation 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingAnimation {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Rate Limit Warning */
.rate-limit-warning {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.1));
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #991b1b;
    padding: 12px 16px;
    font-size: 13px;
    text-align: center;
    font-weight: 600;
    animation: warningPulse 0.3s ease-out;
}

@keyframes warningPulse {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Suggestions */
.chatbot-suggestions {
    padding: 12px 16px 0;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggestion-chip {
    padding: 8px 14px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    font-size: 13px;
    color: #4a5568;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.suggestion-chip:hover {
    background: linear-gradient(135deg, rgba(0, 217, 255, 0.1), rgba(123, 44, 191, 0.1));
    border-color: #00D9FF;
    color: #0A0E27;
    transform: translateY(-2px);
}

/* Input Container */
.chatbot-input-container {
    background: white;
    border-top: 1px solid #e2e8f0;
}

.chatbot-input-wrapper {
    padding: 16px;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    position: relative;
}

.chatbot-input {
    flex: 1;
    padding: 12px 16px 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: all 0.2s;
    max-height: 120px;
    line-height: 1.5;
}

.chatbot-input:focus {
    border-color: #00D9FF;
    box-shadow: 0 0 0 3px rgba(0, 217, 255, 0.1);
}

.chatbot-input::placeholder {
    color: #a0aec0;
}

.char-counter {
    position: absolute;
    bottom: 22px;
    right: 82px;
    font-size: 11px;
    color: #cbd5e0;
    pointer-events: none;
    transition: color 0.2s;
}

.char-counter.char-limit-warning {
    color: #EF4444;
    font-weight: 600;
}

.chatbot-send {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #00D9FF, #7B2CBF);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    position: relative;
}

.chatbot-send:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 217, 255, 0.4);
}

.chatbot-send:active:not(:disabled) {
    transform: scale(0.95);
}

.chatbot-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.send-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Footer Actions */
.chatbot-footer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #f7fafc;
    border-top: 1px solid #e2e8f0;
}

.footer-action-btn {
    background: none;
    border: none;
    color: #718096;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.2s;
}

.footer-action-btn:hover {
    background: rgba(0, 217, 255, 0.1);
    color: #00D9FF;
}

.session-counter {
    font-size: 11px;
    color: #a0aec0;
    font-weight: 600;
}

.session-counter.limit-reached {
    color: #EF4444;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chatbot-bubble {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        /* Add safe area for notched phones */
        bottom: calc(20px + env(safe-area-inset-bottom));
        right: calc(20px + env(safe-area-inset-right));
    }

    .chatbot-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        /* Use dynamic viewport height for better keyboard handling */
        height: 100dvh;
        max-height: 100dvh;
        /* Fallback for browsers that don't support dvh */
        height: -webkit-fill-available;
        border-radius: 0;
        /* Add safe area padding */
        padding-top: env(safe-area-inset-top);
    }

    .chatbot-header {
        border-radius: 0;
        /* Account for safe area at top */
        padding-top: calc(20px + env(safe-area-inset-top));
    }

    .chatbot-messages {
        /* Better spacing for mobile */
        padding: 16px 12px;
        gap: 12px;
        /* Improve scrolling performance on mobile */
        -webkit-overflow-scrolling: touch;
    }

    .message-wrapper {
        max-width: 85%;
    }

    .message-content {
        font-size: 15px;
        /* Better tap targets */
        padding: 10px 14px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
    }

    .suggestion-chip {
        font-size: 14px;
        /* Larger tap targets */
        padding: 10px 16px;
    }

    .chatbot-input-wrapper {
        padding: 12px;
        /* Add safe area for bottom */
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .chatbot-input {
        font-size: 16px; /* Prevents auto-zoom on iOS */
        padding: 10px 14px;
    }

    .char-counter {
        bottom: calc(18px + env(safe-area-inset-bottom));
        right: 76px;
        font-size: 10px;
    }

    .chatbot-footer-actions {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
        /* Add safe area for bottom */
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .session-counter {
        text-align: center;
    }

    /* Hide minimize button on mobile (full-screen mode) */
    #chatbot-minimize {
        display: none;
    }

    /* Make close button more prominent */
    #chatbot-close {
        width: 36px;
        height: 36px;
    }

    /* Improve scroll-to-bottom button visibility */
    .scroll-to-bottom {
        bottom: calc(80px + env(safe-area-inset-bottom));
    }

    /* Adjust welcome message for mobile */
    .chatbot-welcome {
        margin: 12px;
        padding: 20px 16px;
    }

    .welcome-icon {
        font-size: 40px;
    }

    /* Better input container spacing */
    .chatbot-input-container {
        background: white;
        /* Prevent keyboard from covering input */
        position: relative;
    }
}

/* Support for older iOS browsers without dvh */
@supports not (height: 100dvh) {
    @media (max-width: 768px) {
        .chatbot-window {
            height: 100vh;
        }
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .chatbot-bubble,
    .chatbot-window,
    .chatbot-message,
    .chatbot-action-btn,
    .chatbot-send,
    .suggestion-chip,
    .scroll-to-bottom {
        animation: none;
        transition: none;
    }

    .chatbot-pulse,
    .chatbot-shimmer {
        display: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .chatbot-window {
        background: #1a202c;
    }

    .chatbot-messages {
        background: #0A0E27;
    }

    .chatbot-welcome {
        background: linear-gradient(135deg, rgba(0, 217, 255, 0.15), rgba(123, 44, 191, 0.15));
        border-color: rgba(0, 217, 255, 0.4);
    }

    .chatbot-welcome h4 {
        color: #e2e8f0;
    }

    .chatbot-welcome p {
        color: #cbd5e0;
    }

    .message-content {
        background: #2d3748;
        color: #e2e8f0;
    }

    .bot-message .message-content {
        background: #2d3748;
        color: #e2e8f0;
    }

    .chatbot-input-container {
        background: #1a202c;
        border-top-color: #2d3748;
    }

    .chatbot-input {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .chatbot-input::placeholder {
        color: #718096;
    }

    .suggestion-chip {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .chatbot-footer-actions {
        background: #1a202c;
        border-top-color: #2d3748;
    }
}
