/* ==========================================================================
   ANIME CUTE SYSTEM - DOITUONGTAC / TOP1SUB
   1. Interactive Peek-a-boo Anime Face on Auth Modals
   2. Floating Interactive Chibi Mascot Assistant (Corner Widget)
   3. Speech Bubble & Emoji Reactions
   4. Heart & Star Particles
   5. Sakura Petals Falling Canvas
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. SAKURA PETALS CANVAS
   -------------------------------------------------------------------------- */
#sakura-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
    opacity: 0.9;
    transition: opacity 0.5s ease;
}

#sakura-canvas.sakura-disabled {
    opacity: 0;
    visibility: hidden;
}

/* --------------------------------------------------------------------------
   2. FLOATING CHIBI MASCOT ASSISTANT (BOTTOM CORNER)
   -------------------------------------------------------------------------- */
.anime-chibi-container {
    position: fixed;
    bottom: 92px; /* Mặc định đặt cao hơn nút Chat để không che mất icon Chat CSKH */
    right: 25px;
    z-index: 99990;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    user-select: none;
    pointer-events: auto;
    font-family: 'Google Sans Text', sans-serif;
    transition: bottom 0.3s ease, left 0.3s ease, right 0.3s ease;
}

/* Các biến thể vị trí tùy chỉnh từ Admin */
.anime-chibi-container.pos-bottom-right-above {
    bottom: 92px;
    right: 25px;
    left: auto;
    align-items: flex-end;
}

.anime-chibi-container.pos-bottom-left {
    bottom: 25px;
    left: 25px;
    right: auto;
    align-items: flex-start;
}

.anime-chibi-container.pos-bottom-left .chibi-speech-bubble::after {
    left: 35px;
    right: auto;
    border-right: none;
    border-bottom: 2px solid #38bdf8;
    border-left: 2px solid #38bdf8;
}

.anime-chibi-container.pos-bottom-right {
    bottom: 25px;
    right: 25px;
    left: auto;
    align-items: flex-end;
}

.anime-chibi-container.chibi-disabled {
    display: none !important;
}

/* Mascot Speech Bubble */
.chibi-speech-bubble {
    position: relative;
    background: #ffffff;
    border: 2px solid #38bdf8;
    border-radius: 18px;
    padding: 10px 16px;
    margin-bottom: 12px;
    max-width: 250px;
    box-shadow: 0 10px 25px -5px rgba(14, 165, 233, 0.3), 0 4px 12px rgba(0, 0, 0, 0.08);
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: auto;
    cursor: pointer;
}

.chibi-speech-bubble.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.chibi-speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -9px;
    right: 35px;
    width: 15px;
    height: 15px;
    background: #ffffff;
    border-right: 2px solid #38bdf8;
    border-bottom: 2px solid #38bdf8;
    transform: rotate(45deg);
}

.chibi-bubble-text {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.45;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chibi-bubble-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed #e2e8f0;
    font-size: 11px;
}

.chibi-btn-toggle {
    background: #f0f9ff;
    color: #0284c7;
    border: 1px solid #bae6fd;
    border-radius: 12px;
    padding: 2px 8px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.2s ease;
}

.chibi-btn-toggle:hover {
    background: #0284c7;
    color: #ffffff;
}

.chibi-btn-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 13px;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s ease;
}

.chibi-btn-close:hover {
    color: #ef4444;
}

