/* Chatbot with R Character Animation */
:root {
    --sprite-width: 64px;
    --sprite-height: 64px;
    --sprite-scale: 1.5;
    --primary-color: #00A878;
    --primary-dark: #008F6A;
    --primary-light: #2CC896;
    --secondary-color: #9D4EDD;
    --text-primary: #333333;
    --text-secondary: #666666;
    --bg-light: #F4F7F6;
    --bg-message: #EFF1F3;
    --border-color: #EEEEEE;
}

/* Chatbot Container */
.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* R Character Button */
.chatbot-button {
    width: calc(var(--sprite-width) * var(--sprite-scale));
    height: calc(var(--sprite-height) * var(--sprite-scale));
    border: none;
    cursor: pointer;
    background: transparent;
    padding: 0;
    position: relative;
    transition: all 0.3s ease;
}

.chatbot-button:hover {
    transform: scale(1.08);
    filter: drop-shadow(0 4px 20px rgba(0, 200, 150, 0.4));
}

.chatbot-button.active {
    transform: scale(1.02);
}

/* R Character Sprite */
.r-character-sprite {
    width: calc(var(--sprite-width) * var(--sprite-scale));
    height: calc(var(--sprite-height) * var(--sprite-scale));
    background-image: url('/images/r-sprite.png');
    background-size: calc(var(--sprite-width) * 3 * var(--sprite-scale)) calc(var(--sprite-height) * 3 * var(--sprite-scale));
    background-repeat: no-repeat;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    -ms-interpolation-mode: nearest-neighbor;
    position: relative;
    filter: contrast(1.1) brightness(1.05);
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Character States - Run through all 9 poses */
.r-character-sprite.idle {
    animation: sprite-all-9 27s steps(1) infinite;
}

@keyframes sprite-all-9 {
    0% { background-position: 0 0; }
    11.11% { background-position: calc(-1 * var(--sprite-width) * var(--sprite-scale)) 0; }
    22.22% { background-position: calc(-2 * var(--sprite-width) * var(--sprite-scale)) 0; }
    33.33% { background-position: 0 calc(-1 * var(--sprite-height) * var(--sprite-scale)); }
    44.44% { background-position: calc(-1 * var(--sprite-width) * var(--sprite-scale)) calc(-1 * var(--sprite-height) * var(--sprite-scale)); }
    55.55% { background-position: calc(-2 * var(--sprite-width) * var(--sprite-scale)) calc(-1 * var(--sprite-height) * var(--sprite-scale)); }
    66.66% { background-position: 0 calc(-2 * var(--sprite-height) * var(--sprite-scale)); }
    77.77% { background-position: calc(-1 * var(--sprite-width) * var(--sprite-scale)) calc(-2 * var(--sprite-height) * var(--sprite-scale)); }
    88.88% { background-position: calc(-2 * var(--sprite-width) * var(--sprite-scale)) calc(-2 * var(--sprite-height) * var(--sprite-scale)); }
    100% { background-position: calc(-2 * var(--sprite-width) * var(--sprite-scale)) calc(-2 * var(--sprite-height) * var(--sprite-scale)); }
}

.r-character-sprite.talking {
    animation: sprite-all-9 27s steps(1) infinite;
}

.r-character-sprite.happy {
    animation: sprite-all-9 27s steps(1) infinite;
}

.r-character-sprite.excited {
    animation: sprite-all-9 27s steps(1) infinite;
}

.r-character-sprite.thinking {
    animation: sprite-all-9 27s steps(1) infinite;
}

.r-character-sprite.waving {
    animation: sprite-all-9 15s steps(1) 1;
}

.r-character-sprite.confused {
    animation: sprite-all-9 27s steps(1) infinite;
}

.r-character-sprite.sad {
    animation: sprite-all-9 27s steps(1) infinite;
}

.r-character-sprite.running {
    animation: sprite-all-9 27s steps(1) infinite;
}

.r-character-sprite.jumping {
    animation: sprite-all-9 18s steps(1) 1;
}

/* Notification Badge */
.chatbot-notification {
    display: none;
}

@keyframes pulse-notification {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Speech Bubble */
.speech-bubble {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    background: var(--primary-color);
    color: white;
    padding: 12px 18px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 200, 150, 0.3);
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--primary-color);
}

