/* 고급 채팅 시스템 스타일 */

/* 고급 채팅 위젯 */
.advanced-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 채팅 토글 버튼 */
.chat-toggle {
    width: 60px;
    height: 60px;
    background: var(--color-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--color-primary-shadow, rgba(59, 130, 246, 0.3));
    transition: all 0.3s ease;
    position: relative;
    border: none;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px var(--color-primary-shadow-hover, rgba(59, 130, 246, 0.4));
}

.chat-toggle:active,
.chat-toggle.active-touch {
    transform: scale(0.95);
    background: var(--color-primary-hover, #1d4ed8);
}

.chat-icon {
    font-size: 24px;
    color: white;
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--color-error);
    color: var(--color-text-inverse);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* 채팅 컨테이너 */
.chat-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    max-height: 80vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px var(--color-shadow-large, rgba(0, 0, 0, 0.15));
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
    overflow: hidden;
    z-index: 9999;
}

.advanced-chat-widget.active .chat-container {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1) !important;
    display: flex !important;
}

/* 채팅 헤더 */
.chat-header {
    background: var(--color-primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 16px 16px 0 0;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.chat-close:hover {
    background: var(--color-overlay-light, rgba(255, 255, 255, 0.2));
}

/* 채팅 메시지 영역 */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--color-surface-secondary);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

/* 채팅 메시지 */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.user-message .message-content {
    background: var(--color-primary);
    color: white;
    border-bottom-right-radius: 6px;
}

.bot-message .message-content {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px var(--color-shadow-light, rgba(0, 0, 0, 0.05));
}

.message-text {
    line-height: 1.5;
    font-size: 14px;
}

.message-text a {
    color: inherit;
    text-decoration: underline;
}

.message-time {
    font-size: 11px;
    color: var(--color-text-secondary);
    margin-top: 4px;
    align-self: flex-end;
}

.user-message .message-time {
    color: var(--color-text-muted);
}


/* 타이핑 인디케이터 */
.typing-message .message-content {
    background: white;
    border: 1px solid var(--color-border);
    padding: 16px;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
}

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

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

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 채팅 입력 영역 */
.chat-input-container {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--color-border);
    position: relative;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 24px;
    padding: 8px;
    transition: border-color 0.3s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light, rgba(59, 130, 246, 0.1));
}

.chat-action-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
    color: var(--color-text-secondary);
}

.chat-action-btn:hover {
    background: var(--color-border);
    color: var(--color-primary);
}

.chat-input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 14px;
    color: var(--color-text);
    padding: 8px 0;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
}

.chat-input::placeholder {
    color: var(--color-text-muted);
}

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

.chat-send-btn:hover {
    background: var(--color-primary-hover);
    transform: scale(1.05);
}

.send-icon {
    font-size: 16px;
    transform: rotate(90deg);
}

/* FAQ 빠른 버튼 */
.faq-message {
    margin: 10px 0;
}

.faq-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.faq-btn {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 10px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.faq-btn:hover {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--color-primary-shadow);
}

.faq-btn:active {
    transform: translateY(0);
}

