/* 基本設定 */
body {
    font-family: 'Roboto', sans-serif;
    background-color: #121212;
    color: #FFFFFF;
    margin: 0;
    padding-top: 60px;
    height: 100%;
    overflow: hidden;
}

html {
    height: 100%;
}

/* ヘッダー */
header {
  /* ヘッダーのレイアウト */
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 60px; /* 高さは任意 */
  background-color: #1F1F1F;
  display: flex;
  justify-content: space-between; /* 左にロゴ、右にメニュー */
  align-items: center;
  z-index: 999;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
  /* padding は適宜 */
  padding: 0 20px;
}

/* ロゴやタイトル */
header .logo {
  display: flex;
  gap: 10px;
  color: #E0E0E0;
}

header .logo .main-title {
    font-size: 1.5em;
    font-weight: bold;
    color: #E0E0E0;
}

header .logo .sub-title {
    font-size: 0.9em;
    font-weight: 400;
    color: #B0B0B0;
}

header nav {
    position: absolute; 
    top: 60px;   /* ヘッダーの下に表示 (60pxはヘッダーの高さ) */
    left: 0;
    width: 100%;
    background-color: #1F1F1F; /* or #333 等 */
    display: none;            /* 初期は非表示 */
    flex-direction: column;
    gap: 10px;
    padding: 10px 20px;
}

/* メニューアイコン */
.menu-toggle {
  position: fixed;
  top: 10px;
  right: 10px;
  color: #CB6847;
  font-size: 24px;
  z-index: 9999;
  padding: 8px;
  border-radius: 4px;
}

.nav-menu.open {
  display: flex;
}

header nav a {
    text-decoration: none;
    color: #E0E0E0;
    font-weight: 500;
    transition: color 0.3s;
}

header nav a:hover {
    color: #FFD700;
}

/* メインコンテナ */
main {
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(100% - 60px);
    overflow: hidden;
}

.chat-container {
    background-color: #1F1F1F;
    width: 100%;
    max-width: 600px;
    height: 90%;
    max-height: calc(100vh - 40px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #333333;
}

.chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    max-height: 100%;
    background-color: #332E29;
    border-radius: 8px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.message {
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 20px;
    max-width: 80%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user {
    background-color: #CB6847;
    color: #FFFFFF;
    align-self: flex-end;
}

.message.bot {
    position: relative; /* ボタンを絶対配置するため */
    background-color: #333333;
    color: #E0E0E0;
    align-self: flex-start;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* 返答文の右下に音声読み上げボタンを重ねる */
.text-to-audio-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background-color: #555;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px;
    cursor: pointer;
    font-size: 0.9em;
    opacity: 0.8;
}

.text-to-audio-btn:hover {
    opacity: 1;
}

/* 入力エリア */
.chat-input {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background-color: #1F1F1F;
    border-top: 1px solid #333;
}

.chat-input button {
    background-color: #CB6847;
    color: #FFFFFF;
    border: none;
    padding: 10px;
    cursor: pointer;
    border-radius: 5px;
}

/* 従来の input[type="text"] と同様のスタイルを textarea に適用 */
.chat-input textarea {
    font-size: 16px;
    flex: 1;
    padding: 10px;
    background-color: #1F1F1F;
    color: #E0E0E0;
    border: 1px solid #333;
    border-radius: 5px;
    resize: none;           /* ユーザーによるリサイズを無効化 */
    height: 40px;           /* 従来の高さに近い大きさに合わせる */
    box-sizing: border-box; /* パディング含めた計算に */
    line-height: 1.4;       /* 好みに応じて微調整 */
    overflow-y: auto;       /* 内容が多い場合にスクロール */
    scrollbar-color: #666 #222;
    scrollbar-width: thin;
}

.chat-input textarea::-webkit-scrollbar {
  width: 8px;               /* スクロールバーの幅 */
  background-color: #222;   /* トラックの背景色(余白部分) */
}

.chat-input textarea::-webkit-scrollbar-thumb {
  background-color: #666;   /* スクロールバーつまみ部分 */
  border-radius: 4px;
}

.chat-input textarea::-webkit-scrollbar-thumb:hover {
  background-color: #888;   /* ホバー時 */
}

.chat-input textarea::-webkit-scrollbar-corner {
  background-color: #222;   /* スクロールバー角部分 */
}

/* フッター */
footer {
    background-color: #1F1F1F;
    padding: 10px 20px;
    text-align: center;
    color: #E0E0E0;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.5);
}

/* ボタンエリア */
.button-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    border-top: 1px solid #333333;
    background-color: #1F1F1F;
    gap: 10px;
}

.button-controls button,
.audio-label {
    background-color: #007BFF;
    color: #FFFFFF;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    text-align: center;
}

.button-controls button:hover,
.audio-label:hover {
    background-color: #0056b3;
}

.recording-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 10px 0;
}

.recording-controls button {
    background-color: #007BFF;
    color: white;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 1em;
    border-radius: 5px;
}

