﻿/* ═══════════════════════════════════════════════
   chatbot.css — AI 챗봇 전용 스타일
   ※ site.css 이후에 로드할 것
   ═══════════════════════════════════════════════ */

/* ── PC 플로팅 버튼 ──────────────────────────── */
.chatbot-float {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99;
}

.chatbot-btn {
    width: 56px;
    height: 56px;
    border-radius: 17px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
    box-shadow: 0 8px 24px rgba(0,160,220,0.4);
    transition: transform .2s, box-shadow .2s;
    position: relative;
    overflow: hidden;
    padding: 0;
}

/* 나용이 마스코트 아바타 — 흰 배경 정사각 에셋 */
.chatbot-btn img,
.cp-avatar img,
.msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    display: block;
}

    .chatbot-btn:hover {
        transform: translateY(-3px) scale(1.05);
        box-shadow: 0 12px 32px rgba(0,160,220,0.5);
    }

.chatbot-online {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--success);
    border: 2.5px solid #fff;
    animation: pulse 2s infinite;
}

.chatbot-tooltip {
    position: absolute;
    right: 68px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--navy);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 7px 12px;
    border-radius: 9px;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s;
}

    .chatbot-tooltip::after {
        content: '';
        position: absolute;
        right: -5px;
        top: 50%;
        transform: translateY(-50%);
        width: 0;
        height: 0;
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        border-left: 6px solid var(--navy);
    }

.chatbot-float:hover .chatbot-tooltip {
    opacity: 1;
}

/* ── PC 챗봇 패널 ────────────────────────────── */
.chatbot-panel {
    position: fixed;
    bottom: 96px;
    right: 28px;
    z-index: 99;
    width: 560px;
    background: #fff;
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    overflow: hidden;
    display: none;
    flex-direction: column;
    height: 700px;
    max-height: calc(100vh - 120px);
    animation: chatSlideUp .2s ease;
}

    .chatbot-panel.open {
        display: flex;
    }

@keyframes chatSlideUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── 챗봇 공통 UI ────────────────────────────── */
.cp-head {
    background: linear-gradient(135deg, var(--navy), var(--navy-3));
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.cp-avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    overflow: hidden;
    flex-shrink: 0;
}

.cp-info strong {
    display: block;
    font-size: 15px;
    font-weight: 800;
    color: #fff;
}

.cp-info span {
    font-size: 11.5px;
    color: rgba(255,255,255,0.5);
    display: flex;
    align-items: center;
    gap: 4px;
}

    .cp-info span::before {
        content: '';
        width: 6px;
        height: 6px;
        background: var(--success);
        border-radius: 50%;
    }

.cp-close {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.6);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── 메시지 영역 ─────────────────────────────── */
.cp-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.msg {
    display: flex;
    gap: 8px;
    max-width: 95%;
    min-width: 0;
}

    .msg.user {
        margin-left: auto;
        flex-direction: row-reverse;
        max-width: 80%;
    }

.msg-bubble {
    padding: 11px 15px;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.55;
    min-width: 0;
    overflow-x: auto;
    word-break: break-word;
}

.msg-bubble img {
    max-width: 100%;
    height: auto;
    cursor: pointer;
}

/* ── 답변 속 마크다운 표 렌더링 ───────────────── */
.msg-bubble .msg-table-wrap {
    overflow-x: auto;
    margin: 8px 0;
}

.msg-bubble table.msg-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13.5px;
    line-height: 1.45;
    background: #fff;
}

.msg-bubble table.msg-table th,
.msg-bubble table.msg-table td {
    border: 1px solid #d5dbe3;
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
    word-break: keep-all;
    overflow-wrap: anywhere;
}

.msg-bubble table.msg-table th {
    background: #eef2f7;
    font-weight: 700;
    white-space: nowrap;
}

.msg-bubble table.msg-table tbody tr:nth-child(even) td {
    background: #f8fafc;
}

/* ── 이미지 라이트박스 모달 ───────────────────── */
.chatbot-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    animation: lbFadeIn .15s ease;
}

