/**
 * 自社チャットボットのUI
 *
 * 配色はテーマの既存トークンに合わせる。#1FAB89 はテーマCSSで241回使われている
 * サイトの主色（ロゴの緑）、#EDF5F4 は本文まわりの淡い背景色。独自の色を持ち込むと
 * 「あとから貼った別サービス」に見えるため、サイトの色をそのまま使う。
 *
 * 位置は右下。下部にはテーマの追従CTA（.fixedFooter・黄色帯・z-index 999）が
 * スクロールで出入りするため、bottom は JS が実測して動的に上げ下げする
 * （chatbot.js の adjustBottom）。ここでは初期値だけ持つ。
 */

.sfq-chat-launcher,
.sfq-chat-panel {
  --sfq-green: #1fab89;
  --sfq-green-dark: #17957a;
  --sfq-green-deep: #0f7d64;
  --sfq-mist: #edf5f4;
  --sfq-line: #d3e6e2;
  --sfq-ink: #17302b;
  --sfq-ink-2: #4a6b64;
}

/* ── ランチャー ───────────────────────────────── */

.sfq-chat-launcher {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 13px 20px 13px 16px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #23c09a 0%, var(--sfq-green) 55%, var(--sfq-green-deep) 100%);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(31, 171, 137, .42), 0 2px 6px rgba(0, 0, 0, .12);
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s ease;
}

.sfq-chat-launcher:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 28px rgba(31, 171, 137, .5), 0 3px 8px rgba(0, 0, 0, .14);
}

.sfq-chat-launcher:active {
  transform: translateY(-1px) scale(.99);
}

.sfq-chat-launcher:focus-visible {
  outline: 3px solid var(--sfq-green-deep);
  outline-offset: 3px;
}

.sfq-chat-launcher .sfq-chat-icon {
  width: 22px;
  height: 22px;
  flex: none;
}

/* 初回だけ軽く弾ませて存在を知らせる（3回で止める） */
.sfq-chat-launcher.is-intro {
  animation: sfq-chat-pop .9s ease 3;
}

@keyframes sfq-chat-pop {
  0%, 70%, 100% { transform: translateY(0); }
  35% { transform: translateY(-6px); }
}

/* ランチャー横の吹き出し（初回のみ・数秒で消える） */
.sfq-chat-tip {
  position: fixed;
  right: 16px;
  z-index: 9997;
  max-width: 210px;
  padding: 10px 14px;
  border-radius: 12px 12px 4px 12px;
  background: #fff;
  color: var(--sfq-ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .16);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .35s ease, transform .35s ease;
  pointer-events: none;
}

.sfq-chat-tip.is-on {
  opacity: 1;
  transform: translateY(0);
}

.sfq-chat-tip::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: -7px;
  border-width: 8px 7px 0 0;
  border-style: solid;
  border-color: #fff transparent transparent transparent;
}

.sfq-chat-launcher[hidden],
.sfq-chat-panel[hidden],
.sfq-chat-tip[hidden] {
  display: none;
}

/* ── パネル ─────────────────────────────────── */

.sfq-chat-panel {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  width: 370px;
  max-width: calc(100vw - 24px);
  height: 540px;
  max-height: calc(100vh - 40px);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(15, 60, 50, .3), 0 4px 12px rgba(0, 0, 0, .1);
  overflow: hidden;
  font-family: inherit;
  transform-origin: bottom right;
  animation: sfq-chat-open .28s cubic-bezier(.16, 1, .3, 1);
}

@keyframes sfq-chat-open {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sfq-chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 14px 15px 18px;
  background: linear-gradient(135deg, #23c09a 0%, var(--sfq-green) 60%, var(--sfq-green-deep) 100%);
  color: #fff;
}

.sfq-chat-head .sfq-chat-avatar {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sfq-chat-head .sfq-chat-avatar svg {
  width: 19px;
  height: 19px;
}

.sfq-chat-headtext {
  flex: 1;
  min-width: 0;
  line-height: 1.35;
}

.sfq-chat-headtext strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
}

.sfq-chat-headtext small {
  font-size: 11px;
  opacity: .9;
}

.sfq-chat-close {
  flex: none;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  width: 30px;
  height: 30px;
  cursor: pointer;
  border-radius: 8px;
  transition: background .15s ease;
}

.sfq-chat-close:hover {
  background: rgba(255, 255, 255, .2);
}

.sfq-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--sfq-mist);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.sfq-chat-log > * {
  animation: sfq-chat-in .3s ease both;
}

@keyframes sfq-chat-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.sfq-chat-msg {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.75;
  word-break: break-word;
}

.sfq-chat-msg.is-user {
  align-self: flex-end;
  background: var(--sfq-green);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 2px 8px rgba(31, 171, 137, .25);
}

.sfq-chat-msg.is-bot {
  align-self: flex-start;
  background: #fff;
  color: var(--sfq-ink);
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 4px rgba(23, 48, 43, .07);
}

/* 検索結果の1件目（全文表示） */
.sfq-chat-card {
  align-self: stretch;
  border-radius: 14px;
  background: #fff;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.8;
  box-shadow: 0 2px 10px rgba(23, 48, 43, .09);
  border-left: 4px solid var(--sfq-green);
}

.sfq-chat-card h4 {
  margin: 0 0 8px;
  padding: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--sfq-green-deep);
  line-height: 1.6;
}

