/* IPSS チャットボット ウィジェット
   色を変えたいときは下の変数だけ書き換えてください */
.ipss-cb {
  --cb-main: #1f8a4c;        /* メインカラー（ボタン・ヘッダー）サイトの青と区別するためグリーン */
  --cb-main-dark: #18733f;   /* ボタンのホバー */
  --cb-on-main: #ffffff;     /* メインカラーの上の文字 */
  --cb-on-main-hover: rgba(255,255,255,.18); /* メインカラーの上のアイコン背景・閉じるボタンのホバー */
  --cb-link: #17703d;        /* 白地の上の緑の文字（リンク・よくある質問ボタン） */
  --cb-accent: #4caf73;      /* アクセント（明るい緑） */
  --cb-accent-light: #e6f4ea; /* よくある質問ボタンのホバー */
  --cb-bg: #ffffff;
  --cb-panel-bg: #f3f9f5;    /* 会話エリアの背景（ごく薄い緑） */
  --cb-bot-bubble: #ffffff;
  --cb-user-bubble: #1f8a4c;
  --cb-text: #1f2a24;
  --cb-sub: #5d6b63;
  --cb-line: #dde8e1;
  --cb-radius: 16px;
  --cb-shadow: 0 12px 40px rgba(0, 0, 0, .2);

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans TC", "Microsoft JhengHei", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--cb-text);
}
.ipss-cb *, .ipss-cb *::before, .ipss-cb *::after { box-sizing: border-box; }

/* ---- 開くボタン ---- */
.ipss-cb__launcher {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 64px;
  padding: 0 26px 0 20px;
  border: 3px solid #fff;    /* 白い縁取りで背景から浮かせる */
  border-radius: 32px;
  background: var(--cb-main);
  color: var(--cb-on-main);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .02em;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.ipss-cb__launcher:hover { background: var(--cb-main-dark); transform: translateY(-2px); }
.ipss-cb__launcher:focus-visible,
.ipss-cb button:focus-visible,
.ipss-cb textarea:focus-visible { outline: 3px solid var(--cb-accent); outline-offset: 2px; }
.ipss-cb__launcher svg { width: 30px; height: 30px; flex: none; }
.ipss-cb.is-open .ipss-cb__launcher { display: none; }

/* ---- パネル ---- */
.ipss-cb__panel {
  display: none;
  flex-direction: column;
  width: 380px;
  height: min(620px, calc(100vh - 40px));
  background: var(--cb-bg);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  overflow: hidden;
}
.ipss-cb.is-open .ipss-cb__panel { display: flex; animation: ipss-cb-in .2s ease-out; }
@keyframes ipss-cb-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.ipss-cb__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 14px 16px;
  background: var(--cb-main);
  color: var(--cb-on-main);
}
.ipss-cb__avatar {
  width: 36px; height: 36px; flex: none;
  border-radius: 50%;
  background: var(--cb-on-main-hover);
  display: grid; place-items: center;
}
.ipss-cb__avatar svg { width: 22px; height: 22px; }
.ipss-cb__title { flex: 1; min-width: 0; }
.ipss-cb__title strong { display: block; font-size: 15px; }
.ipss-cb__title span { display: block; font-size: 12px; opacity: .8; }
.ipss-cb__close {
  width: 36px; height: 36px; flex: none;
  border: none; border-radius: 50%;
  background: transparent; color: var(--cb-on-main);
  font-size: 22px; line-height: 1;
  cursor: pointer;
}
.ipss-cb__close:hover { background: var(--cb-on-main-hover); }

/* ---- 会話 ---- */
.ipss-cb__log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  background: var(--cb-panel-bg);
  overscroll-behavior: contain;
}
.ipss-cb__msg { display: flex; margin-bottom: 12px; }
.ipss-cb__msg--user { justify-content: flex-end; }
.ipss-cb__bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.ipss-cb__msg--bot .ipss-cb__bubble {
  background: var(--cb-bot-bubble);
  border: 1px solid var(--cb-line);
  border-top-left-radius: 4px;
}
.ipss-cb__msg--user .ipss-cb__bubble {
  background: var(--cb-user-bubble);
  color: var(--cb-on-main);
  border-top-right-radius: 4px;
}
.ipss-cb__bubble a { color: var(--cb-link); font-weight: 600; text-decoration: underline; }
.ipss-cb__msg--user .ipss-cb__bubble a { color: var(--cb-on-main); }

/* 入力中… */
.ipss-cb__typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.ipss-cb__typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--cb-accent);
  animation: ipss-cb-dot 1s infinite ease-in-out;
}
.ipss-cb__typing i:nth-child(2) { animation-delay: .15s; }
.ipss-cb__typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ipss-cb-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

/* よくある質問ボタン */
.ipss-cb__chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.ipss-cb__chip {
  padding: 6px 12px;
  border: 1px solid var(--cb-accent);
  border-radius: 999px;
  background: #fff;
  color: var(--cb-link);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.ipss-cb__chip:hover { background: var(--cb-accent-light); }

/* ---- 入力欄 ---- */
.ipss-cb__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--cb-line);
  background: var(--cb-bg);
}
.ipss-cb__input {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--cb-line);
  border-radius: 12px;
  font: inherit;
  font-size: 16px; /* iPhoneで拡大されないように16px */
  color: var(--cb-text);
  resize: none;
  background: #fff;
}
.ipss-cb__send {
  width: 42px; height: 42px; flex: none;
  border: none; border-radius: 12px;
  background: var(--cb-main); color: var(--cb-on-main);
  display: grid; place-items: center;
  cursor: pointer;
}
.ipss-cb__send:disabled { opacity: .4; cursor: default; }
.ipss-cb__send svg { width: 20px; height: 20px; }

.ipss-cb__note {
  padding: 0 14px 10px;
  background: var(--cb-bg);
  color: var(--cb-sub);
  font-size: 11px;
  line-height: 1.5;
}
.ipss-cb__note a { color: var(--cb-sub); }

/* ---- スマホ：全画面表示 ---- */
@media (max-width: 480px) {
  .ipss-cb { right: 12px; bottom: 12px; }
  .ipss-cb__launcher { height: 52px; padding: 0 18px 0 14px; gap: 8px; font-size: 15px; border-width: 2px; }
  .ipss-cb__launcher svg { width: 24px; height: 24px; }
  .ipss-cb.is-open { inset: 0; right: 0; bottom: 0; }
  .ipss-cb.is-open .ipss-cb__panel { width: 100%; height: 100%; border-radius: 0; }
  .ipss-cb__header { padding-top: max(14px, env(safe-area-inset-top)); }
  .ipss-cb__note { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

/* ---- サイトのページトップボタンと重ならないよう、チャットボタンの上へ移動 ----
   チャットボタンの上端（bottom + 高さ）から12px空ける */
#to_top { bottom: 96px; }
@media (max-width: 480px) {
  #to_top { bottom: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  .ipss-cb *, .ipss-cb { animation: none !important; transition: none !important; }
}

@media print { .ipss-cb { display: none !important; } }
