/* CROSS LINK AI Chatbot — ウィジェット専用CSS（既存サイト組み込み用・自動生成） */
/* 既存サイトに干渉しないよう、box-sizing はウィジェット内に限定 */
.chat-widget, .chat-widget *, .chat-widget *::before, .chat-widget *::after, .chat-open, .chat-open::before, .chat-teaser { box-sizing: border-box; }

:root {
  --ink:        #393331;  /* ブランドのダークチャコール */
  --ink-2:      #2b2624;  /* さらに濃い影 */
  --ink-soft:   #4f4843;
  --lime:       #a6c61e;  /* ブランドのライムグリーン */
  --lime-bright:#bedc36;
  --lime-deep:  #8aa813;
  --lime-tint:  #eef4d4;  /* ユーザー発話の淡いライム */
  --paper:      #f4f3ee;  /* 温かみのあるオフホワイト */
  --card:       #ffffff;
  --line:       #e6e4dd;
  --muted:      #8f8a80;
  --text:       #2b2622;
  --on-dark:    #f4f2ec;
  --on-dark-soft:#c8c4ba;
  --radius:     16px;
}

/* ===== Chat widget ===== */
.chat-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999; /* 常に最前面（背面の本文と重ならないように） */
  /* 画面サイズに追従（上限・下限つき）。大画面ほど少し大きく、小画面では自動で縮小 */
  width: clamp(340px, 28vw, 400px);
  height: clamp(500px, 72vh, 650px);
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 40px);
  /* クリアな半透明（ぼかしなし：背景の文字がそのまま透けて見える） */
  background: transparent;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 16px;
  box-shadow: 0 22px 64px rgba(20,16,14,.42);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: rise .5s ease both;
}

/* ドラッグでサイズ変更するハンドル（右下固定なので 左上=縦横 / 左辺=幅 / 上辺=高さ をつかむ） */
.cw-resize { position: absolute; z-index: 6; touch-action: none; }
.cw-resize-t  { top: 0; left: 16px; right: 46px; height: 8px; cursor: ns-resize; }
.cw-resize-l  { left: 0; top: 16px; bottom: 16px; width: 8px; cursor: ew-resize; }
.cw-resize-tl { top: 0; left: 0; width: 28px; height: 28px; cursor: nwse-resize; }
/* 角のつかむグリップ：常時ライムで表示し、脈打つように点滅＝ドラッグ可能と気づかせる */
.cw-resize-tl::before {
  content: ""; position: absolute; left: 7px; top: 7px; width: 13px; height: 13px;
  border-left: 3px solid var(--lime);
  border-top: 3px solid var(--lime);
  border-top-left-radius: 5px;
  transform-origin: top left;
  animation: cw-grip-pulse 1.5s ease-in-out infinite;
}
/* ホバー／ドラッグ時に浮き上がる発光リング */
.cw-resize-tl::after {
  content: ""; position: absolute; left: 0; top: 0; width: 28px; height: 28px;
  border-top-left-radius: 16px;
  background: radial-gradient(circle at 9px 9px, rgba(166,198,30,.35), transparent 62%);
  opacity: 0; transition: opacity .18s ease;
}
/* ホバー時はアニメを止めて“くっきり固定”＝つかめる合図 */
.cw-resize-tl:hover::before,
.chat-widget:hover .cw-resize-tl::before {
  animation-play-state: paused;
  opacity: 1; transform: translate(-1px, -1px) scale(1.18);
  filter: drop-shadow(0 0 4px rgba(166,198,30,.85));
}
.cw-resize-tl:hover::after,
.chat-widget:hover .cw-resize-tl::after { opacity: 1; }

/* 点滅＋伸縮のパルス（光彩も同時に伸縮） */
@keyframes cw-grip-pulse {
  0%   { opacity: .5;  transform: translate(0, 0) scale(1);
         filter: drop-shadow(0 0 0 rgba(166,198,30,0)); }
  50%  { opacity: 1;   transform: translate(-1.5px, -1.5px) scale(1.24);
         filter: drop-shadow(0 0 6px rgba(166,198,30,.9)); }
  100% { opacity: .5;  transform: translate(0, 0) scale(1);
         filter: drop-shadow(0 0 0 rgba(166,198,30,0)); }
}
.chat-widget.resizing { user-select: none; }
@media (max-width: 560px) { .cw-resize { display: none; } } /* スマホでは無効 */