.sfq-chat-card .sfq-chat-answer {
  color: var(--sfq-ink);
}

.sfq-chat-card .sfq-chat-answer p {
  margin: 0 0 7px;
}

.sfq-chat-card .sfq-chat-answer p:last-child {
  margin-bottom: 0;
}

.sfq-chat-card a.sfq-chat-more {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--sfq-green-deep);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.sfq-chat-card a.sfq-chat-more:hover {
  border-bottom-color: var(--sfq-green-deep);
}

/* 2件目以降の候補 */
.sfq-chat-alts {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.sfq-chat-alts-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--sfq-ink-2);
}

.sfq-chat-alt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  padding: 11px 13px;
  border: 1px solid var(--sfq-line);
  border-radius: 12px;
  background: #fff;
  color: var(--sfq-ink);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.sfq-chat-alt::after {
  content: "＋";
  flex: none;
  color: var(--sfq-green);
  font-weight: 700;
}

.sfq-chat-alt:hover {
  border-color: var(--sfq-green);
  transform: translateX(2px);
  box-shadow: 0 2px 10px rgba(31, 171, 137, .16);
}

/* 「解決しましたか？」— 会話を邪魔しないよう控えめに置く */
.sfq-chat-feedback {
  align-self: stretch;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 12px;
  border: 1px dashed var(--sfq-line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .6);
}

.sfq-chat-feedback-q {
  flex: 1;
  min-width: 7em;
  font-size: 12.5px;
  color: var(--sfq-ink-2);
}

.sfq-chat-fb-btn {
  flex: none;
  padding: 5px 15px;
  border: 1px solid var(--sfq-line);
  border-radius: 999px;
  background: #fff;
  color: var(--sfq-ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.sfq-chat-fb-btn:hover {
  border-color: var(--sfq-green);
  background: var(--sfq-green);
  color: #fff;
}

.sfq-chat-fb-btn.is-no:hover {
  border-color: #b06a6a;
  background: #b06a6a;
}

.sfq-chat-links {
  align-self: stretch;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.sfq-chat-links a {
  padding: 8px 14px;
  border: 1.5px solid var(--sfq-green);
  border-radius: 999px;
  color: var(--sfq-green-deep);
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}

.sfq-chat-links a:hover {
  background: var(--sfq-green);
  color: #fff;
}

/* ── 入力欄 ─────────────────────────────────── */

.sfq-chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--sfq-line);
  background: #fff;
}

.sfq-chat-form input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border: 1.5px solid var(--sfq-line);
  border-radius: 999px;
  font-family: inherit;
  font-size: 14px;
  color: var(--sfq-ink);
  background: var(--sfq-mist);
  transition: border-color .15s ease, background .15s ease;
}

.sfq-chat-form input:focus {
  outline: none;
  border-color: var(--sfq-green);
  background: #fff;
}

.sfq-chat-form button {
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--sfq-green);
  color: #fff;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}

.sfq-chat-form button svg {
  width: 18px;
  height: 18px;
}

.sfq-chat-form button:hover:not(:disabled) {
  background: var(--sfq-green-deep);
  transform: scale(1.05);
}

.sfq-chat-form button:disabled {
  background: #b4ccc7;
  cursor: default;
}

.sfq-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 13px 16px;
  background: #fff;
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 4px rgba(23, 48, 43, .07);
}

.sfq-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sfq-green);
  animation: sfq-chat-blink 1.2s infinite ease-in-out;
}

.sfq-chat-typing span:nth-child(2) { animation-delay: .2s; }
.sfq-chat-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes sfq-chat-blink {
  0%, 80%, 100% { opacity: .25; transform: scale(.85); }
  40% { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .sfq-chat-launcher,
  .sfq-chat-panel,
  .sfq-chat-log > *,
  .sfq-chat-typing span,
  .sfq-chat-alt,
  .sfq-chat-tip {
    animation: none !important;
    transition: none !important;
  }
}

/**
 * スマホ。
 *
 * 下部にはテーマの追従CTA（黄色帯・タイトル＋ボタン2つで100px前後）が出る。
 * 横長のピルをその上に重ねると画面下部が二重の帯で埋まってしまうため、
 * SPでは**円形アイコンだけ**にして専有面積を落とす。
 * ラベルは aria-label で担保しているので読み上げ環境でも意味は伝わる。
 */
@media (max-width: 600px) {
  .sfq-chat-launcher {
    right: 12px;
    width: 58px;
    height: 58px;
    padding: 0;
    gap: 0;
    justify-content: center;
    border-radius: 50%;
  }

  /* 「ご質問はこちら」のテキストを畳む（アイコンだけにする） */
  .sfq-chat-launcher > span {
    display: none;
  }

  .sfq-chat-launcher .sfq-chat-icon {
    width: 26px;
    height: 26px;
  }

  .sfq-chat-panel {
    right: 8px;
    left: 8px;
    width: auto;
    height: min(560px, calc(100vh - 100px));
    border-radius: 16px;
  }

  .sfq-chat-tip {
    right: 12px;
    max-width: 172px;
    font-size: 12.5px;
    padding: 9px 12px;
  }

  .sfq-chat-tip::after {
    right: 20px;
  }

  .sfq-chat-msg,
  .sfq-chat-card {
    font-size: 13.5px;
  }
}
