/**
 * Comic Bubble & Chat Window Styles
 * Speech bubble and conversation interface for VoiceAgent
 * 
 * @author lycosa9527
 * @made_by MindSpring Team
 */

/* ============================================================================
   Black Cat Container - Sits above status bar
   ============================================================================ */
.black-cat-container {
    position: fixed;
    bottom: 85px; /* Above status bar */
    left: 20px;
    width: 100px;
    height: 100px;
    cursor: pointer;
    z-index: 9999;
    transition: transform 0.3s ease, filter 0.3s ease;
    filter: drop-shadow(2px 4px 8px rgba(0, 0, 0, 0.3));
    user-select: none;
}

.black-cat-container .kitty-svg {
    width: 100%;
    height: auto;
    display: block;
    pointer-events: none; /* Let container handle all clicks */
}

.black-cat-container:hover {
    transform: translateY(-5px) scale(1.05);
    filter: drop-shadow(2px 8px 16px rgba(102, 126, 234, 0.5));
}

.black-cat-container:active {
    transform: translateY(-2px) scale(0.98);
}

/* Prevent SVG element selection - container handles everything */
.black-cat-container,
.black-cat-container * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.black-cat-container svg,
.black-cat-container svg * {
    pointer-events: none; /* Disable all SVG element interactions */
}

/* ============================================================================
   Chat Window - Main Container
   ============================================================================ */
.chat-window {
    position: fixed;
    bottom: 195px; /* Above kitty (85px + 100px + 10px gap) */
    left: 20px;
    width: 280px; /* Narrower for better left-right alignment */
    max-height: 380px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 10002; /* Higher than node palette (10001) to ensure it's on top */
    display: flex;
    flex-direction: column;
    
    /* Hidden by default */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-window.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ============================================================================
   Chat Header - Hidden to save space
   ============================================================================ */
.chat-header {
    display: none; /* Hidden - user can click kitty to close */
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #2c3e50;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #27ae60;
    box-shadow: 0 0 6px rgba(39, 174, 96, 0.5);
}

.status-dot.thinking {
    background: #f39c12;
    animation: pulse-dot 1.2s ease-in-out infinite;
}

.status-dot.error {
    background: #e74c3c;
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-header-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #7f8c8d;
    transition: all 0.2s;
}

.chat-header-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #2c3e50;
}

.chat-header-btn svg {
    width: 16px;
    height: 16px;
}

/* ============================================================================
   Chat Messages Container
   ============================================================================ */
.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 10px; /* Reduced horizontal padding for narrower modal */
    display: flex;
    flex-direction: column;
    gap: 10px; /* Slightly increased gap for better separation */
    min-height: 80px;
    max-height: 220px;
    align-items: stretch; /* Ensure full width for alignment */
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}

/* ============================================================================
   Chat Message Bubbles
   ============================================================================ */
.chat-message {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    animation: message-in 0.25s ease-out;
    display: flex;
    flex-direction: column;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Agent messages - left aligned */
.chat-message.agent {
    align-self: flex-start;
    background: #f1f3f4;
    color: #2c3e50;
    border-radius: 12px;
    border-bottom-left-radius: 4px; /* Slight tail effect for left-aligned */
    margin-left: 0;
    margin-right: auto;
}

/* User messages - right aligned */
.chat-message.user {
    align-self: flex-end;
    background: #3498db;
    color: white;
    border-radius: 12px;
    border-bottom-right-radius: 4px; /* Slight tail effect for right-aligned */
    margin-left: auto;
    margin-right: 0;
}

.message-content {
    display: block;
}

.chat-message-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
    display: none; /* Hidden by default for minimal look */
}

/* ============================================================================
   Thinking Animation
   ============================================================================ */
.chat-message.thinking {
    background: #f1f3f4;
    padding: 12px 16px;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: #7f8c8d;
    border-radius: 50%;
    animation: thinking-bounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ============================================================================
   Chat Input Area
   ============================================================================ */
.chat-input-container {
    padding: 10px 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: #f8f9fa;
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: center; /* Center items vertically */
    gap: 6px;
    background: white;
    border-radius: 12px;
    padding: 6px 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
    border-color: #3498db;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13px;
    line-height: 1.4;
    resize: none;
    max-height: 80px;
    outline: none;
    font-family: inherit;
    pointer-events: auto; /* Ensure input is clickable */
    vertical-align: middle; /* Center text vertically */
    padding: 0; /* Remove default padding that might offset text */
}

.chat-input::placeholder {
    color: #95a5a6;
}

.chat-voice-btn,
.chat-send-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #7f8c8d;
    transition: all 0.2s;
    flex-shrink: 0;
    pointer-events: auto; /* Ensure buttons are clickable */
    -webkit-user-select: none;
    user-select: none;
}

