/* ===== AIチャットウィジェット ===== */

#chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
}

/* 開くボタン */
#chat-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #1a1a1a;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
#chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0,0,0,0.32);
}
#chat-toggle svg { transition: opacity 0.2s; }
#chat-toggle .icon-open { opacity: 1; }
#chat-toggle .icon-close { opacity: 0; position: absolute; }
#chat-widget.open #chat-toggle .icon-open { opacity: 0; }
#chat-widget.open #chat-toggle .icon-close { opacity: 1; }

/* バッジ */
#chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #e04b4b;
  border-radius: 50%;
  border: 2px solid #f5f4f0;
  animation: chatPulse 2s infinite;
}
@keyframes chatPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* チャットパネル */
#chat-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 340px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.92) translateY(12px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s;
}
#chat-widget.open #chat-panel {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* スマホ：画面全体 */
@media (max-width: 480px) {
  #chat-widget {
    bottom: 16px;
    right: 16px;
  }
  #chat-panel {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    width: auto;
    border-radius: 16px;
    transform: scale(0.92) translateY(12px);
    transform-origin: bottom right;
  }
  #chat-widget.open #chat-panel {
    transform: scale(1) translateY(0);
  }
}

/* ヘッダー */
#chat-header {
  background: #1a1a1a;
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: chatBlink 2s infinite;
  flex-shrink: 0;
}
@keyframes chatBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
#chat-header h3 { font-size: 0.9rem; font-weight: 600; }
#chat-header p { font-size: 0.72rem; color: #aaa; margin-top: 1px; }

/* スマホの閉じるボタン */
#chat-close-sp {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
@media (max-width: 480px) {
  #chat-close-sp { display: flex; }
}

/* メッセージエリア */
#chat-messages {
  flex: 1;
  height: 320px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafafa;
}
@media (max-width: 480px) {
  #chat-messages {
    height: auto;
    flex: 1;
  }
}
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* メッセージバブル */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.55;
  animation: chatFadeUp 0.25s ease;
  white-space: pre-wrap;
}
@keyframes chatFadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.ai {
  background: #fff;
  border: 1px solid #e8e8e8;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  color: #1a1a1a;
}
.chat-msg.user {
  background: #1a1a1a;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* タイピングインジケーター */
.chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #e8e8e8;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}
.chat-typing-dot {
  width: 6px;
  height: 6px;
  background: #bbb;
  border-radius: 50%;
  animation: chatTypingBounce 1.2s infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatTypingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* 入力エリア */
#chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #eee;
  background: #fff;
  align-items: flex-end;
}
@media (max-width: 480px) {
  #chat-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
#chat-input {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 38px;
  transition: border-color 0.2s;
  line-height: 1.4;
  background: #fafafa;
}
#chat-input:focus { border-color: #1a1a1a; background: #fff; }
#chat-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #1a1a1a;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
#chat-send:hover { background: #333; }
#chat-send:disabled { background: #ccc; cursor: not-allowed; }

/* フッター */
#chat-footer {
  text-align: center;
  font-size: 0.68rem;
  color: #bbb;
  padding: 6px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
}
/* PC：上に戻るボタンと重ならないよう位置調整 */
@media screen and (min-width: 801px) {
  #chat-widget {
    bottom: 80px;
  }
}