/* 사장님 상담 채팅 — 띄우는 버튼 + 대화 시트
   모바일에선 바닥에서 올라오는 시트, 데스크탑에선 우측 하단 카드. */

.cs-fab {
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    width: 56px; height: 56px;
    border-radius: 50%;
    border: 0; padding: 0;
    background: var(--accent, #7c3aed);
    color: #fff;
    display: grid; place-items: center;
    box-shadow: 0 6px 16px rgba(124, 58, 237, 0.42);
    z-index: 900;
    transition: transform 0.15s, box-shadow 0.15s;
}
.cs-fab:hover  { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(124, 58, 237, 0.5); }
.cs-fab:active { transform: scale(0.94); }
.cs-fab svg { width: 24px; height: 24px; fill: currentColor; }
/* 시트·검색이 열리면 숨긴다(rules 6.4) — cs.js가 data-cs-hide를 보고 붙인다 */
.cs-fab.cs-hide { display: none; }
/* 답장이 왔을 때만 뜨는 점 — 숫자까지 붙이면 시선을 너무 뺏는다 */
.cs-fab .dot {
    position: absolute; top: 4px; right: 4px;
    width: 12px; height: 12px; border-radius: 50%;
    background: #fbbf24; border: 2px solid #fff;
    display: none;
}
.cs-fab.has-new .dot { display: block; }

.cs-sheet {
    position: fixed;
    right: 16px;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    width: 360px;
    max-height: min(560px, calc(100vh - 140px));
    background: var(--surface, #ffffff);
    border: 1px solid var(--line, #e5e8eb);
    border-radius: 20px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 901;
    box-shadow: var(--shadow-pop, 0 12px 32px rgba(25,31,40,0.14));
}
.cs-sheet.open { display: flex; }

.cs-head {
    display: flex; align-items: center; justify-content: space-between;
    gap:8px; padding:16px;
    border-bottom: 1px solid var(--line, #e5e8eb);
}
.cs-head h3 { margin:0; font-size:15px; font-weight: 700; letter-spacing: -0.01em; }
.cs-head p  { margin:4px 0 0; font-size:12px; color: var(--muted, #4e5968); }
.cs-close {
    width: 44px; height: 44px; margin: -8px -8px -8px 0;
    padding: 0; background: transparent; border: 0; color: var(--muted, #4e5968);
    font-size:22px; line-height: 1; border-radius: 12px;
}
.cs-close:hover { background: var(--surface-2, #f2f4f6); color: var(--text, #191f28); }

/* 담당자가 이어받은 상태 — AI가 왜 조용한지 사장님이 알아야 한다 */
.cs-banner {
    display: none;
    padding:8px 16px;
    font-size:13px;
    color: var(--accent-text, #7c3aed);
    background: rgba(124, 58, 237, 0.1);
    border-bottom: 1px solid var(--line, #e5e8eb);
}
.cs-sheet.escalated .cs-banner { display: block; }

.cs-body {
    flex: 1; overflow-y: auto;
    padding:16px;
    display: flex; flex-direction: column; gap:8px;
    -webkit-overflow-scrolling: touch;
}

.cs-msg {
    max-width: 84%;
    padding:8px 16px;
    border-radius: 14px;
    font-size:14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.cs-msg.user  { align-self: flex-end; background: var(--accent, #7c3aed); color: #fff; border-bottom-right-radius: 5px; }
.cs-msg.ai    { align-self: flex-start; background: var(--surface-2, #f2f4f6); color: var(--text, #191f28); border-bottom-left-radius: 5px; }
.cs-msg.admin { align-self: flex-start; background: var(--surface-2, #f2f4f6); color: var(--text, #191f28); border-bottom-left-radius: 5px; border: 1px solid var(--accent-text, #7c3aed); }
.cs-msg .who  { display: block; font-size:12px; color: var(--muted, #4e5968); margin-bottom:4px; }

/* 상태 4종 */
.cs-state { margin: auto 0; text-align: center; padding:24px 8px; }
.cs-state p  { margin:0 0 8px; font-size:14px; color: var(--text, #191f28); }
.cs-state small { display: block; font-size:13px; color: var(--muted, #4e5968); line-height: 1.6; }
.cs-state button {
    margin-top:16px; min-height: 44px; padding:0 16px;
    border-radius: 999px; border: 1px solid var(--line, #e5e8eb);
    background: var(--surface-2, #f2f4f6); color: var(--text, #191f28); font-size:14px; font-weight: 600;
}
.cs-skel { height: 40px; border-radius: 14px; background: var(--surface-2, #f2f4f6); opacity: 0.5; animation: cs-pulse 1.3s ease-in-out infinite; }
.cs-skel:nth-child(2) { width: 60%; align-self: flex-end; }
.cs-skel:nth-child(3) { width: 76%; }
@keyframes cs-pulse { 0%, 100% { opacity: 0.5 } 50% { opacity: 0.22 } }

/* 예시 질문 — 빈 화면에서 뭘 물어야 할지 막막하지 않게 */
.cs-chips { display: flex; flex-wrap: wrap; gap:8px; justify-content: center; margin-top:16px; }
.cs-chips button {
    min-height: 44px; padding:0 16px; margin:0;
    border-radius: 999px; border: 1px solid var(--line, #e5e8eb);
    background: transparent; color: var(--muted, #4e5968); font-size:13px;
}
.cs-chips button:hover { color: var(--text, #191f28); border-color: var(--accent-text, #7c3aed); }

.cs-foot { display: flex; gap:8px; padding:16px; border-top: 1px solid var(--line, #e5e8eb); }
.cs-foot textarea {
    flex: 1; min-height: 44px; max-height: 110px;
    padding:8px 16px; resize: none;
    background: var(--surface-2, #f2f4f6); border: 1px solid var(--line, #e5e8eb); border-radius: 12px;
    color: var(--text, #191f28); font-family: inherit; font-size:14px; line-height: 1.45;
}
.cs-foot textarea:focus { outline: none; border-color: var(--accent-text, #7c3aed); }
.cs-foot button {
    width: 44px; height: 44px; flex-shrink: 0;
    border-radius: 12px; border: 0; padding: 0;
    background: var(--accent, #7c3aed); color: #fff;
    display: grid; place-items: center;
}
.cs-foot button:disabled { opacity: 0.4; }
.cs-foot button svg { width: 18px; height: 18px; fill: currentColor; }

@media (max-width: 600px) {
    .cs-sheet {
        right: 0; left: 0; bottom: 0;
        width: auto;
        max-height: 82vh;
        border-radius: 20px 20px 0 0;
        border-left: 0; border-right: 0; border-bottom: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* 랜딩: 넓은 화면에서만 말풍선(오른쪽 아래 24). 모바일은 하단 상담 바 [채팅 상담]이 시트를 연다 */
body[data-cs-fab="pc"] .cs-fab { right: 24px; bottom: 24px; }
@media (min-width: 1024px) { body[data-cs-fab="pc"] .cs-sheet { right: 24px; bottom: 96px; } }
@media (max-width: 1023px) { body[data-cs-fab="pc"] .cs-fab { display: none; } }
/* 고객지원: 카드의 [상담 시작]이 시트를 연다 — 시안(1026:2576)에 말풍선 없음 */
body[data-cs-fab="none"] .cs-fab { display: none; }

/* 스켈레톤 깜빡임도 동작 줄이기 설정을 따른다 */
@media (prefers-reduced-motion: reduce) {
    .cs-skel { animation: none; opacity: 0.4; }
    .cs-fab, .cs-fab:hover, .cs-fab:active { transition: none; transform: none; }
}
