:root {
  --chat-primary: #0f766e; /* 各カスタマーのテーマカラーが上書きされる */
  --chat-user-bg: var(--chat-primary);
  --chat-user-text: #ffffff;
  --chat-ai-bg: #f3f4f6;
  --chat-ai-text: #111827;
}

/* --- 全体レイアウト --- */
body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #e0f2fe, #f8fafc);
}

.chat-shell {
  width: min(960px, 100% - 2rem);
}

.chat-card {
  background: var(--pico-card-background-color, #ffffff);
  border-radius: 1.5rem;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.15);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 90vh;
}

/* --- ヘッダー --- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.chat-icon {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: linear-gradient(135deg, var(--chat-primary), #0ea5e9);
  color: #fff;
}

.chat-title {
  margin: 0;
}

.chat-title a {
  color: var(--chat-primary);
  text-decoration: none;
}

.chat-title a:hover {
  text-decoration: underline;
}

/* --- チャット履歴エリア --- */
#chat-history {
  flex: 1;
  min-height: 260px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 1rem;
  border-radius: 1rem;
  background: rgba(148, 163, 184, 0.12);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* --- 各メッセージ --- */
.user-message,
.ai-response {
  margin-bottom: 0.2rem;
  padding: 0.6rem 0.8rem;
  border-radius: 0.75rem;
  word-wrap: break-word;
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ユーザー: 右寄せ */
.user-message {
  align-self: flex-end;
  max-width: 80%;
  background-color: var(--chat-user-bg);
  color: var(--chat-user-text);
  border-bottom-right-radius: 0.3rem;
}

/* AI: 横幅いっぱい近くまで */
.ai-response {
  align-self: stretch;
  max-width: 100%;
  background-color: var(--chat-ai-bg);
  color: var(--chat-ai-text);
  border-bottom-left-radius: 0.3rem;
}

/* ラベル */
.user-message strong,
.ai-response strong {
  font-size: 0.8rem;
  opacity: 0.8;
  display: block;
  margin-bottom: 0.2rem;
}

/* --- 入力フォームエリア --- */
.chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chat-input-row {
  display: block;
}

.chat-textarea {
  width: 100%;
  resize: none;
  min-height: 60px;
  max-height: 160px;
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
  line-height: 1.5;
  border-radius: 0.8rem;
  border: 1px solid var(--pico-muted-border-color, #d1d5db);
  background: var(--pico-card-background-color, #fff);
  color: var(--pico-color, #111);
}

.chat-textarea:focus {
  outline: none;
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--chat-primary) 30%, transparent);
}

/* --- ローディングインジケータ --- */
.htmx-indicator {
  opacity: 0;
  visibility: hidden;
  font-size: 0.85rem;
  color: #6b7280;
  margin-top: 0.25rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* リクエスト中は表示 */
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
  visibility: visible;
}

/* タイピング風ドット */
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #9ca3af;
  animation: typing 1s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.2;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* --- スマホ調整 --- */
@media (max-width: 640px) {
  .chat-card {
    border-radius: 1rem;
    padding: 1rem;
  }

  .chat-textarea {
    font-size: 0.95rem;
  }
}