.recording-controls button:hover {
    background-color: #0056b3;
}

.recording-controls button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

/* ファイルアップロード用モーダル */
.modal-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0,0,0,0.5);
  z-index: 2000;
}

/* モーダル本体 */
.modal-content {
  position: relative; /* 相対位置を指定して、閉じるボタンを絶対配置 */
  background: #FFFFFF;
  color: #333333;
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  animation: popupFadeIn 0.3s ease-in-out;
  text-align: left;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 1.2em;
}

.modal-content input[type="file"] {
    display: block;
    margin: 0 auto 20px auto;
}

.modal-buttons {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.modal-buttons button {
    background-color: #007BFF;
    color: #FFFFFF;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    flex: 1;
    font-size: 1em;
}

.modal-buttons button:hover {
    background-color: #0056b3;
}

/* 右上の閉じるボタン */
.modal-close-button {
  position: absolute;
  top: 10px;
  right: 15px;
  background: transparent; /* 背景なし */
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #000; /* ボタンの色を指定 */
}

.modal-close-button:hover {
  color: #666; /* ホバー時に少し色を変えるなど */
}

/* ポップアップ */
.popup-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.popup {
    position: relative;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 20px;
    max-width: 500px;
    width: 80%;
    text-align: center;
    z-index: 1001;
    animation: popupFadeIn 0.3s ease-in-out;
}

#popup-text {
    font-size: 16px;
    color: #333333;
    margin-bottom: 20px;
}

.close-popup {
    background-color: #007BFF;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.close-popup:hover {
    background-color: #0056b3;
}

/* ファイル詳細用モーダルのベース: 画面全体にかぶせる */
.file-detail-modal-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center; 
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 2000; 
}

.file-detail-modal-content {
  position: relative; /* 子要素を絶対配置するため */
  background: #fff;
  color: #333;
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;         /* 長いときにスクロール */
  overflow-y: auto;         /* 縦スクロール有効 */
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  animation: popupFadeIn 0.3s ease-in-out;
}

/* バツボタン */
.detail-close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #000; /* ダーク文字色 */
  cursor: pointer;
}

.detail-close-button:hover {
  color: #888; /* ホバー時の色変化 */
}


/* テキスト部分 (必要に応じて装飾) */
.file-detail-text {
    white-space: pre-wrap; /* 改行などを反映する場合 */
    line-height: 1.4;
}

/* ボタンが読み込み中のとき（.loading） */
#send-button.loading {
  opacity: 0.7;         /* 半透明 */
  cursor: not-allowed;  /* カーソルを禁止アイコン */
  position: relative;
}

/* ボタンにspinnerを差し込む簡易例 */
#send-button.loading::after {
  content: "";
  border: 3px solid #ccc;
  border-top: 3px solid #007bff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  animation: spin 0.8s linear infinite;
  display: block;
  position: absolute;
  right: 10px; 
  top: 50%;
  transform: translateY(-50%);
}

/* スピナー */
.spinner {
  border: 3px solid #f3f3f3;     /* 薄い枠 */
  border-top: 3px solid #007bff; /* 上部分を強調色に */
  border-radius: 50%;
  width: 16px;
  height: 16px;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  position: absolute;
  right: 10px;    /* ボタン内の右側に配置 */
  top: 50%;
  transform: translateY(-50%);
}

/* 3つのドットでTyping...を表現 */
.typing-indicator {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  padding: 10px 15px;
  border-radius: 20px;
  background-color: #333333; /* botメッセージ背景色 */
  color: #E0E0E0;
  margin-bottom: 15px;
  max-width: 80%;
  word-wrap: break-word;
  align-self: flex-start;
}

.bot-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #fff;
  animation: botTyping 1s infinite ease-in-out;
  display: inline-block;
}

.bot-typing-dot:nth-child(1) { animation-delay: 0s; }
.bot-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.bot-typing-dot:nth-child(3) { animation-delay: 0.4s; }

#record-button.loading {
  opacity: 0.7;
  cursor: not-allowed;
  position: relative;
}

#record-button.loading::after {
  content: "";
  border: 3px solid #f3f3f3;
  border-top: 3px solid red; /* 録音用に赤色とか */
  border-radius: 50%;
  width: 16px;
  height: 16px;
  animation: spin 0.8s linear infinite;
  display: block;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}

.suggested-questions {
  padding: 10px;
  background: #2f2f2f;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.suggested-questions button {
  background: #444;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
}
.suggested-questions button:hover {
  background: #666;
}

/* アニメーション */
@keyframes popupFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes spin {
  0% { transform: translateY(-50%) rotate(0deg); }
  100% { transform: translateY(-50%) rotate(360deg); }
}

@keyframes botTyping {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* レスポンシブ */
@media (max-width: 768px) {
    header nav {
        display: none;
    }

    header .menu-toggle {
        display: block;
        cursor: pointer;
    }

    .chat-container {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
}
