/* 채팅 위젯 스타일 */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 185px; /* 사이드바(165px) 왼쪽에 위치 */
    z-index: 9999;
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* 사이드바가 숨겨지는 화면에서는 우측으로 */
@media (max-width: 1124px) {
    body .chat-widget {
        right: 10px;
        bottom: 80px;
        z-index: 999999;
        pointer-events: auto;
    }

    body .chat-widget .chat-toggle-btn {
        width: 50px;
        height: 50px;
        pointer-events: auto;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        cursor: pointer;
    }

    /* 모바일에서 채팅창 열렸을 때 토글 버튼 숨김 */
    body .chat-widget .chat-toggle-btn.chat-open {
        display: none;
    }
}

/* 채팅 버튼 */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #364052;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(54, 64, 82, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: visible;
    /* 모바일 터치 지원 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    user-select: none;
    -webkit-user-select: none;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.chat-toggle-btn svg {
    display: none;
}

/* 눈 컨테이너 */
.chat-eyes {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
}

/* 눈 */
.chat-eye {
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
}

/* 눈동자 */
.chat-pupil {
    width: 14px;
    height: 14px;
    background: #333;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: lookAround 4s ease-in-out infinite;
}

/* 눈동자 하이라이트 */
.chat-pupil::before,
.chat-pupil::after {
    content: '';
    position: absolute;
    background: white;
    border-radius: 50%;
}

.chat-pupil::before {
    width: 4px;
    height: 4px;
    top: 2px;
    left: 4px;
}

.chat-pupil::after {
    width: 2px;
    height: 2px;
    top: 7px;
    left: 8px;
}

/* 스마일 입 */
.chat-smile {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 13px;
    height: 7px;
    border: 2px solid white;
    border-top: none;
    border-radius: 0 0 13px 13px;
}

/* 눈동자 좌우 움직임 */
@keyframes lookAround {
    0%, 100% {
        transform: translate(-50%, -50%);
    }
    25% {
        transform: translate(-80%, -50%);
    }
    50% {
        transform: translate(-20%, -50%);
    }
    75% {
        transform: translate(-80%, -50%);
    }
}

/* 눈 깜박임 */
.chat-eye::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #364052;
    transform: scaleY(0);
    transform-origin: top;
    animation: blink 5s ease-in-out infinite;
}

@keyframes blink {
    0%, 94%, 96%, 100% {
        transform: scaleY(0);
    }
    95% {
        transform: scaleY(1);
    }
}

/* 읽지 않은 메시지 뱃지 */
.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
}

/* 채팅 창 */
.chat-window {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 310px;
    height: 420px;
    min-width: 230px;
    min-height: 300px;
    max-width: 380px;
    max-height: 550px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    overflow: hidden;
    flex-direction: column;
    resize: both;
    user-select: none;
}

.chat-window.active {
    display: flex;
    animation: slideUp 0.3s ease;
}

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

/* 채팅 헤더 */
.chat-header {
    background: #364052;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
    user-select: none;
}

.chat-header-title {
    font-size: 16px;
    font-weight: bold;
}

.chat-header-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin-top: 2px;
}

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

.chat-header-actions button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 채팅 메시지 영역 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f5f5f5;
}

