/* 基本設定 */
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: 0 20px;
  box-sizing: border-box;
}

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-actions {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-left: auto;
}

.icon-button {
    background: none;
    border: none;
    color: #CB6847;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
}

.icon-button:hover {
    color: #E08E70;
}

header nav {
    position: absolute; 
    top: 60px;
    left: 0;
    width: 100%;
    background-color: #1F1F1F;
    display: none;
    flex-direction: column;
    gap: 10px;
    padding: 10px 20px;
}

.menu-toggle {
  color: #CB6847;
  font-size: 24px;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
}

.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(100vh - 60px);
  padding-top: 60px;
  box-sizing: border-box;
  overflow: hidden;
}

/* アバター+チャット統合コンテナ */
.avatar-chat-container {
  background-color: #1F1F1F;
  width: 100%;
  max-width: 600px;
  height: 90%;
  max-height: calc(100vh - 80px);
  margin: 10px auto;
  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;
}

/* アバター動画コンテナ */
.avatar-container {
  width: 100%;
  height: 55%;
  background-color: #000;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#avatar-video {
  width: 100%;
  height: auto;
  object-fit: contain;
  background-color: #000;
}

/* 現在の会話表示エリア */
.current-conversation {
  flex-grow: 1;
  padding: 15px;
  overflow-y: auto;
  background-color: #332E29;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.current-message {
  padding: 10px 15px;
  border-radius: 20px;
  max-width: 90%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.current-message.user {
    background-color: #CB6847;
    color: #FFFFFF;
    align-self: flex-end;
}

.current-message.bot {
    position: relative;
    background-color: #333333;
    color: #E0E0E0;
    align-self: flex-start;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.current-message p {
    margin: 0;
}

/* 会話履歴モーダル */
.history-modal-content {
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
}

.chat-messages {
    max-height: calc(70vh - 60px);
    overflow-y: auto;
    padding: 15px;
    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;
    margin-left: auto;
}

.message.bot {
    position: relative;
    background-color: #333333;
    color: #E0E0E0;
    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;
}

.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;
}

/* 引用表示 */
.citation {
    margin-top: 5px;
    padding: 5px 10px;
    background-color: rgba(0, 0, 0, 0.3);
    border-left: 3px solid #CB6847;
    font-size: 0.9em;
    border-radius: 0 5px 5px 0;
}

/* ファイルアップロード用モーダル */
.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: #1F1F1F;
  color: #E0E0E0;
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
  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;
    color: #E0E0E0;
}

.modal-content input[type="file"] {
    display: block;
    margin: 0 auto 20px auto;
    color: #E0E0E0;
}

.modal-buttons {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.modal-buttons button {
    background-color: #CB6847;
    color: #FFFFFF;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    flex: 1;
    font-size: 1em;
}

.modal-buttons button:hover {
    background-color: #D5805F;
}

.modal-close-button {
  position: absolute;
  top: 10px;
  right: 15px;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #E0E0E0;
}

.modal-close-button:hover {
  color: #FFF;
}

.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: #1F1F1F;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    padding: 20px;
    max-width: 500px;
    width: 80%;
    text-align: center;
    z-index: 1001;
    animation: popupFadeIn 0.3s ease-in-out;
    color: #E0E0E0;
}

#popup-text {
    font-size: 16px;
    margin-bottom: 20px;
}

.close-popup {
    background-color: #CB6847;
    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: #D5805F;
}

/* チャット入力欄の下部固定など、スマホ向けの調整 */
@media (max-width: 768px) {
  .avatar-container {
    width: 100%;
    height: auto;
  }
  
  #avatar-video {
    width: 100%;
    height: auto;
    object-fit: cover;
  }
  
  .chat-input {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 999;
  }
  
  main {
    padding-bottom: 70px;
  }
}

/* アニメーション */
@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); }
}
