#chatbot {
    white-space: normal;
    word-break: normal;
    overflow-wrap: normal;
    line-height: normal;
    font-size: initial;
    font-family: sans-serif;
    margin: 0;
}

#chatbot .chat-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
    border: 4px solid #fff;
    z-index: 1000;
    overflow: visible !important;
}

#chatbot .chat-launcher img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

#chatbot .launcher-close-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ffffff;
    color: #312d2e;
    border: 2px solid #fff;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

#chatbot .chat-launcher.hidden {
    display: none;
}

#chatbot .bubble {
    position: fixed;
    right: 120px;
    bottom: 80px;
    background: #ffffff;
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.18);
    max-width: 220px;
    z-index: 999;
    color: #000000;
    cursor: pointer;
}

#chatbot .bubble.hidden {
    display: none;
}

#chatbot .chat-window {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 360px;
    height: 600px;
    max-height: calc(100vh - 40px);
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    z-index: 1001;
    transform: scale(0);
    transform-origin: bottom right;
    transition: transform 0.3s ease;
    /* キーボード高さのカスタムプロパティ（JavaScriptから設定） */
    --keyboard-height: 0px;
}

#chatbot .chat-window.open {
    transform: scale(1);
}

/* キーボード表示時のスタイル */
#chatbot .chat-window.keyboard-open {
    /* キーボード分だけ高さを減らす */
    max-height: calc(100vh - 40px - var(--keyboard-height));
}

#chatbot .chat-header {
    background: #3b82f6;
    color: #ffffff;
    padding: 16px;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

#chatbot .close-btn {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
}

#chatbot .chat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f7f7f7;
    /* iOS Safariでのスムーズスクロール */
    -webkit-overflow-scrolling: touch;
    /* スクロールバーのスタイリング */
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

#chatbot .chat-body::-webkit-scrollbar {
    width: 6px;
}

#chatbot .chat-body::-webkit-scrollbar-track {
    background: transparent;
}

#chatbot .chat-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

#chatbot .bot-msg {
    display: flex;
    align-items: flex-start;
    margin-bottom: 12px;
}

#chatbot .bot-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 10px;
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    color: #555;
    flex-shrink: 0;
}

#chatbot .bot-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#chatbot .bot-bubble {
    background: #3b82f6;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    max-width: 70%;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    white-space: pre-wrap;
    word-wrap: break-word;
}

#chatbot .user-msg {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

#chatbot .user-bubble {
    background: #ffffff;
    color: #000000;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    max-width: 70%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    white-space: pre-wrap;
    word-wrap: break-word;
}

#chatbot .chat-input-area {
    border-top: 1px solid #ddd;
    padding: 10px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}

#chatbot .chat-input-area textarea {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 8px;
    /* iOS Safariのネイティブ描画を無効化し、CSSのborderやstyleを正しく反映させる */
    -webkit-appearance: none;
    appearance: none;
    /* iOS Safariでのズーム防止 */
    font-size: 13px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    overflow: hidden;
    max-height: 100px;
    box-sizing: border-box;
}

#chatbot .chat-input-area button {
    padding: 10px 16px;
    background: #3b82f6;
    border: none;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}

#chatbot .chat-input-area button:hover {
    background: #2563eb;
}

#chatbot .powered-by {
    padding: 8px 16px;
    text-align: right;
    font-size: 11px;
    color: #999;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

#chatbot .logo-text {
    font-weight: 600;
    color: #3b82f6;
}

#chatbot .logo-image {
    height: 14px;
    vertical-align: middle;
    margin-left: 4px;
}

@media (max-width: 480px) {
    #chatbot .chat-window {
        right: 10px;
        bottom: 10px;
        left: 10px;
        width: auto;
        height: auto !important;
        top: 10px;
        max-height: none;
        border-radius: 12px;
    }

    /* キーボード表示時のスマホ対応 */
    #chatbot .chat-window.keyboard-open {
        /* キーボード表示時は下端をキーボードの上に配置 */
        bottom: calc(var(--keyboard-height));
        /* 上端は固定 */
        top: 10px;
    }

    #chatbot .chat-launcher {
        width: 65px;
        height: 65px;
        right: 15px;
        bottom: 15px;
    }

    #chatbot .bubble {
        right: 95px;
        bottom: 65px;
        max-width: 200px;
        font-size: 13px;
    }

    #chatbot .chat-header {
        padding: 12px 16px;
        font-size: 16px;
    }

    #chatbot .chat-body {
        padding: 12px;
    }

    #chatbot .bot-icon {
        width: 40px;
        height: 40px;
    }

    #chatbot .chat-input-area textarea {
        padding: 8px 12px;
        /* iOS Safariでズームを防ぐため16px以上必須 */
        font-size: 16px;
    }

    #chatbot .chat-input-area button {
        padding: 8px 12px;
        font-size: 14px;
    }
}

/* iPhone SE など小さい画面用 */
@media (max-width: 375px) and (max-height: 667px) {
    #chatbot .chat-window {
        top: 10px;
        bottom: 10px;
    }

    #chatbot .chat-window.keyboard-open {
        bottom: calc(var(--keyboard-height));
        top: 10px;
    }
}

/* 横向き対応 */
@media (orientation: landscape) and (max-height: 500px) {
    #chatbot .chat-window {
        top: 5px;
        bottom: 5px;
    }

    #chatbot .chat-window.keyboard-open {
        bottom: calc(var(--keyboard-height));
        top: 5px;
    }
}