.chatbot-button:hover .speech-bubble {
    opacity: 1;
    transform: translateY(0);
}

/* Chatbot Window */
.chatbot-window {
    position: absolute;
    bottom: calc(100% + 20px);
    right: 0;
    width: 380px;
    height: 450px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUpFade 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: none;
}

.chatbot-window.active {
    display: flex;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.chatbot-header {
    background: #FFFFFF;
    color: var(--text-primary);
    padding: 2px;
    display: flex;
    align-items: center;
    gap: 1px;
    position: relative;
    border-bottom: 1px solid #E8E8E8;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chatbot-header::before {
    display: none;
}

.chatbot-avatar {
    display: none;
}

@keyframes avatar-all-9 {
    0% { background-position: 0 0; }
    11.11% { background-position: calc(-1 * var(--sprite-width) * 0.8) 0; }
    22.22% { background-position: calc(-2 * var(--sprite-width) * 0.8) 0; }
    33.33% { background-position: 0 calc(-1 * var(--sprite-height) * 0.8); }
    44.44% { background-position: calc(-1 * var(--sprite-width) * 0.8) calc(-1 * var(--sprite-height) * 0.8); }
    55.55% { background-position: calc(-2 * var(--sprite-width) * 0.8) calc(-1 * var(--sprite-height) * 0.8); }
    66.66% { background-position: 0 calc(-2 * var(--sprite-height) * 0.8); }
    77.77% { background-position: calc(-1 * var(--sprite-width) * 0.8) calc(-2 * var(--sprite-height) * 0.8); }
    88.88% { background-position: calc(-2 * var(--sprite-width) * 0.8) calc(-2 * var(--sprite-height) * 0.8); }
    100% { background-position: calc(-2 * var(--sprite-width) * 0.8) calc(-2 * var(--sprite-height) * 0.8); }
}

.chatbot-avatar.talking {
    background-position: center center;
}

.chatbot-avatar.happy {
    background-position: center center;
}

.chatbot-info {
    flex: 1;
    position: relative;
    z-index: 1;
    text-align: center;
}

.chatbot-info h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0;
    text-shadow: none;
}