.chat-header {
  background: rgba(57,51,49,.82);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px solid var(--lime);
}
.chat-header strong {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
}
/* ヘッダーのシャッター（絞り）ロゴ */
.chat-header strong::before {
  content: "";
  width: 18px; height: 18px;
  flex: 0 0 auto;
  background: url("assets/logo-aperture.svg?v=1") center/contain no-repeat;
}
.chat-header small { display: block; opacity: .7; margin-top: 4px; letter-spacing: .04em; }
.chat-header button {
  background: transparent;
  color: #fff;
  border: 0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: .8;
  transition: opacity .15s ease;
}
.chat-header button:hover { opacity: 1; }
/* ヘッダー左側（ロゴ＋タイトル＋「自動応答」バッジ） */
.cw-head-left { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.cw-badge {
  font-size: 10.5px; font-weight: 700; color: #fff; background: #000;
  border-radius: 5px; padding: 2px 7px; letter-spacing: .02em; white-space: nowrap;
}
/* 最小化ボタン（ライムの横バー） */
.chat-header button.cw-min { position: relative; width: 30px; height: 24px; opacity: 1; }
.chat-header button.cw-min::before {
  content: ""; position: absolute; left: 7px; right: 7px; top: 50%; height: 3px;
  transform: translateY(-50%); background: var(--lime); border-radius: 2px;
  transition: background .15s ease;
}
.chat-header button.cw-min:hover::before { background: var(--lime-bright); }

.chat-body {
  flex: 1; padding: 18px 18px 2px; overflow-y: auto; background: rgba(250,249,245,.45);
  display: flex; flex-direction: column; align-items: flex-start;
}

.bot, .user {
  padding: 12px 15px;
  border-radius: 16px;
  margin: 10px 0;
  line-height: 1.7;
  white-space: pre-wrap;
  font-size: 14.5px;
  max-width: 88%;
  word-break: break-word;
}
.bot {
  background: rgba(255,255,255,.92);
  border: 1px solid var(--line);
  border-top-left-radius: 5px;
  color: var(--text);
  white-space: pre-wrap; /* 改行（「・」箇条書き）をそのまま表示 */
}
/* AI回答のリッチ整形 */
.bot p { margin: 0 0 8px; }
.bot p:last-child { margin-bottom: 0; }
.bot p.md-h { font-weight: 800; margin: 10px 0 4px; }
.bot strong { font-weight: 800; color: var(--ink); }
.bot ul, .bot ol { margin: 6px 0; padding-left: 1.35em; }
.bot li { margin: 3px 0; }
.bot li::marker { color: var(--lime-deep); }
.user {
  background: var(--lime-tint);
  border: 1px solid #dfeab4;
  border-top-right-radius: 5px;
  color: #3a4413;
  align-self: flex-end;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,.5);
  background: rgba(252,251,248,.55);
}
.chat-input input {
  flex: 1;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text);
  background: rgba(255,255,255,.9);
  transition: border-color .15s ease;
}
.chat-input input:focus {
  outline: none;
  border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(166,198,30,.22);
}
.chat-input button {
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 800;
  cursor: pointer;
  background: var(--lime);
  color: var(--ink);
  transition: background .15s ease, transform .15s ease;
}
.chat-input button:hover { background: var(--lime-bright); transform: translateY(-1px); }

/* フローティングの起動ボタン（シャッターロゴのタイル） */
.chat-open {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9998; /* 起動ボタンも本文より前面に */
  width: 60px;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 17px;
  font-size: 0;
  cursor: pointer;
  background: url("assets/logo-aperture-tile.svg?v=1") center/cover no-repeat;
  box-shadow: 0 14px 34px rgba(43,38,36,.32);
  transition: transform .16s ease, box-shadow .16s ease;
}
.chat-open:hover { transform: translateY(-3px) scale(1.03); box-shadow: 0 18px 42px rgba(43,38,36,.4); }

