/* 권선동성당 AI 도우미 챗봇 위젯 */
#chatbot-widget-root {
    position: fixed;
    z-index: 9999;
    right: 1.25rem;
    bottom: 1.25rem;
    font-family: 'Noto Sans KR', sans-serif;
}
#chatbot-widget-root * { box-sizing: border-box; }
#chatbot-widget-root.resizing { user-select: none; }

/* ---- 토글 버튼 (AI 상담) ---- */
.cbw-toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1.2rem 0.55rem 0.6rem;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--ai-card-color-1, #4a433d) 0%, var(--ai-card-color-2, #c5a880) 100%);
    color: #fff;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.cbw-toggle-btn:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32);
}
#chatbot-widget-root.open .cbw-toggle-btn {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.85);
}

.cbw-toggle-icon {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.cbw-toggle-icon svg { width: 25px; height: 25px; }
.cbw-toggle-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.55);
    animation: cbwPulse 2.6s ease-out infinite;
    pointer-events: none;
}
@keyframes cbwPulse {
    0% { transform: scale(1); opacity: 0.7; }
    70%, 100% { transform: scale(1.65); opacity: 0; }
}

.cbw-toggle-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    line-height: 1.3;
}
.cbw-toggle-text strong { font-size: 0.95rem; font-weight: 800; letter-spacing: 0.02em; }
.cbw-toggle-text small { font-size: 0.68rem; font-weight: 500; opacity: 0.85; }

/* 아이콘 색상 (말풍선 + 반짝임) */
.cbw-toggle-icon .cbw-icon-bubble { fill: #fff; }
.cbw-toggle-icon .cbw-icon-spark { fill: var(--ai-card-color-1, #7d6242); }
.cbw-avatar .cbw-icon-bubble,
.cbw-msg-avatar .cbw-icon-bubble { fill: var(--accent-gold, #c5a880); }
.cbw-avatar .cbw-icon-spark,
.cbw-msg-avatar .cbw-icon-spark { fill: #fff; }

/* ---- 챗봇 창 ---- */
.cbw-window {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 370px;
    height: 560px;
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 3rem);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.28);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color, rgba(197, 168, 128, 0.35));
}
.cbw-window.open { display: flex; animation: cbwOpen 0.22s ease-out; }
@keyframes cbwOpen {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to { opacity: 1; transform: none; }
}
.cbw-window.maximized {
    width: min(760px, calc(100vw - 2.5rem)) !important;
    height: calc(100vh - 3rem) !important;
}

/* 크기 조절 핸들 (좌측 상단) */
.cbw-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 28px;
    height: 28px;
    z-index: 5;
    cursor: nwse-resize;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.65);
    border-top-left-radius: 18px;
}
.cbw-resize-handle:hover { color: #fff; }
.cbw-resize-handle svg { width: 13px; height: 13px; }
.cbw-window.maximized .cbw-resize-handle { display: none; }

/* ---- 헤더 ---- */
.cbw-header {
    background: linear-gradient(135deg, var(--ai-card-color-1, #4a433d) 0%, var(--ai-card-color-2, #c5a880) 100%);
    color: #fff;
    padding: 0.85rem 0.9rem 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
}
.cbw-header-info {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}
.cbw-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.cbw-avatar svg { width: 22px; height: 22px; }
.cbw-header-texts { min-width: 0; }
.cbw-header-title {
    font-size: 0.95rem;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cbw-header-sub {
    font-size: 0.7rem;
    opacity: 0.9;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 0.32rem;
    white-space: nowrap;
    overflow: hidden;
}
.cbw-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #7ef29b;
    box-shadow: 0 0 6px rgba(126, 242, 155, 0.9);
    flex-shrink: 0;
}
.cbw-header-actions { display: flex; gap: 0.15rem; flex-shrink: 0; }
.cbw-icon-btn {
    background: transparent;
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.cbw-icon-btn:hover { background: rgba(255, 255, 255, 0.18); }
.cbw-icon-btn svg { width: 16px; height: 16px; }

/* ---- 메시지 영역 ---- */
.cbw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    background: #f7f5f1;
}

.cbw-row { display: flex; align-items: flex-end; gap: 0.45rem; }
.cbw-row.user { justify-content: flex-end; }
.cbw-msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #e9e1d3;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.cbw-msg-avatar svg { width: 15px; height: 15px; }

.cbw-msg {
    max-width: 82%;
    padding: 0.62rem 0.9rem;
    border-radius: 14px;
    font-size: 0.87rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.cbw-msg.user {
    background: linear-gradient(135deg, var(--accent-gold, #c5a880), var(--accent-gold-hover, #b08d5e));
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 6px rgba(var(--accent-gold-rgb, 176, 141, 94), 0.3);
}
.cbw-msg.bot {
    background: #fff;
    color: var(--text-primary, #4a433d);
    border: 1px solid #ece5d8;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.cbw-msg.bot.error { border-color: #fc8181; color: #c53030; background: #fff5f5; }

/* 타이핑 인디케이터 */
.cbw-typing { display: flex; align-items: center; gap: 4px; padding: 0.8rem 0.9rem; }
.cbw-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-gold, #c0ab8b);
    animation: cbwBlink 1.2s infinite;
}
.cbw-typing span:nth-child(2) { animation-delay: 0.2s; }
.cbw-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cbwBlink {
    0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* ---- 입력 영역 ---- */
.cbw-input-area {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.7rem 0.75rem;
    padding-bottom: calc(0.7rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #ece5d8;
    background: #fff;
    flex-shrink: 0;
}
.cbw-input {
    flex: 1;
    border: 1px solid #ddd3c2;
    border-radius: 22px;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    background: #faf8f5;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.cbw-input:focus {
    outline: none;
    border-color: var(--accent-gold, #c5a880);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(var(--accent-gold-rgb, 197, 168, 128), 0.15);
}
.cbw-send-btn {
    background: linear-gradient(135deg, var(--accent-gold, #c5a880), var(--accent-gold-hover, #a8865a));
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, opacity 0.15s ease;
}
.cbw-send-btn svg { width: 18px; height: 18px; margin-left: 2px; }
.cbw-send-btn:hover:not(:disabled) { transform: scale(1.07); }
.cbw-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- 모바일: 하단 시트 레이아웃 ---- */
@media (max-width: 640px) {
    #chatbot-widget-root { right: 0.9rem; bottom: 0.9rem; }

    .cbw-toggle-btn { padding: 0.5rem 1.05rem 0.5rem 0.55rem; }
    .cbw-toggle-icon { width: 38px; height: 38px; }
    .cbw-toggle-text small { display: none; }

    .cbw-window {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        max-width: 100%;
        height: min(88vh, 640px) !important;
        height: min(88dvh, 640px) !important;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 20px 20px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }
    .cbw-window.maximized {
        height: 100vh !important;
        height: 100dvh !important;
        border-radius: 0;
    }
    .cbw-resize-handle { display: none; }
    .cbw-header { padding-left: 1.1rem; }

    /* iOS 포커스 시 자동 확대 방지 */
    .cbw-input { font-size: 16px; }
}
