/* Chatbot Widget Styles */
#chatbot-widget {
    position: fixed;
    right: 20px;
    width: 380px;
    max-width: 90%;
    background-image: linear-gradient(to bottom right, #E5E4CA, #C3D8D8);
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    bottom: -500px;
    transition: all 0.3s ease;
    font-family: 'Noto Sans JP', sans-serif;
}

#chatbot-widget.active {
    opacity: 1;
    visibility: visible;
    bottom: 20px;
}

#chatbot-header {
    background-image: linear-gradient(to bottom right, #E5E4CA, #C3D8D8);
    color: #3D4951;
    padding: 5px 15px;
    display: flex;
    justify-content: center; /* これでh3が中央に */
    align-items: center;
    height: 50px;
    position: relative;
}

#chatbot-header h3 {
    margin: 0;
    font-size: 18px;
    font-family: "Jost", sans-serif;
    letter-spacing: 0.2rem;
    font-weight: 200;
}

#chatbot-close {
    background: none;
    border: none;
    color: #3D4951;
    font-size: 20px;
    cursor: pointer;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 7px;
}

#chatbot-messages {
    height: 400px;
    overflow-y: auto;
    padding: 15px;
    background-color: rgba(255, 255, 255, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
}

.chat-message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    flex-shrink: 0;
    margin: 0 0 10px 0;
}

.chat-message.user {
    align-self: flex-end;
    background-color: #C3D8D8;
    color: #3D4951;
    border-bottom-right-radius: 2px;
}

.chat-message.bot {
    align-self: flex-start;
    background-color: #e3e3e3;
    color: #3D4951;
    border-bottom-left-radius: 2px;
}

/* Source List Styling */
.chatbot-sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #ccc;
    font-size: 0.85em;
}

.source-title {
    margin: 0 0 5px 0;
    font-weight: bold;
    color: #555;
}

.chatbot-sources ul {
    margin: 0;
    padding-left: 20px;
    list-style-type: disc;
}

.chatbot-sources li {
    margin-bottom: 3px;
}

.chatbot-sources a {
    color: #007aff;
    text-decoration: none;
}

.chatbot-sources a:hover {
    text-decoration: underline;
}

#chatbot-input-area {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    box-sizing: border-box;
}

#chatbot-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    min-width: 0;
}

#chatbot-send {
    background: #3D4951;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    white-space: nowrap;
    flex-shrink: 0;
}

#chatbot-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Loading Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px;
    background: #e5e5ea;
    border-radius: 10px;
    align-self: flex-start;
    width: fit-content;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

@media (max-width: 767px) {
    #chatbot-widget {
        width: 94%;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        max-height: calc(var(--vh, 1vh) * 90);
        height: calc(var(--vh, 1vh) * 90);
    }

    #chatbot-messages {
        flex-grow: 1;
        height: auto;
        min-height: 100px;
        overflow-y: auto;
    }
}


/*
    ======================================
    🌙 ダークモード設定 (html.darkでライトモードを上書き)
    ======================================
*/

html.dark #chatbot-widget {
    /* 1. ウィジェット本体の背景 */
    background-image: linear-gradient(68deg, #41527B, #655E70); /* ご指定のグラデーション */
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5); /* 影を濃く */
}

/* 2. ヘッダー */
html.dark #chatbot-header {
    background-image: linear-gradient(68deg, #41527B, #655E70); /* 本体と同じグラデーション */
    color: #ffffff; /* 文字色を白に */
}

html.dark #chatbot-header h3 {
    color: #ffffff;
}

html.dark #chatbot-close {
    color: #ffffff;
}

html.dark #chatbot-messages {
    background-color: #8F91AA;
}

/* 4. メッセージ全体の文字色（ベース） */
html.dark .chat-message {
    color: #ffffff;
}

/* 5. 吹き出しの色設定 */
html.dark .chat-message.user {
    background-color: #58586e;
    color: #ffffff;
}

html.dark .chat-message.bot {
    background-color: #485575;
    color: #ffffff;
}

/* 6. ソースリスト（参照元） */
html.dark .chatbot-sources {
    border-top: 1px solid #777; /* 境界線を明るく */
}

html.dark .source-title {
    color: #cccccc; /* タイトルを明るいグレーに */
}

html.dark .chatbot-sources a {
    color: #4da6ff; /* リンク色をダークモードで映える明るい青に調整 */
}

/* 7. 入力エリア */
html.dark #chatbot-input-area {
    border-top: 1px solid #777;
    background-color: #58586e;
}

html.dark #chatbot-input {
    background: #44445c;
    border: 1px solid #777;
    color: #ffffff;
}

/* 8. 送信ボタン */
html.dark #chatbot-send {
    background: #706f91; /* 目立つ色（オレンジレッド）を適用 */
    color: #ffffff;
}

html.dark #chatbot-send:disabled {
    background: #666;
    color: #aaa;
}

/* 9. ローディングインジケータ */
html.dark .typing-indicator {
    background: #44445c; /* 入力フィールドと同じ色 */
}

html.dark .typing-indicator span {
    background: #ccc; /* ドットの色を明るく */
}