/* 閉じている時の案内フキダシ（起動ボタンの上に数秒だけ表示） */
.chat-teaser {
  position: fixed;
  right: 20px;
  bottom: 92px;               /* 起動ボタン(60px)+20px の少し上 */
  z-index: 9998;
  max-width: 250px;
  background: var(--ink);
  color: #fff;
  border-left: 3px solid var(--lime);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  padding: 11px 14px;
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 12px 30px rgba(20,16,14,.35);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px) scale(.96);
  transform-origin: bottom right;
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
}
.chat-teaser.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.chat-teaser::after {   /* 起動ボタン方向を指すしっぽ */
  content: "";
  position: absolute;
  right: 20px; bottom: -6px;
  width: 13px; height: 13px;
  background: var(--ink);
  transform: rotate(45deg);
  border-radius: 0 0 3px 0;
}
@media (max-width: 560px) { .chat-teaser { right: 16px; bottom: 86px; max-width: 62vw; } }

.hidden { display: none; }

/* RAG出典の表示 */
.sources {
  font-size: 12px;
  color: var(--ink-soft);
  background: #f3f5e6;
  border: 1px solid #e3ebc3;
  border-left: 3px solid var(--lime);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 8px 0 14px;
}
.sources small { display: block; color: var(--muted); margin: 2px 0 6px; }
.sources span { display: block; margin-top: 4px; }

/* チャット内のリンク */
.bot a, .user a {
  color: var(--lime-deep);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.bot a:hover, .user a:hover { color: var(--ink); }

/* CTA ボタン行（Bot回答の下に表示） */
.cta-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; align-self: stretch; }
.cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  border-radius: 999px;
  padding: 9px 15px;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.cta-btn:hover { transform: translateY(-1px); }
.cta-primary { background: var(--lime); color: var(--ink); }
.cta-primary:hover { background: var(--lime-bright); }
.cta-ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.cta-ghost:hover { border-color: var(--lime); }
.cta-ic { font-size: 13px; line-height: 1; }

/* 選択式メニュー（チャット下部へ寄せる：余白があれば最下部に配置） */
.menu { margin: auto 0 4px; align-self: stretch; }
.menu-title {
  font-size: 10.5px;
  color: var(--muted);
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.menu-title .ic { font-size: 12px; }
.menu-title::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--lime); flex: 0 0 auto;
}
/* 2列グリッドで極力コンパクトに（高さ圧縮） */
.opts { display: flex; flex-wrap: wrap; gap: 4px; }
.opts.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-align: center;
  border-radius: 8px;
  padding: 10px 9px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.opt:hover { background: var(--lime); border-color: var(--lime); color: #fff; font-weight: 700; }
.opt:hover .ic { color: #fff; }
.opt .ic { font-size: 13px; }

/* 入力中のローディングドット */
.loading .dots { display: inline-flex; gap: 5px; padding: 2px 0; }
.loading .dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--lime-deep); opacity: .4;
  animation: blink 1.2s infinite ease-in-out;
}
.loading .dots i:nth-child(2) { animation-delay: .2s; }
.loading .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: .3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* スクロールバー */
.chat-body::-webkit-scrollbar { width: 8px; }
.chat-body::-webkit-scrollbar-thumb { background: #d8d6cd; border-radius: 8px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* アクセシビリティ */
.chat-widget :focus-visible, .chat-open:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .chat-widget *, .chat-widget *::before, .chat-widget *::after, .chat-open { animation: none !important; transition: none !important; }
}

@media (max-width: 560px) {
  /* スマホ：縦は画面の約70%に抑える（大きすぎ防止） */
  .chat-widget { width: calc(100vw - 24px); height: 70vh; max-height: 70vh; right: 12px; bottom: 12px; }
  .chat-open { right: 16px; bottom: 16px; }
}
