/* Hiro AI Chatbot widget styles */

/* --- Chat launcher --- */
#hai-chat-launcher {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 12vw;
  max-width: 80px;
  height: 12vw;
  max-height: 80px;
  filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.1));
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.2s ease-in-out;
  z-index: 9998;
}
#hai-chat-launcher:hover {
  transform: scale(1.1);
}
#hai-chat-launcher img {
  width: 100%;
}

/* --- Chat container --- */
#hai-chat-container {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 90vw;
  max-width: 380px;
  height: 70vh;
  max-height: 650px;
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
  transform-origin: bottom right;
  opacity: 0;
  transform: scale(0.95) translateY(10px);
  visibility: hidden;
  z-index: 9999;
  padding-bottom: 5px;
}
#hai-chat-container.open {
  opacity: 1;
  transform: scale(1) translateY(0);
  visibility: visible;
}

/* Input area */
#hai-input-area {
  padding: 2vw;
  border-bottom: 1px solid #eee;
}
#hai-input-area form {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1vw;
  margin: 0;
}
#hai-message-input {
  width: 100%;
  min-height: 8vh;
  max-height: 16vh;
  box-sizing: border-box;
  overflow-y: auto;
  resize: none;
  border: 2px solid #f8b0c0;
  border-radius: 16px;
  padding: 10px 15px;
  font-size: min(20px, 4vw);
  font-family: inherit;
  line-height: 1.3;
  outline: none;
  transition: border-color 0.2s;
  background: #fff;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}
#hai-message-input::-webkit-scrollbar {
  display: none;
}

#hai-send-button {
  background-color: #f8b0c0;
  color: white;
  border: none;
  border-radius: 16px;
  padding: 0 28px;
  font-size: min(22px, 4vw);
  font-weight: bold;
  cursor: pointer;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
#hai-send-button:hover {
  background-color: #f48ca5;
}

/* Messages area */
#hai-messages-area {
  flex-grow: 1;
  overflow-y: auto;
  padding: 2vw;
  position: relative;
}
.hai-message-wrapper {
  display: flex;
  margin-bottom: 20px;
}
.hai-user-message-wrapper {
  justify-content: flex-end;
}
.hai-bot-message-wrapper {
  justify-content: flex-start;
  position: relative;
}

.hai-message {
  padding: 15px;
  border-radius: 18px;
  max-width: 85%;
  line-height: 1.5;
  font-size: 16px;
  font-weight: 400;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}
.hai-message,
.hai-message p,
.hai-message span {
  word-break: normal !important;
  overflow-wrap: break-word !important;
  white-space: pre-wrap !important;
}
.hai-user-message {
  background-color: #fde8ed;
  color: #333;
}
.hai-bot-message {
  background-color: #fff;
  color: #333;
  border: 2px solid #f8b0c0;
  position: relative;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
}
.hai-bot-message::after {
  content: '';
  position: absolute;
  bottom: -12px;
  right: 20px;
  width: 0;
  height: 0;
  border: 12px solid transparent;
  border-top-color: #f8b0c0;
  border-bottom: 0;
  border-right: 0;
}
.hai-bot-message::before {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 22px;
  width: 0;
  height: 0;
  border: 10px solid transparent;
  border-top-color: #fff;
  border-bottom: 0;
  border-right: 0;
  z-index: 1;
}

/* Typing indicator */
.hai-typing-indicator {
  display: flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  gap: 4px;
  justify-content: flex-start;
}
.hai-typing-dot {
  width: 8px;
  height: 8px;
  background: #888;
  border-radius: 50%;
  opacity: 0.6;
  animation: hai-typing-bounce 1.2s infinite;
}
.hai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.hai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes hai-typing-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.6; }
  40% { transform: scale(1); opacity: 1; }
}

/* Source links */
.hai-source-links {
  margin-top: 12px;
  display: inline-flex !important;
  overflow-x: auto;
  white-space: nowrap;
  padding-bottom: 2px;
  scrollbar-width: thin;
  flex-wrap: nowrap;
  gap: 10px;
  min-width: 0;
  width: 100%;
}
.hai-source-links a {
  display: inline-flex !important;
  white-space: nowrap !important;
  color: #f48ca5;
  text-decoration: underline;
  font-size: 12px;
  background: #fff;
  border: 1px solid #f8b0c0;
  border-radius: 8px;
  padding: 2px 10px;
  margin-bottom: 0;
  flex-shrink: 0;
}

/* Scroll to bottom button */
#hai-scroll-to-bottom {
  position: fixed !important;
  bottom: 115px;
  right: 20px;
  width: 35px;
  height: 35px;
  background-color: #f8b0c0;
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(248, 176, 192, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10000;
}
#hai-scroll-to-bottom.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
#hai-scroll-to-bottom:hover {
  background-color: #f48ca5;
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(244, 140, 165, 0.4);
}
#hai-scroll-to-bottom svg {
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

