/* チャットアイコンのスタイル */
.qa-chat-icon {
   position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #007bff; /* 青色の背景 */
    color: white;
    /* width: 60px; /* ★削除またはコメントアウト */
    /* height: 60px; /* ★削除またはコメントアウト */
    border-radius: 00%; /* 円形にする */
    display: flex; /* ★追加: テキストを中央揃えにするためにflexを使用 */
    justify-content: center; /* ★追加: 水平方向中央揃え */
    align-items: center; /* ★追加: 垂直方向中央揃え */
    font-size: 0.9em; /* ★調整: 文字サイズを少し小さく */
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    padding: 10px 15px; /* ★調整: パディングでボタンサイズを調整 */
    line-height: 1; /* ★追加: 行の高さを1に設定してテキストのずれを抑える */
    min-width: 120px; /* ★追加: ボタンの最小幅を設定 (テキストが収まるように) */
    text-align: center; /* ★削除: flex使用のため不要 */
    animation: pulse 2s infinite, float 2s ease-in-out infinite, colorChange 5s linear infinite;
}

@keyframes float {
  0% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
  100% { transform: translateY(0); }
}

@keyframes colorChange {
  0% { background-color: #a85700; }  /* 緑 */
  50% { background-color: #007bff; } /* 青 */
  100% { background-color: #a85700;} /* 緑に戻る */
}

.qa-chat-icon.qa-hidden-icon {
    display: none;
}

.qa-chat-icon:hover {
    transform: scale(1.05);
}

/* アイコン非表示用のクラス */
.qa-hidden-icon {
    opacity: 0;
    pointer-events: none; /* クリックイベントを無効化 */
    transform: scale(0.5); /* 小さくして消えるアニメーション */
}

/* チャットコンテナのスタイル */
.qa-container {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    width: 100%;
    max-width: 380px; /* PCでの最大幅を調整 */
    height: min(550px, 80vh); /* ★修正: 画面の高さに応じて調整 */
    max-height: 80vh; /* ★追加: 最大高さを画面の80%に制限 */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* 右下固定表示 */
    position: fixed;
    bottom: 90px; /* アイコンの上に来るように調整 */
    right: 20px;
    z-index: 999; /* アイコンより下にする（アイコンがクリックのトリガーなので） */

    background-color: #ffffff;
    transform: scale(1); /* 初期表示アニメーション用 */
    transform-origin: bottom right; /* 拡大縮小の基準点を右下にする */
    transition: transform 0.3s ease-out, opacity 0.3s ease-out; /* 表示/非表示のアニメーション */
    opacity: 1;
}

/* 非表示状態 */
.qa-hidden {
    transform: scale(0.5); /* 縮小して非表示 */
    opacity: 0;
    pointer-events: none; /* クリックイベントを無効化 */
}

/* ヘッダー部分 */
.qa-chat-header {
    background-color: #007bff;
    color: white;
    padding: 15px;
    font-size: 1.1em;
    font-weight: bold;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* ★追加: ヘッダーは固定サイズを保つ */
}

.qa-close-button {
    background: none;
    border: none;
    font-size: 1.5em; /* 少し大きくして押しやすく */
    color: #333; /* ★重要: 色を濃いグレーに変更して見えるようにする */
    cursor: pointer;
    padding: 0 8px; /* パディングを調整 */
    line-height: 1; /* テキストの縦位置調整 */
}

.qa-close-button:hover {
    color: #c6c6c6;
}

.qa-header {
    display: flex; /* ヘッダー内要素の配置調整のため追加 */
    justify-content: space-between; /* タイトルと閉じるボタンを両端に配置 */
    align-items: center; /* 垂直方向中央揃え */
    padding: 10px 15px;
    background-color: #f1f1f1;
    border-bottom: 1px solid #ccc;
    border-radius: 8px 8px 0 0;
    flex-shrink: 0; /* ヘッダーは固定サイズを保つ */
}

/* チャットメッセージ表示エリア */
.qa-chat-box {
    flex: 1; /* 利用可能な残りのスペースをすべて使う */
    padding: 15px;
    overflow-y: auto;
    background-color: #f9f9f9;
    border-bottom: 1px solid #eee;
    display: flex;
    flex-direction: column; /* メッセージを縦に並べる */
    min-height: 0; /* flexアイテムの最小高さを制限 */
}

/* 個々のメッセージ要素 */
.qa-message {
    margin-bottom: 10px;
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 85%;
    word-wrap: break-word;
    font-size: 0.95em;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    color: #000000; /* ★追加: 文字色を黒に設定 */
}

/* ユーザーからのメッセージ */
.qa-message.qa-user {
    background-color: #e1fce0;
    align-self: flex-end;
    margin-left: auto; /* 右寄せ */
    border-bottom-right-radius: 4px; /* 角を少しだけ直角に */
    color: #000000; /* ★追加: ユーザーメッセージの文字色を黒に設定 */
}

/* システムからのメッセージ */
.qa-message.qa-system {
    background-color: #d2eeff;
    padding: 10px 15px; /* ★調整: パディングを少し増やす */
    border-radius: 18px 18px 18px 3px; /* 角を調整 */
    align-self: flex-start; /* ★重要: コンテナ内で左寄せにする */
    max-width: 75%; /* ★追加: 最大幅を設定して長いテキストの折り返しを制御 */
    word-wrap: break-word; /* ★追加: 長い単語でも折り返す */
    text-align: left; /* テキストを左寄せ */
    color: #000000; /* ★追加: システムメッセージの文字色を黒に設定 */
}

/* 推奨質問コンテナ */
.qa-recommended-questions-container {
    padding: 12px;
    border-top: 1px solid #eee;
    background-color: #f9f9f9;
    display: none; /* 初期状態では非表示 */
    flex-wrap: wrap;
    gap: 8px;
    min-height: 40px; /* 最小高さを確保 */
    max-height: 100px; /* 最大高さを制限 */
    overflow-y: auto;
    flex-shrink: 0; /* コンテナ内で縮まないようにする */
}

/* 推奨質問ボタン */
.qa-recommended-button {
    background-color: #4472a3;
    color: white;
    border: none;
    padding: 8px 12px; /* パディングを増やしてボタンを大きく */
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 32px; /* 最小高さを設定 */
}

.qa-recommended-button:hover {
    background-color: #49747a;
    transform: translateY(-1px);
}

.qa-recommended-button:active {
    background-color: #80deea;
    transform: translateY(0);
}

/* ファジー検索候補コンテナ */
.qa-fuzzy-suggestions-container {
    padding: 12px;
    border-top: 1px solid #eee;
    background-color: #f0f0f0;
    display: none; /* 初期状態では非表示 */
    flex-wrap: wrap;
    gap: 8px;
    min-height: 40px; /* 最小高さを確保 */
    max-height: 100px; /* 最大高さを制限 */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0; /* コンテナ内で縮まないようにする */
}

/* ファジー検索候補ボタン */
.qa-fuzzy-suggestion-button {
    background-color: #207a9b;
    color: #ffffff;
    border: none;
    padding: 8px 12px; /* パディングを増やしてボタンを大きく */
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 32px; /* 最小高さを設定 */
}

.qa-fuzzy-suggestion-button:hover {
    background-color: #bbdefb;
    transform: translateY(-1px);
}

.qa-fuzzy-suggestion-button:active {
    background-color: #90caf9;
    transform: translateY(0);
}

/* 入力エリア */
.qa-input-area {
    display: flex; /* ★重要: Flexboxを使用 */
    padding: 12px;
    border-top: 1px solid #ccc;
    background-color: #f9f9f9;
    align-items: center; /* 垂直方向中央揃え */
    gap: 10px; /* 要素間の隙間 */
    flex-shrink: 0; /* 入力エリアは固定サイズを保つ */
}

/* ユーザー入力フォーム */
.qa-user-input {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid #ccc;
    border-radius: 25px;
    font-size: 1em;
    outline: none; /* フォーカス時のアウトラインを消す */
    transition: border-color 0.2s;
}

.qa-user-input:focus {
    border-color: #007bff;
}

/* 送信ボタン */
.qa-send-button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s, transform 0.1s;
    white-space: nowrap; /* ボタン内のテキストが改行されないように */
    flex-shrink: 0; /* ボタンは縮まないようにする */
}

.qa-send-button:hover {
    background-color: #0056b3;
}

.qa-send-button:active {
    transform: scale(0.98);
}

/* IDセレクタでの追加スタイル（JSで動的に作成される要素用） */
#qa-container {
    display: flex;
    flex-direction: column; /* 縦方向に要素を並べる */
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: min(550px, 80vh); /* ★修正: 画面の高さに応じて調整 */
    max-height: 80vh; /* ★追加: 最大高さを画面の80%に制限 */
    background-color: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    z-index: 999;
    overflow: hidden; /* スクロールバーを内側で管理 */
}

#qa-recommended-questions {
    display: none; /* 初期状態は非表示 */
    flex-wrap: wrap; /* ボタンが複数ある場合に折り返す */
    gap: 8px; /* ボタン間のスペース */
    padding: 12px;
    border-top: 1px solid #eee;
    background-color: #f9f9f9;
    min-height: 50px; /* 最小高さを確保 */
    max-height: 120px; /* 最大高さを制限 */
    overflow-y: auto;
    border-radius: 5px;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
    z-index: 9;
    position: relative;
    flex-shrink: 0; /* コンテナ内で縮まないようにする */
}

