/* ==================================================
   챗봇 공통 규격
   ================================================== */
:root {
    --chatbot-width: 31.25rem;
    --chatbot-height: 37.5rem;
    --chatbot-edge-space: var(--size-20);
    --chatbot-responsive-edge-space: var(--size-20);
    --chatbot-mobile-edge-space: var(--size-12);
    --chatbot-frame-bottom-space: var(--size-70);
    --chatbot-border-radius: var(--size-12);
    --chatbot-button-size: var(--size-60);
    --chatbot-button-min-height: var(--size-72);
    --chatbot-button-padding-y: var(--size-18);
    --chatbot-button-padding-x: var(--size-30);
    --chatbot-button-border-radius: var(--size-38);
    --chatbot-button-font-size: var(--size-23);
    --chatbot-button-color: #007bff;
    --chatbot-button-hover-color: #0056b3;
    --chatbot-button-text-color: #ffffff;
    --chatbot-menu-gap: var(--size-8);
    --chatbot-close-button-size: var(--size-40);
    --chatbot-close-button-gap: var(--size-8);
    --chatbot-close-button-space: calc(var(--chatbot-close-button-size) + var(--chatbot-close-button-gap));
    --chatbot-frame-shadow: 0 var(--size-4) var(--size-16) rgba(0, 0, 0, 0.2);
    --chatbot-button-shadow: 0 var(--size-4) var(--size-10) rgba(0, 0, 0, 0.2);
    --chatbot-frame-z-index: 99999;
    --chatbot-button-z-index: 100000;
    --chatbot-transition-duration: 0.3s;
}

/* ==================================================
   일반 스타일 (데스크톱 기본)
   ================================================== */
#chat-iframe {
    display: none;
    position: fixed;
    right: var(--chatbot-edge-space);
    bottom: var(--chatbot-frame-bottom-space);
    z-index: var(--chatbot-frame-z-index);
    width: var(--chatbot-width);
    height: var(--chatbot-height);
    border: 0;
    border-radius: var(--chatbot-border-radius);
    box-shadow: var(--chatbot-frame-shadow);
    transition: opacity var(--chatbot-transition-duration) ease;
}

.floating-quick-menu {
    position: fixed;
    top: auto;
    right: var(--chatbot-edge-space);
    bottom: calc(var(--chatbot-edge-space) + env(safe-area-inset-bottom, 0px));
    z-index: var(--chatbot-button-z-index);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--chatbot-menu-gap);
    transform: none;
}

#chat-close-btn {
    display: block;
    width: var(--chatbot-button-size);
    height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    transition: transform var(--chatbot-transition-duration) ease;
}

#chat-toggle-btn {
    display: block;
    min-height: var(--chatbot-button-min-height);
    padding: var(--chatbot-button-padding-y) var(--chatbot-button-padding-x);
    border: 0;
    border-radius: var(--chatbot-button-border-radius);
    background-color: var(--chatbot-button-color);
    box-shadow: var(--chatbot-button-shadow);
    color: var(--chatbot-button-text-color);
    font-size: var(--chatbot-button-font-size);
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background-color var(--chatbot-transition-duration) ease,
        transform var(--chatbot-transition-duration) ease;
}

#chat-close-btn {
    display: none;
    position: fixed;
    top: max(var(--size-12), calc(100vh - var(--chatbot-frame-bottom-space) - var(--chatbot-height) - var(--chatbot-close-button-size) - var(--chatbot-close-button-gap)));
    right: var(--chatbot-edge-space);
    width: var(--chatbot-close-button-size);
    height: var(--chatbot-close-button-size);
    border-radius: 50%;
    background: #ffffff;
    box-shadow: var(--chatbot-frame-shadow);
    color: #414141;
    font-size: var(--size-32);
    line-height: 1;
}

.floating-quick-menu.is-chat-open #chat-toggle-btn {
    display: none;
}

.floating-quick-menu.is-chat-open {
    top: 0;
    right: 0;
    bottom: auto;
    transform: none;
}

.floating-quick-menu.is-chat-open #chat-close-btn {
    display: block;
}

#chat-close-btn:focus-visible {
    outline: var(--size-2) solid #195bd7;
    outline-offset: var(--size-2);
    border-radius: var(--size-4);
}

#chat-toggle-btn:focus-visible {
    outline: var(--size-2) solid var(--chatbot-button-text-color);
    outline-offset: var(--size-2);
}

@media (hover: hover) and (pointer: fine) {
    #chat-close-btn:hover {
        transform: scale(1.05);
    }

    #chat-toggle-btn:hover {
        background-color: var(--chatbot-button-hover-color);
        transform: scale(1.05);
    }
}

/* ==================================================
   미디어 쿼리 - 태블릿 포함 (1024px 이하)
   화면 여백만 남긴 풀스크린 형태로 적용
   ================================================== */
@media (max-width: 64rem) {
    #chat-iframe {
        top: calc(var(--chatbot-responsive-edge-space) + var(--chatbot-close-button-space) + env(safe-area-inset-top, 0px));
        right: calc(var(--chatbot-responsive-edge-space) + env(safe-area-inset-right, 0px));
        bottom: auto;
        left: auto;
        width: calc(100vw - (var(--chatbot-responsive-edge-space) * 2) - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
        max-width: none;
        height: calc(100vh - (var(--chatbot-responsive-edge-space) * 2) - var(--chatbot-close-button-space) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        height: calc(100dvh - (var(--chatbot-responsive-edge-space) * 2) - var(--chatbot-close-button-space) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        max-height: none;
    }

    #chat-close-btn {
        top: calc(var(--chatbot-responsive-edge-space) + env(safe-area-inset-top, 0px));
        right: calc(var(--chatbot-responsive-edge-space) + env(safe-area-inset-right, 0px));
    }
}

/* ==================================================
   미디어 쿼리 - 모바일 (768px 이하)
   ================================================== */
@media (max-width: 48rem) {
    :root {
        --chatbot-responsive-edge-space: var(--chatbot-mobile-edge-space);
        --chatbot-button-min-height: var(--size-48);
        --chatbot-button-padding-y: var(--size-12);
        --chatbot-button-padding-x: var(--size-20);
        --chatbot-button-border-radius: var(--size-25);
        --chatbot-button-font-size: var(--size-15);
    }

    #chat-iframe {
        border-radius: var(--chatbot-border-radius);
    }

    .floating-quick-menu {
        right: var(--chatbot-mobile-edge-space);
        bottom: calc(var(--chatbot-mobile-edge-space) + env(safe-area-inset-bottom, 0px));
    }

    #chat-close-btn {
        top: calc(var(--chatbot-mobile-edge-space) + env(safe-area-inset-top, 0px));
        right: calc(var(--chatbot-mobile-edge-space) + env(safe-area-inset-right, 0px));
    }
}

/* ==================================================
   미디어 쿼리 - 모션 최소화 설정
   ================================================== */
@media (prefers-reduced-motion: reduce) {
    #chat-iframe,
    #chat-toggle-btn,
    #chat-close-btn {
        transition: none;
    }
}