@media (min-width: 768px) and (max-width: 1024px) {
  #hai-chat-container { width: 98vw; bottom: 70px; right: 1.5vw; height: 58vh; }
  #hai-message-input { font-size: 18px; min-height: 60px; max-height: 120px; }
  #hai-send-button { font-size: 16px; padding: 0 20px; height: 45px; }
  #hai-chat-launcher { width: 55px; height: 55px; }
  #hai-messages-area { padding: 1.5vw; }
}
@media (min-width: 481px) and (max-width: 767px) {
  #hai-chat-container { width: 98vw; bottom: 75px; right: 1.5vw; height: 55vh; }
  #hai-message-input { font-size: 16px; min-height: 60px; max-height: 120px; }
  #hai-send-button { font-size: 16px; padding: 0 20px; height: 45px; }
  #hai-chat-launcher { width: 50px; height: 50px; }
  #hai-messages-area { padding: 1.5vw; }
}
@media (max-width: 767px) {
  #hai-chat-launcher { position: relative; inset: 3px 6px auto auto; }
}
@media (max-width: 400px) {
  #hai-chat-launcher { position: fixed; inset: 90px 10px auto auto; }
  #hai-chat-container { bottom: auto; top: 150px; }
}
@media (max-width: 480px) {
  #hai-chat-container { width: 100vw; bottom: 75px; right: 1vw; height: 55vh; }
  #hai-message-input { font-size: 15px; min-height: 60px; max-height: 120px; }
  #hai-send-button { font-size: 14px; padding: 0 20px; height: 45px; }
  #hai-chat-launcher { width: 50px; height: 50px; }
  #hai-messages-area { padding: 1.5vw; }
  .hai-message.hai-bot-message { font-size: 15px; }
}

/* ===== チャットランチャーを追従CTAの上・右下に固定 2026-08-06 =====
   従来の問題:
     - max-width:767px で position:relative になり、401〜767px の端末では
       ページ最下部に流し込まれて画面上に出てこなかった（SPで表示されない原因）
     - max-width:400px では inset:90px 10px auto auto で右上に出ていた（右下が意図）
     - PC/タブレットでは bottom:20px で下部の追従CTAに重なっていた
   変更: 全幅で右下固定にし、追従CTA（約73px）の上に重ならないよう配置する */

/* --- ベース（PC・タブレット） --- */
#hai-chat-launcher {
  bottom: 90px;                   /* 追従CTA（約73px）の上 */
}
#hai-chat-container {
  bottom: 180px;                  /* ランチャー（最大80px）の上に開く */
}

/* --- スマホ全域 --- */
@media (max-width: 767px) {
  #hai-chat-launcher {
    position: fixed;
    inset: auto 12px 88px auto;   /* 右12px／下88px */
    width: 54px;
    height: 54px;
    max-width: none;
    max-height: none;
    z-index: 9998;
  }
  #hai-chat-container {
    top: auto;
    bottom: 150px;                /* ランチャー（54px）の上 */
    height: min(56vh, 440px);
  }
}
@media (max-width: 480px) {
  #hai-chat-container {
    width: 94vw;
    right: 3vw;
    bottom: 150px;
  }
}
@media (max-width: 400px) {
  #hai-chat-launcher {
    position: fixed;
    inset: auto 10px 84px auto;
    width: 50px;
    height: 50px;
  }
  #hai-chat-container {
    top: auto;
    bottom: 144px;
    height: min(54vh, 400px);
  }
}

/* ===== ランチャーを監修医（岡院長）の写真に変更 2026-08-06 =====
   従来のSVGアイコンは #f7b0c0 主体で薄く、背景に埋もれて気づかれにくかった。
   写真＋濃いピンク(#e5548a)の枠に変更し、下部CTAと色を揃える。 */
#hai-chat-launcher{
  background:#fff;
  border:3px solid #e5548a;
  border-radius:50%;
  box-shadow:0 3px 10px rgba(0,0,0,.22);
  overflow:visible;
  padding:0;
  box-sizing:border-box;
}
#hai-chat-launcher img{
  width:100%;
  height:100%;
  border-radius:50%;
  object-fit:cover;
  display:block;
}
#hai-chat-launcher .hai-launcher-label{
  position:absolute;
  left:50%;
  bottom:-9px;
  transform:translateX(-50%);
  background:#e5548a;
  color:#fff;
  font-size:10px;
  font-weight:700;
  line-height:1;
  padding:3px 8px;
  border-radius:9px;
  white-space:nowrap;
  letter-spacing:.02em;
  box-shadow:0 1px 3px rgba(0,0,0,.2);
}
@media (max-width:400px){
  #hai-chat-launcher .hai-launcher-label{font-size:9px;padding:2px 6px;bottom:-8px}
}

/* ===== ときどき小さく揺れて存在に気づいてもらう 2026-08-06 =====
   9秒に1回、約1.3秒だけ左右に傾く。妊婦さん向けサイトのため振れ幅は控えめにし、
   ホバー中・チャットを開いている間・OS側で「視差を減らす」設定の場合は動かさない。 */
@keyframes hai-attention {
  0%   { transform: rotate(0deg) scale(1); }
  4%   { transform: rotate(-13deg) scale(1.06); }
  8%   { transform: rotate(11deg) scale(1.06); }
  12%  { transform: rotate(-10deg) scale(1.05); }
  16%  { transform: rotate(9deg) scale(1.04); }
  20%  { transform: rotate(-7deg) scale(1.03); }
  24%  { transform: rotate(5deg) scale(1.02); }
  28%  { transform: rotate(-3deg) scale(1.01); }
  32%  { transform: rotate(1deg) scale(1); }
  36%, 100% { transform: rotate(0deg) scale(1); }
}
@media (prefers-reduced-motion: no-preference) {
  #hai-chat-launcher {
    animation: hai-attention 6s ease-in-out 1.2s infinite;
    transform-origin: 50% 60%;
    will-change: transform;
  }
}
/* ホバー中は既存の拡大表示を優先 */
#hai-chat-launcher:hover { animation: none; }
/* チャットを開いている間は揺らさない（コンテナはランチャーより前にあるので一般兄弟で指定） */
#hai-chat-container.open ~ #hai-chat-launcher { animation: none; }