/* Mascot Wrapper & Avatar */
.chibi-avatar-wrap {
    position: relative;
    cursor: pointer;
    filter: drop-shadow(0 8px 20px rgba(14, 165, 233, 0.35));
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chibi-avatar-wrap:hover {
    transform: scale(1.08) translateY(-4px);
}

.chibi-avatar-wrap:active {
    transform: scale(0.96);
}

.chibi-avatar-img {
    height: 125px;
    width: auto;
    object-fit: contain;
    animation: chibiFloating 3.6s ease-in-out infinite alternate;
    pointer-events: auto;
}

@keyframes chibiFloating {
    0% {
        transform: translateY(0px) rotate(0deg);
    }
    50% {
        transform: translateY(-8px) rotate(2deg);
    }
    100% {
        transform: translateY(3px) rotate(-1.5deg);
    }
}

/* Ambient Aura Glow under Mascot */
.chibi-aura-glow {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    height: 18px;
    background: radial-gradient(ellipse, rgba(56, 189, 248, 0.5) 0%, rgba(37, 99, 235, 0.2) 50%, transparent 70%);
    border-radius: 50%;
    animation: chibiShadow 3.6s ease-in-out infinite alternate;
    z-index: -1;
}

@keyframes chibiShadow {
    0% {
        transform: translateX(-50%) scale(1);
        opacity: 0.7;
    }
    50% {
        transform: translateX(-50%) scale(0.8);
        opacity: 0.35;
    }
    100% {
        transform: translateX(-50%) scale(1.1);
        opacity: 0.85;
    }
}

/* Minimized Badge Mode */
.chibi-minimized-badge {
    display: none;
    background: linear-gradient(135deg, #38bdf8 0%, #2563eb 100%);
    color: #ffffff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: pulseBadge 2.5s infinite;
}

.chibi-minimized-badge:hover {
    transform: scale(1.12);
}

@keyframes pulseBadge {
    0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
    100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

/* Trạng thái Tắt câu nói - Chỉ ẩn bong bóng câu nói, Bé Chibi luôn hiển thị */
.anime-chibi-container.bubble-muted .chibi-speech-bubble {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Ẩn triệt để huy hiệu con mèo theo yêu cầu */
.chibi-minimized-badge {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Floating Heart Burst Effect */
.chibi-heart-particle {
    position: fixed;
    pointer-events: none;
    z-index: 99995;
    font-size: 22px;
    animation: floatHeart 1.4s ease-out forwards;
}

@keyframes floatHeart {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(0.6) rotate(0deg);
    }
    50% {
        transform: translate(var(--dx), -45px) scale(1.3) rotate(var(--rot));
    }
    100% {
        opacity: 0;
        transform: translate(var(--dx), -90px) scale(0.9) rotate(var(--rot));
    }
}
/* --------------------------------------------------------------------------
   CHIBI MASCOT AI CHATBOX WIDGET (UNIFIED CHIBI AI COPILOT)
   -------------------------------------------------------------------------- */
.chibi-btn-chat {
    background: linear-gradient(135deg, #ec4899, #8b5cf6) !important;
    color: #ffffff !important;
    border: none !important;
    box-shadow: 0 3px 10px rgba(236, 72, 153, 0.4);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 700 !important;
}

.chibi-btn-chat:hover {
    transform: translateY(-1px) scale(1.05);
    box-shadow: 0 5px 14px rgba(236, 72, 153, 0.6);
}

.chibi-chatbox {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 385px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 80px);
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18), 0 8px 24px rgba(236, 72, 153, 0.22);
    z-index: 100000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 2px solid rgba(244, 114, 182, 0.45);
    animation: chibiSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: 'Google Sans Text', sans-serif;
}

@keyframes chibiSlideIn {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.94);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chibi-chat-header {
    background: linear-gradient(135deg, #ec4899 0%, #a855f7 50%, #6366f1 100%);
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 15px rgba(236, 72, 153, 0.25);
    position: relative;
    user-select: none;
}

.chibi-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chibi-chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #ffffff;
    padding: 2px;
    object-fit: contain;
    border: 2px solid #fbcfe8;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    animation: chibiHeaderBounce 3s ease-in-out infinite alternate;
}

@keyframes chibiHeaderBounce {
    0% { transform: translateY(0) rotate(0deg); }
    100% { transform: translateY(-3px) rotate(3deg); }
}

.chibi-chat-header-title {
    font-size: 14.5px;
    font-weight: 700;
    margin: 0;
    line-height: 1.25;
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.chibi-chat-header-status {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.chibi-status-dot {
    width: 7px;
    height: 7px;
    background-color: #34d399;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7);
    animation: chibiPulse 2s infinite;
}

@keyframes chibiPulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.chibi-chat-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
}

.chibi-chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: rotate(90deg);
}

.chibi-chat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #fff5f7;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: #fbcfe8 transparent;
}

.chibi-chat-body::-webkit-scrollbar {
    width: 5px;
}
.chibi-chat-body::-webkit-scrollbar-thumb {
    background: #fbcfe8;
    border-radius: 10px;
}

.chibi-msg {
    max-width: 86%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

.chibi-msg-assistant {
    align-self: flex-start;
    background: #ffffff;
    color: #1e293b;
    border: 1.5px solid #fed7e2;
    border-top-left-radius: 4px;
    box-shadow: 0 4px 15px rgba(244, 114, 182, 0.1);
}

.chibi-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #ec4899, #d946ef);
    color: #ffffff;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(236, 72, 153, 0.3);
}

.chibi-chat-chips {
    padding: 8px 14px;
    background: #ffffff;
    border-top: 1px solid #fce7f3;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
}
.chibi-chat-chips::-webkit-scrollbar {
    display: none;
}

.chibi-chip-btn {
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 11px;
    border-radius: 20px;
    background: #fdf2f8;
    color: #be185d;
    border: 1px solid #fbcfe8;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    user-select: none;
}

.chibi-chip-btn:hover {
    background: #f472b6;
    color: #ffffff;
    border-color: #ec4899;
    transform: translateY(-1px);
}

.chibi-chat-footer {
    padding: 10px 14px;
    background: #ffffff;
    border-top: 1px solid #f1f5f9;
}

.chibi-chat-input-wrap {
    display: flex;
    align-items: center;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 30px;
    padding: 3px 5px 3px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chibi-chat-input-wrap:focus-within {
    border-color: #ec4899;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.15);
}

.chibi-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13px;
    color: #1e293b;
    outline: none;
}

.chibi-chat-send-btn {
    background: linear-gradient(135deg, #ec4899, #8b5cf6);
    color: #ffffff;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s;
}

.chibi-chat-send-btn:hover:not(:disabled) {
    transform: scale(1.08);
}

.chibi-chat-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 576px) {
    .chibi-chatbox {
        bottom: 12px;
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        height: 80vh;
        border-radius: 20px;
    }
}

/* --------------------------------------------------------------------------
   3. INTERACTIVE PEEK-A-BOO ANIME IN AUTH MODAL
   -------------------------------------------------------------------------- */
.auth-anime-peekaboo-box {
    position: relative;
    width: 100%;
    height: 65px;
    margin-top: 2px;
    margin-bottom: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
    user-select: none;
}

.anime-peekaboo-char {
    position: relative;
    width: 100px;
    height: 65px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* SVG Face Container */
.anime-face-svg {
    width: 85px;
    height: 65px;
    transition: transform 0.3s ease;
}

/* Eyes Tracking & Blinking */
.anime-eye-left,
.anime-eye-right {
    transform-origin: center;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: animeBlink 4.5s infinite;
}

@keyframes animeBlink {
    0%, 94%, 98%, 100% {
        transform: scaleY(1);
    }
    96% {
        transform: scaleY(0.08);
    }
}

/* Looking down when focused on username input */
.auth-anime-peekaboo-box.looking-down .anime-eye-left,
.auth-anime-peekaboo-box.looking-down .anime-eye-right {
    transform: translateY(2.5px) scaleY(0.9);
}

/* Hands/Paws covering eyes on password */
.anime-paw-left,
.anime-paw-right {
    position: absolute;
    bottom: 8px;
    width: 28px;
    height: 28px;
    background: #ffffff;
    border: 2.2px solid #0284c7;
    border-radius: 50% 50% 45% 45%;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transform: translateY(30px) scale(0.6);
}

.anime-paw-left {
    left: 18px;
}

.anime-paw-right {
    right: 18px;
}

/* Pink Paw Pads */
.anime-paw-left::after,
.anime-paw-right::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 13px;
    height: 9px;
    background: #f472b6;
    border-radius: 50%;
    opacity: 0.9;
}

/* Cover Eyes State (Password Focus) */
.auth-anime-peekaboo-box.covering-eyes .anime-paw-left {
    opacity: 1;
    transform: translateY(-24px) scale(1.15) rotate(-12deg);
}

.auth-anime-peekaboo-box.covering-eyes .anime-paw-right {
    opacity: 1;
    transform: translateY(-24px) scale(1.15) rotate(12deg);
}

/* Blushing cheeks glow brighter when covering eyes */
.anime-blush-left,
.anime-blush-right {
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 0.5;
}

.auth-anime-peekaboo-box.covering-eyes .anime-blush-left,
.auth-anime-peekaboo-box.covering-eyes .anime-blush-right {
    opacity: 1;
    transform: scale(1.35);
}

/* Mobile Responsiveness for Mascot */
@media (max-width: 991px) {
    /* Vị trí chuẩn: Nằm phía trên nút Chat CSKH (nút Chat ở bottom: 70px, bé Chibi ở bottom: 126px) */
    .anime-chibi-container,
    .anime-chibi-container.pos-bottom-right-above,
    .anime-chibi-container.pos-bottom-right {
        bottom: 126px !important;
        right: 12px !important;
        left: auto !important;
        z-index: 99995 !important;
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        align-items: flex-end !important;
    }

    /* Tùy chọn vị trí góc dưới bên trái: hoàn toàn tách biệt với nút Chat ở bên phải */
    .anime-chibi-container.pos-bottom-left {
        bottom: 72px !important;
        left: 12px !important;
        right: auto !important;
        z-index: 99995 !important;
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        align-items: flex-start !important;
    }

    .anime-chibi-container.pos-bottom-left .chibi-speech-bubble::after {
        left: 35px !important;
        right: auto !important;
        border-right: none !important;
        border-bottom: 2px solid #38bdf8 !important;
        border-left: 2px solid #38bdf8 !important;
    }

    .anime-chibi-container:not(.minimized) .chibi-avatar-wrap {
        display: block !important;
        visibility: visible !important;
    }
    .anime-chibi-container:not(.minimized) .chibi-avatar-img {
        height: 68px !important;
        width: auto !important;
        display: block !important;
        visibility: visible !important;
    }

    /* Đảm bảo khi Minimized trên mobile thì ẩn sạch avatar bé Chibi và bong bóng */
    .anime-chibi-container.minimized .chibi-avatar-wrap,
    .anime-chibi-container.minimized .chibi-avatar-img,
    .anime-chibi-container.minimized .chibi-speech-bubble,
    .anime-chibi-container.minimized .chibi-aura-glow {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        height: 0 !important;
        width: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .anime-chibi-container.minimized .chibi-minimized-badge {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    .anime-chibi-container:not(.minimized) .chibi-minimized-badge {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    .chibi-speech-bubble {
        max-width: 220px !important;
        padding: 8px 12px !important;
        border-radius: 14px !important;
        margin-bottom: 8px !important;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15) !important;
    }
    .chibi-bubble-text {
        font-size: 12px !important;
        line-height: 1.4 !important;
    }
    .chibi-bubble-actions {
        margin-top: 6px !important;
        gap: 6px !important;
    }
    .chibi-btn-toggle,
    .chibi-btn-close {
        font-size: 10px !important;
        padding: 3px 8px !important;
    }
}
