/* チャットウィジェット */
.chat-widget-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #ffffff;
    /* 白背景に変更 */
    background-image: url('../img/ai_chat_icon_v3.png');
    /* 生成したアイコンパス */
    background-size: cover;
    /* アイコンサイズリセット */
    background-position: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 2px solid #ffd700;
    /* ピックムーイエロー */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.chat-widget-btn:hover {
    transform: scale(1.05);
    /* background-color: var(--color-emerald-700); */
    /* 背景色ホバーはアイコンで不要 */
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    /* ホバー時の影を強調 */
}

.chat-widget-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 350px;
    height: 500px;
    max-height: 80vh;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    transform-origin: bottom right;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
}

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

.chat-header {
    background: linear-gradient(135deg, #065f46 0%, #059669 100%);
    /* Stylish Emerald Gradient */
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-title {
    font-weight: bold;
    font-size: 1rem;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.bot {
    align-self: flex-start;
    background-color: white;
    color: #333;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.message.user {
    align-self: flex-end;
    background-color: var(--color-emerald-600);
    color: white;
    border-bottom-right-radius: 4px;
}

.typing-indicator {
    align-self: flex-start;
    background-color: #e5e7eb;
    padding: 8px 12px;
    border-radius: 18px;
    font-size: 0.8rem;
    color: #666;
    display: none;
}

.chat-input-area {
    padding: 10px;
    border-top: 1px solid #e5e7eb;
    background-color: white;
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    outline: none;
    font-size: 0.9rem;
}

.chat-input:focus {
    border-color: var(--color-emerald-600);
}

.chat-send-btn {
    background-color: var(--color-emerald-800);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s;
    flex-shrink: 0;
    /* Prevent button from vanishing on small screens */
}

.chat-send-btn:hover {
    background-color: var(--color-emerald-700);
}

.chat-send-btn:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
}

/* Mobile responsivness */
@media (max-width: 480px) {
    .chat-widget-window {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        /* Fallback for browsers that don't support dvh */
        height: 100dvh;
        /* Dynamic viewport height */
        max-height: 100dvh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        /* Ensure padding doesn't affect width */
    }

    .chat-header {
        border-radius: 0;
        flex-shrink: 0;
        /* Prevent header from shrinking */
    }

    .chat-messages {
        flex: 1;
        /* Takes up remaining space */
        overflow-y: auto;
    }

    .chat-input-area {
        flex-shrink: 0;
        /* Prevent input area from shrinking */
        padding-bottom: env(safe-area-inset-bottom, 20px);
        /* Safe area for iPhone home bar */
    }
}