.chatbot-info p {
    margin: 4px 0 0 0;
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.status-dot {
    width: 9px;
    height: 9px;
    background: var(--primary-color);
    border-radius: 50%;
    display: inline-block;
    animation: blink-dot 2.5s infinite;
    box-shadow: 0 0 0 2px rgba(0, 168, 120, 0.25);
}

@keyframes blink-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.close-btn {
    position: relative;
    z-index: 1;
    width: 20px;
    height: 4px;
    background: #CCCCCC;
    backdrop-filter: none;
    border: none;
    border-radius: 2px;
    color: var(--text-primary);
    font-size: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.close-btn:hover {
    background: #999999;
    transform: none;
}

/* Messages Area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #ffffff;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.chatbot-messages::-webkit-scrollbar {
    width: 5px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
    margin: 8px 0;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #CBD5E0;
    border-radius: 10px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #A0AEC0;
}

/* Message */
.message {
    display: flex;
    margin-bottom: 18px;
    animation: messageSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot {
    justify-content: flex-start;
}

.message.user {
    justify-content: flex-end;
}

.message-avatar {
    display: none;
}

@keyframes mini-avatar-all-9 {
    0% { background-position: 0 0; }
    11.11% { background-position: calc(-1 * var(--sprite-width) * 0.5) 0; }
    22.22% { background-position: calc(-2 * var(--sprite-width) * 0.5) 0; }
    33.33% { background-position: 0 calc(-1 * var(--sprite-height) * 0.5); }
    44.44% { background-position: calc(-1 * var(--sprite-width) * 0.5) calc(-1 * var(--sprite-height) * 0.5); }
    55.55% { background-position: calc(-2 * var(--sprite-width) * 0.5) calc(-1 * var(--sprite-height) * 0.5); }
    66.66% { background-position: 0 calc(-2 * var(--sprite-height) * 0.5); }
    77.77% { background-position: calc(-1 * var(--sprite-width) * 0.5) calc(-2 * var(--sprite-height) * 0.5); }
    88.88% { background-position: calc(-2 * var(--sprite-width) * 0.5) calc(-2 * var(--sprite-height) * 0.5); }
    100% { background-position: calc(-2 * var(--sprite-width) * 0.5) calc(-2 * var(--sprite-height) * 0.5); }
}

.message-avatar.talking {
    background-position: center center;
}

.message-content {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    position: relative;
}

.message.bot .message-content {
    background: #FFFFFF;
    color: var(--text-primary);
    border-top-left-radius: 4px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    border: 1px solid #E8E8E8;
    position: relative;
}

.message.user .message-content {
    background: #FFFFFF;
    color: var(--text-primary);
    border-top-right-radius: 4px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    border: 1px solid #E8E8E8;
    position: relative;
}

.message-time {
    font-size: 11px;
    color: #999999;
    margin-top: 5px;
    text-align: center;
    display: block;
    width: 100%;
    opacity: 1;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: #FFFFFF;
    border-radius: 12px;
    border-top-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    border: 1px solid #E8E8E8;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999999;
    border-radius: 50%;
    margin: 0 2px;
    animation: typing-bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Quick Replies */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    animation: fadeInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.quick-reply-btn {
    background: #ffffff;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 10px 22px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 600;
    box-shadow: none;
    text-transform: uppercase;
}

.quick-reply-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: none;
    box-shadow: none;
}

/* Input Area */
.chatbot-input-area {
    padding: 15px 20px;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 15px;
    align-items: center;
    box-shadow: none;
    border-radius: 0;
}

.chatbot-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: transparent;
    color: var(--text-primary);
    padding: 0;
}

.chatbot-input::placeholder {
    color: #AAAAAA;
    opacity: 1;
}

.chatbot-input:focus {
    border: none;
    background: transparent;
    box-shadow: none;
}

.chatbot-send-btn {
    width: auto;
    height: auto;
    background: transparent;
    color: #AAAAAA;
    border: none;
    border-radius: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    box-shadow: none;
    padding: 0;
    position: relative;
}

.chatbot-send-btn:hover {
    background: transparent;
    color: var(--primary-color);
    transform: none;
    box-shadow: none;
}

.chatbot-send-btn:active {
    transform: none;
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Welcome Screen */
.welcome-screen {
    text-align: center;
    padding: 50px 24px;
    animation: fadeIn 0.6s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.welcome-character {
    width: calc(var(--sprite-width) * 2);
    height: calc(var(--sprite-height) * 2);
    background-image: url('/images/r-sprite.png');
    background-size: calc(var(--sprite-width) * 10 * 2) calc(var(--sprite-height) * 10 * 2);
    background-repeat: no-repeat;
    image-rendering: pixelated;
    margin: 0 auto 20px;
    animation: welcome-character-anim 1s steps(10) infinite;
}

@keyframes welcome-character-anim {
    0% { background-position: 0 calc(-8 * var(--sprite-height) * 2); }
    100% { background-position: calc(-1 * var(--sprite-width) * 10 * 2) calc(-8 * var(--sprite-height) * 2); }
}

.welcome-screen h4 {
    margin: 0 0 12px 0;
    color: var(--primary-dark);
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.welcome-screen p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.7;
}

/* Responsive */
@media (max-width: 768px) {
    .chatbot-container {
        bottom: 15px;
        right: 15px;
    }

    .chatbot-window {
        width: calc(100vw - 30px);
        height: calc(100vh - 140px);
        max-height: 620px;
        border-radius: 16px;
    }

    .chatbot-button {
        --sprite-scale: 1.3;
    }

    .chatbot-header {
        padding: 20px;
        border-radius: 16px 16px 0 0;
    }

    .chatbot-messages {
        padding: 18px;
    }

    .message-content {
        max-width: 82%;
        font-size: 14px;
    }

    .chatbot-input-area {
        padding: 16px 18px;
        border-radius: 0 0 16px 16px;
    }

    .chatbot-input {
        padding: 13px 18px;
        font-size: 14px;
    }

    .chatbot-send-btn {
        width: 46px;
        height: 46px;
        font-size: 20px;
    }
}
