/* Extracted from app.css for route-specific maintainability. */
/* 🤖 하단 AI 채팅바 (PC 짤림 방지 완결판) */
.chat-bar {
    position: fixed;
    bottom: 0;
    left: 180px; /* 🌟 PC 사이드바 너비만큼 시작 지점을 조절 */
    right: 0;
    height: auto;
    background: transparent;
    border-top: none;
    display: flex;
    align-items: center;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
    z-index: 1000;
    box-sizing: border-box; /* 패딩이 너비에 포함되게 설정 */
    pointer-events: none; /* 내부 컨테이너만 클릭 */
}

/* 🤖 채팅바 컨테이너 (기준점) */
.chat-container {
    display: flex;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    align-items: center;
    position: relative; /* 🌟 이게 있어야 말풍선이 위로 뜹니다! */
    background: #ffffff;
    border-radius: 14px;
    padding: 8px 8px 8px 10px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
    border: 1px solid #e2e8f0;
    box-sizing: border-box;
    pointer-events: auto;
}

.chat-input {
    flex: 1;
    height: 40px;
    border: 0;
    border-radius: 12px;
    padding: 0 12px;
    font-size: 14px;
    outline: none;
    background-color: #f1f5f9;
    color: #0f172a;
    min-width: 0;
}

.chat-input:focus { box-shadow: 0 0 0 3px rgba(0, 85, 170, 0.22); background-color: #ffffff; }

.chat-send-btn {
    width: 40px;
    height: 40px;
    background-color: #0055aa;
    color: #ffffff;
    border: none;
    border-radius: 12px;
    margin-left: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 6px 14px rgba(0, 85, 170, 0.26);
}
.chat-send-btn:active { transform: translateY(0.5px); opacity: 0.95; }
.chat-send-btn.chat-send-btn--listening {
    background-color: #b91c1c !important;
    box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.35), 0 6px 14px rgba(185, 28, 28, 0.35);
    animation: chat-send-pulse 1s ease-in-out infinite;
}
@keyframes chat-send-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.88; }
}

#chat-response-area {
    position: absolute; /* 🌟 공중에 띄움 */
    bottom: 74px;       /* 🌟 입력창에서 위로 */
    left: 0;
    right: 0;
    background-color: white;
    padding: 0;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    border: 2px solid #2563eb;
    z-index: 2000;
    max-height: 350px;
    overflow: hidden;
    overscroll-behavior: contain;
    /* display/flexDirection 은 콜백 인라인(style)로만 — 기본 display:flex 가 display:none 을 덮어 빈 말풍선이 떠 보이는 문제 방지 */
}

/* 닫기는 헤더(스크롤 밖), 본문만 스크롤 */
.ai-chat-bubble__header {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    min-height: 40px;
    padding: 8px 10px 4px 14px;
    box-sizing: border-box;
}

.ai-chat-bubble__close {
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    color: #94a3b8;
    font-weight: 700;
    padding: 4px 8px;
    margin: 0;
    position: relative;
    z-index: 10002;
}

.ai-chat-bubble__close:active {
    background: #f1f5f9;
}

.ai-chat-bubble__scroll {
    flex: 1 1 auto;
    min-height: 0;
    /* flex 부모 높이가 불명확할 때도 스크롤 되도록 고정 max-height (헤더 제외 본문만) */
    max-height: none;
    height: 100%;
    overflow-y: auto !important;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 0 16px 16px 16px;
    box-sizing: border-box;
    position: relative;
    isolation: isolate;
}

/* AI 채팅: 로딩(생성중)일 때는 중앙 정렬 */
#chat-response-area[data-ai-loading="1"] .ai-chat-bubble__scroll {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px 16px 16px;
}
#chat-response-area[data-ai-loading="1"] #chat-response-content {
    width: 100%;
    text-align: center;
    font-weight: 800;
    color: #0f172a;
    padding: 18px 10px;
}

/* dcc.Loading 래퍼가 높이를 무한히 키우지 않도록 */
#chat-response-area .ai-chat-bubble__scroll > div {
    min-height: 0;
    max-height: 100%;
}

/* 말풍선 열림 시 배경 스크롤/터치 차단 오버레이 */
#ai-chat-overlay {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    /* 채팅 입력바 영역은 막지 않기 위해 하단 여백을 둔다 */
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    z-index: 9999;
    background: transparent;
    overscroll-behavior: none;
    /* overlay는 배경만 막고, 버블/본문 스크롤은 허용해야 함 */
    touch-action: auto;
    /* overlay는 배경 클릭/스크롤 차단용 (클릭 관통 방지) */
    pointer-events: auto;
}

/* 말풍선 내부 내용 스크롤 영역 */
#chat-response-content {
    overflow: visible;
    min-height: 0;
    box-sizing: border-box;
}

/* 로딩 중일 때 "확인 중..." 글자를 보여주기 위한 팁 */
.dash-loading-callback::after {
    content: " 🔍 AI 에이전트가 확인 중입니다. 잠시만 기다려주세요...";
    font-size: 13px;
    color: #2563eb;
    display: block;
    margin-top: 10px;
    text-align: center;
}

/* 닫기 버튼: 헤더 안에서만 배치 (스크롤과 분리) */
#close-chat-btn {
    position: static;
    flex-shrink: 0;
}

/* 📱 모바일 (600px 이하) - 채팅바 inset만 보정 */
@media screen and (max-width: 600px) {
    .chat-bar {
        left: 0 !important;
        padding-left: 14px !important;
        padding-right: 14px !important;
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
        padding-top: 6px !important;
    }
}
