/* リセットとベーススタイル */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Roboto", "Helvetica", "Arial", sans-serif;
  background-color: #f5f5f5;
  color: #333;
}

/* チャットボットコンテナ */
#chatbot-container {
  position: fixed;
  bottom: 40px;
  right: 30px;
  z-index: 1000;
}

/* スマホ対応 */
@media (max-width: 768px) {
  #chatbot-container {
    bottom: 80px;
    right: 20px;
  }
}

/* チャットウィンドウ */
.chat-window {
  position: absolute;
  right: 0;
  bottom: 80px;
  width: 480px;
  height: 650px;
  margin-bottom: 16px;
  opacity: 1;
  transform: scale(1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.hidden {
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
}

/* スマホでのチャットウィンドウ */
@media (max-width: 768px) {
  .chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    margin: 0;
    z-index: 1001;
  }
}

/* チャットペーパー */
.chat-paper {
  width: 100%;
  height: 100%;
  background: white;
  border-radius: 8px;
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.16),
    0 3px 6px rgba(0, 0, 0, 0.23);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (max-width: 768px) {
  .chat-paper {
    border-radius: 0;
  }
}

.chat-title {
  font-size: 1.25rem;
  font-weight: 500;
  margin: 0;
}

.close-button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s;
}

.close-button:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.close-button .material-icons {
  font-size: 24px;
}

/* メッセージコンテナ */
.messages-container {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background-color: #f5f5f5;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-item.bot {
  align-items: start;
}

.message-item.user {
  align-items: start;
}

.message-bubble {
  max-width: 100%;
  padding: 12px;
  border-radius: 8px;
  position: relative;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.8;
}

@media (max-width: 768px) {
  .message-bubble {
    font-size: 14px;
  }
}

.message-bubble.bot {
  background-color: white;
  color: #333;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ボットメッセージ内のマークダウンスタイル */
.message-bubble.bot a {
  color: #1976d2;
  text-decoration: underline;
  word-break: break-all;
}

.message-bubble.bot a:hover {
  color: #1565c0;
}

.message-bubble.bot p {
  margin: 0 0 8px 0;
}

.message-bubble.bot p:last-child {
  margin-bottom: 0;
}

.message-bubble.bot ul,
.message-bubble.bot ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-bubble.bot li {
  margin: 4px 0;
}

.message-bubble.bot code {
  background-color: #f5f5f5;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Roboto Mono", monospace;
  font-size: 0.9em;
}

.message-bubble.bot pre {
  background-color: #f5f5f5;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-bubble.bot pre code {
  background-color: transparent;
  padding: 0;
}

.message-bubble.bot strong {
  font-weight: 600;
}

.message-bubble.bot h1,
.message-bubble.bot h2,
.message-bubble.bot h3,
.message-bubble.bot h4,
.message-bubble.bot h5,
.message-bubble.bot h6 {
  margin: 12px 0 8px 0;
  font-weight: 600;
}

.message-bubble.bot h1:first-child,
.message-bubble.bot h2:first-child,
.message-bubble.bot h3:first-child {
  margin-top: 0;
}

.message-bubble.user {
  background-color: #1976d2;
  color: white;
}

.message-timestamp {
  font-size: 0.75rem;
  color: #666;
  margin-top: 8px;
}

/* ストリーミングアニメーション */
.streaming-text {
  background: linear-gradient(-45deg, #666, #999, #ccc, #999, #666);
  background-size: 400% 400%;
  animation: gradientShift 2s ease-in-out infinite;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  font-weight: bold;
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* 入力エリア */
.chat-input-container {
  padding: 16px;
  background-color: white;
  border-top: 1px solid #e0e0e0;
}

.input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

.message-input {
  flex: 1;
  padding: 16px 10px;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  border-radius: 20px;
  background-color: #f5f5f5;
}

.message-input:focus {
  border-color: #28a5a0;
}

.message-input:disabled {
  background-color: #f5f5f5;
  color: #999;
}

.send-button {
  padding: 12px;
  background-color: #28a5a0;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s;
  min-width: 48px;
  border-radius: 100%;
  min-height: 48px;
}

.send-button:hover:not(:disabled) {
  background-color: #1565c0;
}

.send-button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.send-button .material-icons {
  font-size: 20px;
}

/* チャットFAB */
.chat-fab {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: #28a5a0;
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.16),
    0 3px 6px rgba(0, 0, 0, 0.23);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-fab:hover {
  background-color: #1565c0;
  box-shadow:
    0 6px 12px rgba(0, 0, 0, 0.2),
    0 6px 12px rgba(0, 0, 0, 0.28);
}

.chat-fab .material-icons {
  font-size: 32px;
}

@media (max-width: 768px) {
  .chat-fab {
    width: 56px;
    height: 56px;
  }

  .chat-fab .material-icons {
    font-size: 24px;
  }
}

/* ユーティリティクラス */
.hidden {
  display: none !important;
}

/* スクロールバーのスタイリング */
.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.messages-container::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
  background: #a1a1a1;
}

/* 画面全体を中央寄せ */
html,
body {
  height: 100%;
}
body {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

/* 既存のポップアップ前提の配置を潰す */
#chatbot-container {
  position: static !important;
  inset: auto !important;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  #chatbot-container {
    padding: 40px 16px 32px 16px;
  }
}

/* チャットを常時表示用のカードに */
#chat-window {
  position: static !important;
  width: 100%;
  max-width: 700px;
  height: 85vh;
  max-height: 95vh;
  display: block;
}

.chat-paper {
  height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  background: #fff;
}

/* ヘッダーをMUIっぽく */
.chat-header {
  padding: 20px;
  text-align: center;
  color: #fff;
  background: #28a5a0;
}
.chat-title {
  margin: 0;
  font-size: 1.1rem;
}

/* メッセージ領域を伸縮 */
.messages-container {
  flex: 1;
  overflow: auto;
  background: #f6f6f6;
  background-image: url(https://www.transparenttextures.com/patterns/cubes.png);
}

/* 入力エリア */
.chat-input-container {
  padding: 16px;
  background: #fff;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.03);
}

.message-item {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin: 14px 0;
}

.message-item.user {
  flex-direction: row-reverse;
}

.message-content {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.message-avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: #fff;
  flex: 0 0 auto;
  box-shadow:
    0px 3px 1px -2px rgba(0, 0, 0, 0.2),
    0px 2px 2px 0px rgba(0, 0, 0, 0.14),
    0px 1px 5px 0px rgba(0, 0, 0, 0.12);
}
.message-avatar.bot {
  background: #39b2a0;
}
.message-avatar.user {
  background: #7c83c9;
}

.message-bubble {
  border-radius: 20px;
  padding: 12px 14px;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.message-bubble.bot {
  background: #fff;
  color: #111;
}
.message-bubble.user {
  background: #1976d2;
  color: #fff;
}

.message-timestamp {
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.75;
}
.message-item.user .message-timestamp {
  text-align: right;
}

.message-bubble {
  white-space: pre-wrap;
}