#qa-fuzzy-suggestions {
    display: none; /* 初期状態は非表示 */
    flex-wrap: wrap; /* ボタンが複数ある場合に折り返す */
    gap: 8px; /* ボタン間のスペース */
    padding: 12px;
    border-top: 1px solid #eee;
    background-color: #f0f0f0;
    min-height: 50px; /* 最小高さを確保 */
    max-height: 120px; /* 最大高さを制限 */
    overflow-y: auto;
    border-radius: 5px;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
    z-index: 10;
    position: relative;
    flex-shrink: 0; /* コンテナ内で縮まないようにする */
}

/* ローディングドットアニメーション */
.qa-loading-dots::after {
    content: '...';
    display: inline-block;
    width: 0;
    overflow: hidden;
    animation: typing-dots 1.5s infinite steps(4, end);
}

@keyframes typing-dots {
    0% { width: 0; }
    25% { width: .5em; }
    50% { width: 1em; }
    75% { width: 1.5em; }
    100% { width: 0; }
}

/* クリック可能なキーワードのスタイル */
.qa-link-keyword {
    color: #258eff; /* リンクの色 */
    text-decoration: underline; /* 下線 */
    cursor: pointer; /* カーソルをポインターに */
    font-weight: bold; /* 太字に */
    transition: color 0.2s;
}

