/**
 * ============================================
 * Next Tab AI 챗봇 위젯 스타일
 * ============================================
 * 글래스모피즘 + 다크 테마 + 애니메이션
 * ============================================
 */

/* ==================== 챗봇 토글 버튼 ==================== */
.chatbot-toggle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    /* 우측 하단 모서리에 배치 */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient-primary);
    /* Use gradient variable */
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(var(--color-primary-rgb), 0.4), 0 0 0 0 rgba(var(--color-primary-rgb), 0.4);
    /* Approximate shadow */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse-ring 2s ease-out infinite;
    color: var(--color-text-dark);
    /* Ensure icon is visible against primary */
}

/* 모바일에서 드래그 중일 때는 애니메이션 중지 */
.chatbot-toggle.dragging {
    animation: none;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(var(--color-primary-rgb), 0.5), 0 0 20px rgba(var(--color-primary-rgb), 0.3);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

.chatbot-toggle .icon {
    font-size: 1.75rem;
    transition: transform 0.3s ease;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.chatbot-toggle.open .icon {
    transform: rotate(90deg);
}

@keyframes pulse-ring {
    0% {
        box-shadow: 0 8px 32px rgba(var(--color-primary-rgb), 0.4), 0 0 0 0 rgba(var(--color-primary-rgb), 0.4);
    }

    70% {
        box-shadow: 0 8px 32px rgba(var(--color-primary-rgb), 0.4), 0 0 0 15px rgba(var(--color-primary-rgb), 0);
    }

    100% {
        box-shadow: 0 8px 32px rgba(var(--color-primary-rgb), 0.4), 0 0 0 0 rgba(var(--color-primary-rgb), 0);
    }
}

/* ==================== 챗봇 컨테이너 ==================== */
.chatbot-container {
    position: fixed;
    bottom: 6.5rem;
    right: 2rem;
    width: 380px;
    height: 550px;
    background: var(--color-bg-card-hover);
    /* Use theme card bg */
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-container.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ==================== 헤더 ==================== */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    color: var(--color-text-dark);
}

.chatbot-title {
    display: flex;
    flex-direction: column;
}

.chatbot-title h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-white);
    margin: 0;
}

.chatbot-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--color-text-gray);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-primary);
    animation: blink 2s ease-in-out infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

.chatbot-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--color-text-gray);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chatbot-close:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

/* ==================== 메시지 영역 ==================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--color-primary) transparent;
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

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

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

/* 메시지 버블 */
.message {
    display: flex;
    gap: 0.625rem;
    max-width: 85%;
    animation: messageSlide 0.3s ease-out;
}

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

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

.message.bot {
    align-self: flex-start;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
}

.message.bot .message-avatar {
    background: var(--gradient-primary);
    color: var(--color-text-dark);
}

.message.user .message-avatar {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.message-content {
    padding: 0.875rem 1rem;
    border-radius: 1rem;
    line-height: 1.5;
    font-size: 0.9rem;
}

.message.bot .message-content {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--color-text-white);
    border-top-left-radius: 0.25rem;
}

.message.user .message-content {
    background: var(--gradient-primary);
    color: var(--color-text-dark);
    border-top-right-radius: 0.25rem;
    font-weight: 500;
}

/* 타이핑 인디케이터 */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.875rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    border-top-left-radius: 0.25rem;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* 빠른 응답 버튼 */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.quick-reply-btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--color-primary);
    border-radius: 2rem;
    color: var(--color-primary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-reply-btn:hover {
    background: var(--color-primary);
    color: var(--color-text-dark);
    transform: translateY(-1px);
}

/* ==================== 입력 영역 ==================== */
.chatbot-input {
    padding: 1rem 1.25rem;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.chatbot-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    transition: all 0.2s ease;
}

.chatbot-input-wrapper:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(54, 226, 123, 0.1);
}

.chatbot-input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--color-text-white);
    font-size: 0.9rem;
    font-family: inherit;
}

.chatbot-input-wrapper input::placeholder {
    color: var(--color-text-gray);
    opacity: 0.7;
}

.chatbot-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    color: var(--color-text-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chatbot-send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px var(--color-primary);
}

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

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chatbot-send-btn .material-symbols-outlined {
    font-size: 1.25rem;
}

/* ==================== 드래그 가능 스타일 ==================== */
.chatbot-toggle.draggable {
    cursor: grab;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

.chatbot-toggle.draggable:active {
    cursor: grabbing;
}

.chatbot-toggle.dragging {
    opacity: 0.8;
    transform: scale(1.1);
    z-index: 10000;
}

/* ==================== 반응형 ==================== */
@media (max-width: 768px) {
    .chatbot-container {
        width: calc(100vw - 1.5rem);
        height: calc(100vh - 8rem);
        max-height: 600px;
        left: 0.75rem;
        right: auto;
        bottom: 5.5rem;
        border-radius: 1.25rem;
        transition: bottom 0.3s ease;
    }

    .chatbot-toggle {
        width: 52px;
        height: 52px;
        bottom: 1.5rem;
        right: 1.5rem;
        /* 모바일에서도 우측 하단 모서리 */
    }

    .chatbot-toggle .icon {
        font-size: 1.5rem;
    }

    .message {
        max-width: 90%;
    }

    /* 모바일에서 입력창이 키보드에 가려지지 않도록 */
    .chatbot-input {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    /* 키보드가 올라올 때 컨테이너 조정 */
    @supports (height: 100dvh) {
        .chatbot-container {
            max-height: calc(100dvh - 8rem);
        }
    }
}

@media (max-width: 480px) {
    .chatbot-toggle {
        width: 52px;
        height: 52px;
        bottom: 1.5rem;
        right: 1rem;
    }

    .chatbot-container {
        height: calc(100vh - 6rem);
        max-height: 500px;
        bottom: 4.5rem;
    }
}

/* ==================== 웰컴 메시지 스타일 ==================== */
.welcome-message {
    text-align: center;
    padding: 1.5rem;
}

.welcome-message h4 {
    color: var(--color-text-white);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.welcome-message p {
    color: var(--color-text-gray);
    font-size: 0.85rem;
    line-height: 1.5;
}