/* 채팅 오류 메시지 */
.chat-error {
    background: var(--color-surface-secondary);
    color: var(--color-error);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    font-size: 14px;
    margin: 8px 0;
    animation: errorShake 0.5s ease;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* 반응형 디자인 - 개선된 모바일 최적화 */

/* 다크 모드 지원 */
@media (prefers-color-scheme: dark) {
    .chat-container {
        background: var(--color-surface);
        border: 1px solid var(--color-border);
    }
    
    .chat-header {
        background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
    }
    
    .chat-messages {
        background: var(--color-background);
    }
    
    .bot-message .message-content {
        background: var(--color-surface-secondary);
        color: var(--color-text);
        border-color: var(--color-border);
    }
    
    
    .chat-input-container {
        background: var(--color-surface);
        border-color: var(--color-border);
    }
    
    .chat-input-wrapper {
        background: var(--color-surface-secondary);
        border-color: var(--color-border);
    }
    
    .chat-input {
        color: var(--color-text);
    }
    
    .chat-input::placeholder {
        color: var(--color-text-secondary);
    }
    
    .chat-action-btn {
        color: var(--color-text-muted);
    }
    
    .chat-action-btn:hover {
        background: var(--color-border);
        color: var(--color-info);
    }
    
    
    .typing-message .message-content {
        background: var(--color-surface-secondary);
        border-color: var(--color-border);
    }
    
    .chat-error {
        background: var(--color-surface-secondary);
        color: var(--color-error);
        border-color: var(--color-border);
    }
}

/* 접근성 개선 */
.chat-toggle:focus,
.chat-close:focus,
.chat-action-btn:focus,
.chat-send-btn:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* 고대비 모드 지원 */
@media (prefers-contrast: high) {
    .chat-container {
        border: 2px solid var(--color-text);
    }
    
    .chat-toggle {
        border: 2px solid var(--color-text-inverse);
    }
    
    .message-content {
        border: 1px solid var(--color-text);
    }
}

/* 애니메이션 최적화 */
.chat-message,
.chat-container {
    will-change: transform, opacity;
}

/* 성능 최적화 */
.chat-messages {
    contain: layout style paint;
}

.chat-input-wrapper {
    contain: layout style;
}

/* 모바일 반응형 디자인 */
@media (max-width: 768px) {
    /* 모바일 채팅 위젯 위치 조정 */
    .advanced-chat-widget {
        bottom: 15px;
        right: 15px;
    }
    
    /* 모바일 채팅 컨테이너 최적화 */
    .chat-container {
        width: calc(100vw - 20px);
        height: calc(100vh - 120px);
        max-height: 75vh;
        bottom: 15px;
        position: fixed;
        border-radius: 12px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
    }
    
    /* 모바일 채팅 토글 버튼 */
    .chat-toggle {
        width: 50px;
        height: 50px;
    }
    
    .chat-icon {
        font-size: 20px;
    }
    
    /* 모바일 채팅 헤더 */
    .chat-header {
        padding: 12px 16px;
    }
    
    .chat-title {
        font-size: 14px;
    }
    
    /* 모바일 채팅 메시지 영역 */
    .chat-messages {
        padding: 12px;
    }
    
    /* 모바일 채팅 입력 영역 */
    .chat-input-container {
        padding: 12px 16px;
    }
    
    .chat-input {
        font-size: 16px; /* iOS 줌 방지 */
        padding: 12px 14px;
        border-radius: 20px;
    }
    
    /* 모바일 채팅 액션 버튼들 */
    .chat-action-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .chat-send-btn {
        width: 40px;
        height: 40px;
    }
    
    /* 모바일 메시지 스타일 */
    .message-content {
        font-size: 14px;
        padding: 8px 12px;
        max-width: calc(100% - 60px);
    }
    
    .user-message .message-content {
        margin-left: 8px;
    }
    
    .bot-message .message-content {
        margin-right: 8px;
    }
    
    
    /* 모바일 타이핑 인디케이터 */
    .typing-indicator {
        padding: 8px 12px;
    }
    
    .typing-dots span {
        width: 6px;
        height: 6px;
    }
    
    /* 모바일 FAQ 버튼 최적화 */
    .faq-buttons {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .faq-btn {
        padding: 12px;
        font-size: 14px;
        border-radius: 18px;
    }
}

@media (max-width: 480px) {
    /* 매우 작은 모바일 화면 */
    .advanced-chat-widget {
        bottom: 10px;
        right: 10px;
    }
    
    .chat-container {
        width: calc(100vw - 20px);
        height: calc(100vh - 140px);
        max-height: 65vh;
        bottom: 75px;
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        margin: 0;
        z-index: 10000;
        border-radius: 8px;
    }
    
    .chat-toggle {
        width: 45px;
        height: 45px;
    }
    
    .chat-icon {
        font-size: 18px;
    }
    
    .chat-badge {
        width: 18px;
        height: 18px;
        font-size: 10px;
        top: -3px;
        right: -3px;
    }
    
}