.chat-message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-message.sent {
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #364052;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}

.chat-message-content {
    max-width: 70%;
}

.chat-message-sender {
    font-size: 11px;
    color: #666;
    margin-bottom: 4px;
    padding: 0 12px;
}

.chat-message.sent .chat-message-sender {
    text-align: right;
}

.chat-message-bubble {
    background: white;
    padding: 10px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-message.sent .chat-message-bubble {
    background: #4A5568;
    color: white;
}

.chat-message.received .chat-message-bubble {
    background: #F7FAFC;
    color: #333;
    border: 1px solid #E2E8F0;
}

.chat-message.system .chat-message-bubble {
    background: #e3f2fd;
    color: #1976d2;
    text-align: center;
    font-size: 12px;
}

.chat-message-image {
    max-width: 200px;
    border-radius: 12px;
    cursor: pointer;
}

/* PDF 파일 메시지 스타일 */
.chat-file-message {
    background: #f8f9fa !important;
    padding: 8px 12px !important;
}

.chat-file-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #333;
}

.chat-file-link:hover {
    color: #1466BA;
}

.chat-file-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.chat-file-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chat-file-name {
    font-size: 12px;
    font-weight: 500;
    word-break: break-all;
    line-height: 1.3;
}

.chat-file-size {
    font-size: 10px;
    color: #888;
}

.chat-message-time {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    padding: 0 12px;
}

/* 채팅 입력 영역 */
.chat-input-area {
    padding: 8px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.chat-input-wrapper {
    display: flex;
    gap: 5px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    font-size: 11px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #364052;
}

.chat-image-btn,
.chat-send-btn {
    background: #364052;
    border: none;
    color: white;
    width: 23px;
    height: 23px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: bold;
}

.chat-image-btn:hover,
.chat-send-btn:hover {
    background: #4a5568;
    transform: scale(1.05);
}

.chat-image-btn {
    background: #f0f0f0;
    color: #666;
    font-size: 17px;
}

.chat-image-btn:hover {
    background: #e0e0e0;
}

.chat-send-btn svg {
    width: 12px;
    height: 12px;
}

/* 파일 입력 숨김 */
#chat-image-input {
    display: none;
}

/* 스크롤바 스타일 */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 로딩 인디케이터 */
.chat-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.chat-loading-dots {
    display: flex;
    gap: 5px;
}

.chat-loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #364052;
    animation: bounce 1.4s infinite ease-in-out both;
}

.chat-loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.chat-loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* 이름 입력 모달 */
.chat-name-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999999;
    align-items: center;
    justify-content: center;
}

.chat-name-modal.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.chat-name-modal-content {
    background: white;
    border-radius: 20px;
    padding: 35px;
    width: 90%;
    max-width: 380px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.chat-name-modal-header {
    text-align: center;
    margin-bottom: 25px;
}

.chat-name-modal-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.chat-name-modal-title {
    font-size: 20px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

.chat-name-modal-subtitle {
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}

.chat-name-modal-body {
    margin-bottom: 25px;
}

.chat-name-modal-label {
    display: block;
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
    font-weight: 500;
}

.chat-name-modal-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
    box-sizing: border-box;
}

.chat-name-modal-input:focus {
    border-color: #364052;
    box-shadow: 0 0 0 3px rgba(54, 64, 82, 0.1);
}

.chat-name-modal-footer {
    display: flex;
    gap: 10px;
}

.chat-name-modal-btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-name-modal-btn-primary {
    background: #364052;
    color: white;
}

.chat-name-modal-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(54, 64, 82, 0.3);
}

.chat-name-modal-btn-secondary {
    background: #f5f5f5;
    color: #666;
}

.chat-name-modal-btn-secondary:hover {
    background: #e8e8e8;
}

/* 모바일 반응형 */
@media (max-width: 480px) {
    /* 모바일 전체화면 채팅창 - 카톡 스타일 */
    .chat-widget .chat-window {
        display: none;
    }

    .chat-widget .chat-window.active {
        display: flex;
        flex-direction: column;
        position: fixed;
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        min-width: 100%;
        min-height: 100%;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        transform: none;
        resize: none;
        z-index: 999999;
    }

    .chat-widget .chat-messages {
        flex: 1;
        overflow-y: auto;
        padding: 15px;
        min-height: 0;
    }

    .chat-widget .chat-header {
        padding: 15px;
        border-radius: 0;
        flex-shrink: 0;
    }

    /* 모바일 헤더 버튼 크기 증가 */
    .chat-widget .chat-header-actions button {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
    }

    .chat-widget .chat-header-actions button svg {
        width: 22px;
        height: 22px;
    }

    .chat-widget .chat-input-area {
        flex-shrink: 0;
    }

    .chat-name-modal-content {
        padding: 25px;
        max-width: calc(100vw - 40px);
    }

    /* 모바일 입력 영역 - 키보드 대응 */
    .chat-input-area {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        box-sizing: border-box;
        overflow: hidden;
        position: sticky;
        bottom: 0;
        background: white;
    }

    .chat-input-wrapper {
        gap: 8px;
        max-width: 100%;
        box-sizing: border-box;
    }

    .chat-input {
        font-size: 16px;
        padding: 10px 14px;
        min-width: 0;
        flex: 1;
    }

    /* 모바일 보내기/이미지 버튼 */
    .chat-widget .chat-send-btn,
    .chat-widget .chat-image-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        flex-shrink: 0;
    }

    .chat-widget .chat-send-btn svg {
        width: 20px;
        height: 20px;
    }

    .chat-widget .chat-image-btn {
        font-size: 22px;
    }
}
