/* ==========================================
   AI Chat Widget
   ========================================== */

/* Bubble Button */
#chat-bubble {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #005c97, #0077b6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 92, 151, 0.4);
    z-index: 9998;
    transition: all 0.3s ease;
    animation: chat-pulse 3s ease-in-out infinite;
}

#chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 28px rgba(0, 92, 151, 0.5);
}

#chat-bubble.active {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

@keyframes chat-pulse {
    0%, 100% { box-shadow: 0 6px 20px rgba(0, 92, 151, 0.4); }
    50% { box-shadow: 0 6px 20px rgba(0, 92, 151, 0.4), 0 0 0 12px rgba(0, 92, 151, 0.08); }
}

#chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 22px;
    height: 22px;
    background: #f39800;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 900;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* Chat Window */
#chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: 1.25rem;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.5);
    transform-origin: bottom right;
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#chat-window.open {
    transform: scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* Header */
#chat-header {
    background: linear-gradient(135deg, #005c97, #0077b6);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

#chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 900;
    letter-spacing: 0.05em;
}

#chat-header-title {
    font-size: 0.95rem;
    font-weight: 700;
}

#chat-header-status {
    font-size: 0.72rem;
    opacity: 0.8;
}

#chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.6rem;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

#chat-close:hover {
    background: rgba(255,255,255,0.15);
}

/* Messages */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #f7f8fa;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

.chat-msg {
    display: flex;
    max-width: 85%;
    animation: msg-in 0.3s ease-out;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg.bot {
    align-self: flex-start;
}

.chat-msg-bubble {
    padding: 12px 16px;
    border-radius: 1rem;
    font-size: 0.88rem;
    line-height: 1.7;
    word-break: break-word;
}

.chat-msg.bot .chat-msg-bubble {
    background: #fff;
    color: #374151;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.chat-msg.user .chat-msg-bubble {
    background: linear-gradient(135deg, #005c97, #0077b6);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Typing dots */
.typing-dots {
    display: flex;
    gap: 5px;
    padding: 4px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: dot-bounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
#chat-input-area {
    padding: 14px 16px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
    background: #fff;
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 0.88rem;
    font-family: 'Noto Sans JP', sans-serif;
    outline: none;
    transition: border-color 0.2s;
    color: #222;
}

#chat-input:focus {
    border-color: #005c97;
    box-shadow: 0 0 0 3px rgba(0, 92, 151, 0.1);
}

#chat-input::placeholder {
    color: #9ca3af;
}

#chat-send {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, #005c97, #0077b6);
    border: none;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

#chat-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 92, 151, 0.3);
}

#chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Mobile */
@media (max-width: 480px) {
    #chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 120px);
        bottom: 8px;
        right: 8px;
        border-radius: 1rem;
    }
    #chat-bubble {
        bottom: 80px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
}


/* Popup Message */
#chat-popup-msg {
    position: fixed;
    bottom: 118px;
    right: 96px;
    background: #fff;
    color: #374151;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.6;
    padding: 14px 36px 14px 18px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    border: 1px solid #e5e7eb;
    z-index: 9997;
    animation: popup-in 0.5s ease-out 1.5s both;
    white-space: nowrap;
}



#chat-popup-close {
    position: absolute;
    top: 4px;
    right: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    color: #9ca3af;
    line-height: 1;
    padding: 4px;
}

#chat-popup-close:hover {
    color: #374151;
}

@keyframes popup-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 480px) {
    #chat-popup-msg {
        bottom: 98px;
        right: 16px;
        font-size: 0.82rem;
    }
}
