/* ================================ FullCount 메인 챗 위젯 — 최종본 (일반 배치 / 입력창 고정 / 채팅창 위로 열림) ================================ */
/* 전역 변수 */
:root {
    --fc-navy: #0B3D91;
    --fc-line: #e6e6e6;
    --fc-gap: 10px;
    /* 기본 여백 */
    --barH: 28px;
    /* #chatInput 높이 */
    --log-lift: 25px;
    /* 채팅창을 추가로 더 위로 올릴 양 (원하면 조절) */
    --header-h: 65px;
    --kb-offset: 0px;
}

/* 컨테이너: 뷰포트 고정 + 푸터 보호 오프셋 */
#fcChat {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(24px + var(--footer-offset, 0px));
    /* ← 핵심 */
    width: 90%;
    max-width: 900px;
    z-index: 999;
    /* 메뉴바(보통 1000+)보다 낮게 설정 */
    --gap: 10px;
    --barH: 48px;
    padding-bottom: calc(var(--barH) + var(--gap));
}

/* 2) 채팅창(로그): 입력창 위로 떠서 열림 */
#chatLog {
    position: absolute;
    left: var(--fc-gap);
    right: var(--fc-gap);
    bottom: calc(var(--barH) + var(--fc-gap));
    /* 입력창과 붙임 */
    z-index: 2;
    /* 입력창보다 위 */
    display: none;
    /* 기본 비표시 */
    background: #fff;
    border: 1px solid var(--fc-line);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
    padding: var(--fc-gap);
    /* ======================================== 📏 채팅창 높이 조절 (여기서 수정!) ======================================== */
    height: 350px;
    /* ← 기본 고정 높이 (인사 메시지가 보이도록 줄임) */
    max-height: clamp(280px, 45vh, 380px);
    /* ← 최대 높이: (최소 280px, 화면의 45%, 최대 380px) */
    /* max-height 값 설명: - 280px = 최소 높이 - 45vh = 화면 높이의 45% - 380px = 절대 최대 높이 (이 값을 늘리면 더 길어짐) */
    overflow-y: auto;
    /* ← 세로 스크롤 활성화 */
    overflow-x: hidden;
    /* ← 가로 스크롤 숨김 */
    overscroll-behavior: contain;
    /* ← 스크롤이 밖으로 전파되지 않게 */
}

#fcChat.active #chatLog {
    display: block;
}

/* 3) 입력창: 하단 고정(그대로) */
/* 입력창은 하단 고정, 로그는 위로 펼침(이미 적용한 구조면 그대로) */
.fc-chat__input {
    position: absolute;
    left: var(--gap);
    right: var(--gap);
    bottom: var(--gap);
    height: var(--barH);
    display: flex;
    gap: 8px;
    align-items: center;
}

#chatInput {
    flex: 1;
    height: 100%;
    padding: 0 16px;
    border: 1px solid var(--fc-line);
    border-radius: 24px;
    background: #fff;
    font-size: 16px;
    outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
    transition: border-color .2s, box-shadow .2s;
}

#chatInput:focus {
    border-color: var(--fc-navy);
    box-shadow: 0 2px 12px rgba(11, 61, 145, .15);
}

#chatInput::placeholder {
    color: #999;
}

/* 전송 버튼 (PC에서는 숨김) */
.fc-send-btn {
    display: none;
    width: var(--barH);
    height: var(--barH);
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--fc-navy);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(11, 61, 145, .2);
    transition: background .2s, box-shadow .2s;
}

.fc-send-btn:hover {
    background: #0a3275;
    box-shadow: 0 4px 12px rgba(11, 61, 145, .3);
}

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

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

/* 4) 메시지 기본 스타일 */
.fc-row {
    display: flex;
    gap: var(--fc-gap);
    margin: var(--fc-gap);
    min-width: 0;
}

.fc-row.user {
    justify-content: flex-end;
}

.fc-row.bot {
    justify-content: flex-start;
    align-items: flex-end;
}

.fc-bubble {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: 18px;
    border: 1px solid var(--fc-line);
    background: #f5f5f5;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
}

.fc-row.user .fc-bubble {
    background: #eef3ff;
    border-color: #dbe6ff;
}

/* 5) 아바타 */
.fc-avatar {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 50%;
    background: var(--fc-navy) url('/assets/img/Baseball_speech_bubble_icon.png') center/cover no-repeat;
}

/* 6) 반응형 */
@media (min-width:1200px) {
    #fcChat {
        max-width: 900px;
    }

    #chatLog {
        min-height: 520px;
        max-height: 70vh;
    }
}

/* 7) 모바일: 메뉴 열릴 때 챗봇 숨김(선택) */
@media (max-width:768px) {
    body.menu-open #fcChat {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }

    /* 🔵 화면 전체 덮는 오버레이 컨테이너 */
    #fcChat {
        position: fixed;
        /* 꼭 fixed */
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        /* 전체 화면 */
        transform: none;
        width: 100%;
        max-width: none;
        padding-bottom: 0;
        z-index: 999;
    }

    /* 🔵 대화창: 헤더 밑 ~ 입력창 위 영역만 차지, 여기만 스크롤 */
    #chatLog {
        position: absolute;
        top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 145px);
        /* 아이폰 노치/주소창 대응 */
        left: 0;
        right: 0;
        /* 입력창 + 키보드 보정 만큼 위에서 끝나게 */
        bottom: calc(var(--barH) + env(safe-area-inset-bottom, 0px) + var(--kb-offset));
        margin: 0;
        border-radius: 0;
        height: auto;
        max-height: none;
        padding: var(--fc-gap);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 900;
        /* 입력창보다 뒤 */
    }

    /* 🔵 입력창 컨테이너: 항상 화면 맨 아래에, 키보드 올라오면 JS로 올려줌 */
    .fc-chat__input {
        position: fixed;
        /* 뷰포트 기준 고정 */
        left: 0;
        right: 0;
        bottom: calc(env(safe-area-inset-bottom, 0px) + var(--kb-offset));
        /* 아이폰 노치 + 키보드 보정 */
        height: var(--barH);
        width: 100%;
        padding: 0 8px;
        box-sizing: border-box;
        z-index: 1000;
        /* chatLog보다 항상 앞 */
        display: flex;
        gap: 8px;
        background: #fff;
    }

    #chatInput {
        flex: 1;
        border-radius: 24px;
        padding: 0 16px;
    }

    /* 모바일에서 전송 버튼 표시 */
    .fc-send-btn {
        display: flex;
    }

    /* iOS 기기에서만 top 값을 더 내리는 CSS 추가 */
    #chatLog,
    body.ios #chatLog {
        top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 145px);
    }
}


/* body 스크롤은 전역에서 제어하지 않습니다. */
/* 스크롤바 스타일 */
#chatLog::-webkit-scrollbar,
.fc-chat__log::-webkit-scrollbar {
    width: 8px;
}

#chatLog::-webkit-scrollbar-thumb,
.fc-chat__log::-webkit-scrollbar-thumb {
    background: #cfd6e3;
    border-radius: 6px;
}

#chatLog::-webkit-scrollbar-track,
.fc-chat__log::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 6px;
}