.qa-link-keyword:hover {
    color: #004997; /* ホバー時の色 */
}

/* スクロールバーのスタイル */
.qa-recommended-questions-container::-webkit-scrollbar,
.qa-fuzzy-suggestions-container::-webkit-scrollbar,
#qa-recommended-questions::-webkit-scrollbar,
#qa-fuzzy-suggestions::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.qa-recommended-questions-container::-webkit-scrollbar-track,
.qa-fuzzy-suggestions-container::-webkit-scrollbar-track,
#qa-recommended-questions::-webkit-scrollbar-track,
#qa-fuzzy-suggestions::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.qa-recommended-questions-container::-webkit-scrollbar-thumb,
.qa-fuzzy-suggestions-container::-webkit-scrollbar-thumb,
#qa-recommended-questions::-webkit-scrollbar-thumb,
#qa-fuzzy-suggestions::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.qa-recommended-questions-container::-webkit-scrollbar-thumb:hover,
.qa-fuzzy-suggestions-container::-webkit-scrollbar-thumb:hover,
#qa-recommended-questions::-webkit-scrollbar-thumb:hover,
#qa-fuzzy-suggestions::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ★追加: 中型画面（ノートパソコン）用のメディアクエリ */
@media (max-width: 1366px) and (min-width: 769px) {
    .qa-container, #qa-container {
        height: min(480px, 75vh); /* ★修正: ノートパソコンでは高さを少し小さく */
        max-height: 75vh; /* ★追加: 最大高さを画面の75%に制限 */
        bottom: 80px; /* ★修正: 下からの距離を少し詰める */
    }
    
    .qa-chat-header {
        padding: 12px; /* ★修正: ヘッダーのパディングを少し小さく */
        font-size: 1.05em; /* ★修正: フォントサイズを少し小さく */
    }
    
    .qa-message {
        padding: 8px 12px; /* ★修正: メッセージのパディングを少し小さく */
        font-size: 0.9em; /* ★修正: フォントサイズを少し小さく */
    }
    
    .qa-input-area {
        padding: 10px; /* ★修正: 入力エリアのパディングを少し小さく */
    }
    
    .qa-recommended-questions-container,
    .qa-fuzzy-suggestions-container,
    #qa-recommended-questions,
    #qa-fuzzy-suggestions {
        max-height: 80px; /* ★修正: 最大高さを少し小さく */
    }
}

/* ★追加: 小型ノートパソコン（11-13インチ）用のメディアクエリ */
@media (max-width: 1024px) and (min-width: 769px) {
    .qa-container, #qa-container {
        height: min(400px, 70vh); /* ★修正: 小型ノートパソコンではさらに高さを小さく */
        max-height: 70vh; /* ★追加: 最大高さを画面の70%に制限 */
        bottom: 70px; /* ★修正: 下からの距離をさらに詰める */
    }
}

/* レスポンシブ対応（スマートフォン） */
@media (max-width: 768px) {
    .qa-container, #qa-container {
        /* スマホでは画面いっぱいに表示 */
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        max-width: none;
        width: 100%;
        height: 100%;
        max-height: 100vh; /* ★追加: スマホでは画面いっぱい */
        border-radius: 0;
        box-shadow: none;
    }
    
    .qa-chat-icon {
        /* スマホでチャットが開いている時にアイコンが重ならないように */
        bottom: 15px; /* スマホでは少し下からの距離を詰める */
        right: 15px; /* スマホでは少し右からの距離を詰める */
        font-size: 0.9em; /* 文字サイズを小さく */
        padding: 8px 12px; /* パディングを小さくしてボタンサイズ全体を小さく */
        min-width: 60px; /* 最小幅も小さく */
    }
    
    .qa-recommended-questions-container,
    .qa-fuzzy-suggestions-container,
    #qa-recommended-questions,
    #qa-fuzzy-suggestions {
        min-height: 60px; /* スマホでは高さを少し大きく */
        max-height: 140px;
    }
}