.chat-voice-btn:hover,
.chat-send-btn:hover {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.chat-voice-btn.active {
    background: #e74c3c;
    color: white;
    animation: pulse-voice 1.5s ease-in-out infinite;
}

@keyframes pulse-voice {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(231, 76, 60, 0); }
}

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

.chat-voice-btn svg,
.chat-send-btn svg {
    width: 16px;
    height: 16px;
}

.comic-bubble {
    position: fixed;
    bottom: 195px; /* Above kitty (85px + 100px + 10px gap) */
    left: 20px;    /* Align with kitty left edge */
    max-width: 380px;
    min-width: 160px;
    
    /* Comic-style gradient background */
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border: 4px solid #2c3e50;
    border-radius: 24px;
    padding: 20px 24px;
    
    /* Enhanced shadow for depth */
    box-shadow: 
        0 8px 24px rgba(44, 62, 80, 0.15),
        0 2px 8px rgba(44, 62, 80, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    
    z-index: 10000;
    
    /* Animation */
    opacity: 0;
    transform: scale(0.85) translateY(-5px);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.comic-bubble.visible {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* Speech bubble tail pointing down to black cat */
.comic-bubble::after {
    content: '';
    position: absolute;
    bottom: -24px;
    left: 40px;
    width: 0;
    height: 0;
    border-left: 18px solid transparent;
    border-right: 18px solid transparent;
    border-top: 24px solid #f8f9fa;
    filter: drop-shadow(0 3px 4px rgba(44, 62, 80, 0.12));
}

/* Dark border for tail */
.comic-bubble::before {
    content: '';
    position: absolute;
    bottom: -29px;
    left: 36px;
    width: 0;
    height: 0;
    border-left: 22px solid transparent;
    border-right: 22px solid transparent;
    border-top: 29px solid #2c3e50;
}

.comic-bubble-text {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #2c3e50;
    font-weight: 500;
    word-wrap: break-word;
    white-space: pre-wrap;
    letter-spacing: 0.2px;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

/* Expand button on bubble */
.comic-bubble-expand {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #7f8c8d;
    transition: all 0.2s;
    opacity: 0;
}

.comic-bubble:hover .comic-bubble-expand {
    opacity: 1;
}

.comic-bubble-expand:hover {
    background: rgba(0, 0, 0, 0.15);
    color: #2c3e50;
}

.comic-bubble-expand svg {
    width: 14px;
    height: 14px;
}

/* Thinking animation (dots) */
.comic-bubble.thinking .comic-bubble-text {
    font-size: 24px;
    text-align: center;
    letter-spacing: 4px;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .black-cat-container {
        width: 80px;
        height: 80px;
        bottom: 90px; /* Above mobile status bar */
        left: 15px;
    }
    
    .chat-window {
        bottom: 180px; /* Above kitty (90px + 80px + 10px gap) */
        left: 10px;
        right: 10px;
        width: auto;
        max-height: 280px;
    }
    
    .comic-bubble {
        bottom: 180px; /* Above kitty */
        left: 15px;
        max-width: 260px;
        padding: 12px 16px;
        font-size: 13px;
    }
    
    .comic-bubble::after {
        left: 30px;
    }
    
    .comic-bubble::before {
        left: 27px;
    }
}

/* Accessibility: High contrast mode */
@media (prefers-contrast: high) {
    .comic-bubble {
        border-width: 4px;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    }
}

/* Animation for typing effect */
@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.comic-bubble.typing .comic-bubble-text::after {
    content: '▌';
    animation: blink-cursor 0.8s infinite;
    margin-left: 2px;
}

/* Fade in words animation */
@keyframes fade-in-word {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.comic-bubble-text .word {
    display: inline-block;
    animation: fade-in-word 0.3s ease;
}