.chatbot-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
    object-fit: contain;
}

.chatbot-lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

@keyframes lbFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.msg.bot .msg-bubble {
    background: #f4f6fb;
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.msg.user .msg-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
    align-self: flex-end;
    overflow: hidden;
}

/* ── 추천 질문 ───────────────────────────────── */
.cp-suggestions {
    padding: 8px 12px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    border-top: 1px solid #f0f3f8;
    flex-shrink: 0;
}

.cp-sug-btn {
    padding: 6px 13px;
    border-radius: 20px;
    background: #f0f3f8;
    border: 1px solid #e0e6f0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    cursor: pointer;
    transition: all .12s;
}

    .cp-sug-btn:hover {
        background: var(--primary);
        border-color: var(--primary);
        color: #fff;
    }

/* ── 입력창 ──────────────────────────────────── */
.cp-input-row {
    padding: 12px 14px;
    border-top: 1px solid #f0f3f8;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.cp-input {
    flex: 1;
    padding: 11px 15px;
    border-radius: 11px;
    border: 1.5px solid #e0e6f0;
    font-size: 15px;
    font-family: 'Pretendard', sans-serif;
    outline: none;
    transition: border .12s;
    background: #f7f9fc;
}

    .cp-input:focus {
        border-color: var(--primary);
        background: #fff;
    }

    .cp-input:disabled {
        background: #f0f3f8;
        color: var(--text-3);
    }

.cp-send {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    flex-shrink: 0;
}

    .cp-send:disabled {
        background: var(--text-3);
        cursor: not-allowed;
    }

/* ── 타이핑 로딩 점 ──────────────────────────── */
.typing-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    animation: typingBounce 1.1s infinite ease-in-out;
}

    .typing-dot:nth-child(2) {
        animation-delay: .18s;
    }

    .typing-dot:nth-child(3) {
        animation-delay: .36s;
    }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: .4;
    }

    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ── 모바일 챗봇 (기본 숨김) ─────────────────── */
#chatbotMobile {
    display: none;
}

/* ── 반응형: 모바일 ──────────────────────────── */
@media (max-width: 768px) {

    /* PC 플로팅 & 패널 숨김 */
    .chatbot-float {
        display: none;
    }

    .chatbot-panel {
        display: none !important;
    }

    /* ★ 모바일 챗봇 전체화면 — 입력창 고정 수정 */
    #chatbotMobile {
        display: flex; /* block → flex (핵심 수정) */
        flex-direction: column;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 100vh;
        height: 100dvh; /* 모바일 주소창 대응 */
        transform: translateY(100%);
        transition: transform 0.3s ease;
        z-index: 9999;
        background: #fff;
    }

        #chatbotMobile.open {
            transform: translateY(0);
        }

        /* 모바일에서 메시지 영역이 남은 공간을 채우도록 */
        #chatbotMobile .cp-messages {
            flex: 1;
            min-height: 0; /* flex 자식 오버플로우 방지 */
        }
}

/* ═══════════════════════════════════════════════
   홈 화면 임베디드 챗봇 (chat-dock)
   — 메인 우측 절반에 항상 표시되는 챗봇 패널
   ═══════════════════════════════════════════════ */
.chat-dock {
    display: flex;
    flex-direction: column;
    /* 첫 화면(스크롤 전)에서 알림배너+패딩만큼 밀려도 하단 입력창이 잘리지 않도록
       여유(100px)를 빼고, 모바일 주소창 대응 위해 동적 뷰포트(100dvh) 사용 */
    height: calc(100dvh - var(--header-h) - 100px);
    min-height: 360px;
    background: #fff;
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(10,22,40,0.08);
    overflow: hidden;
}

/* 챗봇이 화면에 상시 노출되므로 플로팅 버튼/패널은 숨김 */
body:has(.chat-dock) .chatbot-float,
body:has(.chat-dock) .chatbot-panel {
    display: none !important;
}

@media (max-width: 1100px) {
    .chat-dock {
        height: 560px;
        min-height: 0;
    }
}
