/* ============================================================
   案内AIチャット（フローティングウィジェット） / ehyoka-portal
   ブループリント意匠（portal.css のガラスカード）に合わせる。
   z-index: 40（既存最大はトーストの 30）。右下は #corner-actions（社外ログインのスマホ認証＋
   ログアウトの縦積み・bottom:14〜65px）が占有しているため bottom:96px に配置する
   （2026-09-20: リンク追加に伴い 64px → 96px。portal.css の #corner-actions と対で管理）。
   ============================================================ */

#chat-root { font-family: var(--font-ja); color: var(--ink); }

/* ---- 起動ボタン（FAB）: パネルを閉じている間だけ表示 ----
   スチールシャイン（金属面＋約3.5秒ごとに斜めの光が走る・ホバー中は連続）。
   デザイン選定 2026-07-31（デモ A案・光る頻度高め）。 */
#chat-fab {
  position: fixed; bottom: 96px; right: 14px; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 52px; height: 52px; padding: 0; overflow: hidden;
  background: linear-gradient(160deg, #f8fafc 0%, #e2e9f1 28%, #c6d1dd 52%, #e9eef5 72%, #f5f8fb 100%);
  border: 1px solid #b7c3d1; border-radius: 3px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9), 0 2px 10px rgba(30,42,56,0.14), 0 10px 26px rgba(30,42,56,0.10);
  cursor: pointer; transition: border-color .15s, transform .24s cubic-bezier(.2,.8,.2,1), opacity .18s ease;
}
#chat-fab::after {
  content: ""; position: absolute; top: -30%; bottom: -30%; left: -70%; width: 45%;
  background: linear-gradient(105deg, rgba(255,255,255,0) 15%, rgba(255,255,255,0.95) 50%, rgba(255,255,255,0) 85%);
  transform: skewX(-20deg);
  animation: chat-glint 3.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes chat-glint {
  0%   { left: -70%; }
  12%  { left: 130%; }   /* 掃引 約0.4秒（周期3.5秒の12%）＝速めのきらっ */
  100% { left: 130%; }
}
#chat-fab:hover { border-color: var(--accent); transform: translateY(-1px); }
#chat-fab:hover::after { animation: chat-glint 1.1s ease-in-out infinite; }
.chat-fab-en { font-family: var(--font-mono); font-size: 15px; font-weight: 600; letter-spacing: .08em; color: var(--accent); position: relative; z-index: 1; }
.chat-fab-ja { font-size: 10px; color: #53637a; position: relative; z-index: 1; }
/* 開くと FAB は縮んで消え、閉じるとパネルが消えてから戻る（display:none をやめて遷移可能に。2026-09-08 開閉アニメーション）。
   transition ではなく animation で行う＝末尾の prefers-reduced-motion で #chat-fab の transition が無効化される PC
   （OS の「アニメーション効果」オフ・社内に多い）でも、閉じ始めた瞬間に FAB が戻ってしまわないようにするため。 */
#chat-root.open #chat-fab    { opacity: 0; transform: scale(.5) rotate(-8deg); pointer-events: none; animation: chat-fab-out .2s ease-in both; }
#chat-root.closing #chat-fab { opacity: 0; transform: scale(.5) rotate(-8deg); pointer-events: none; animation: chat-fab-in .24s cubic-bezier(.2,.8,.2,1) .14s both; }
#chat-root[data-anim="c"].closing #chat-fab { animation-delay: .66s; }   /* 案 C は逆再生（約 0.8 秒）の光線が消えてから */
@keyframes chat-fab-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(.5) rotate(-8deg); } }
@keyframes chat-fab-in  { from { opacity: 0; transform: scale(.5) rotate(-8deg); } to { opacity: 1; transform: none; } }

/* ---- パネル本体 ---- */
#chat-panel {
  position: fixed; bottom: 96px; right: 14px; z-index: 40;
  display: none; flex-direction: column;
  width: 360px; max-height: 70vh;
  background: rgba(255,255,255,0.66); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.72); border-radius: 3px;
  box-shadow: 0 2px 10px rgba(30,42,56,0.12), 0 14px 34px rgba(30,42,56,0.12);
}
#chat-root.open #chat-panel, #chat-root.closing #chat-panel { display: flex; }

/* ---- 開閉アニメーション（2026-09-08）: #chat-root[data-anim]  a=展開 / b=ガラス浮上 / c=スキャン起動 ----
   config.js CHAT.anim で選択（ローカルプレビューは ?anim=a|b|c で上書き）。閉じるときは共通で短く縮んで消える。 */
#chat-panel { overflow: hidden; }
#chat-panel:not(.wide) { transform-origin: 100% 100%; }
/* 閉じアニメーションの所要時間（ms）。chat.js closePanel() が読み取り、経過後に closing クラスを外して display:none にする */
#chat-root { --chat-close-ms: 260; }
#chat-root[data-anim="c"] { --chat-close-ms: 900; }
/* 閉じる（共通。案 C は下の逆再生で上書き） */
#chat-root.closing #chat-panel:not(.wide) { animation: chat-close .22s ease-in forwards; }
#chat-root.closing #chat-panel.wide { animation: chat-close-wide .2s ease-in forwards; }
@keyframes chat-close { to { opacity: 0; transform: translate(14px, 14px) scale(.85); } }
@keyframes chat-close-wide { to { opacity: 0; } }
/* 拡大表示中に開いた場合はフェードのみ（中央配置の transform と干渉させない） */
#chat-root.open #chat-panel.wide { animation: chat-open-wide .3s ease-out backwards; }
@keyframes chat-open-wide { from { opacity: 0; } to { opacity: 1; } }
/* 中身の遅れ表示（A・C で使用） */
@keyframes chat-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes chat-fade { from { opacity: 0; } to { opacity: 1; } }

/* A: 展開＝FAB の位置から弾むように広がり、見出し→本文→入力欄の順に浮き上がる */
#chat-root[data-anim="a"].open #chat-panel:not(.wide) { animation: chat-open-a .46s cubic-bezier(.22,1,.36,1) backwards; }
@keyframes chat-open-a { 0% { opacity: 0; transform: translate(26px, 26px) scale(.55); } 100% { opacity: 1; transform: none; } }
#chat-root[data-anim="a"].open .chat-head { animation: chat-rise .4s cubic-bezier(.22,1,.36,1) .14s backwards; }
#chat-root[data-anim="a"].open #chat-log  { animation: chat-rise .4s cubic-bezier(.22,1,.36,1) .2s backwards; }
#chat-root[data-anim="a"].open #chat-form { animation: chat-rise .4s cubic-bezier(.22,1,.36,1) .26s backwards; }

/* B: ガラス浮上＝下から浮き上がりつつぼかしが効き、直後に斜めの光が一度走る */
#chat-root[data-anim="b"].open #chat-panel:not(.wide) { animation: chat-open-b .5s cubic-bezier(.2,.9,.2,1) backwards; }
@keyframes chat-open-b {
  0%   { opacity: 0; transform: translateY(34px); backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); }
  100% { opacity: 1; transform: none; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
}
#chat-root[data-anim="b"].open #chat-panel::after {
  content: ""; position: absolute; top: -30%; bottom: -30%; left: -60%; width: 40%; pointer-events: none;
  background: linear-gradient(105deg, rgba(255,255,255,0) 15%, rgba(255,255,255,0.75) 50%, rgba(255,255,255,0) 85%);
  transform: skewX(-20deg); animation: chat-sweep .8s .3s ease-out 1 both;
}
@keyframes chat-sweep { 0% { left: -60%; } 100% { left: 130%; } }

/* C: スキャン起動（2026-09-08 「さらにドラマチックに」版・約 1 秒の起動シーケンス）
   0.00s 中央に光線が点灯（横に伸びる）→ 0.10s 上下に開き走査線が縁へ走る／青い格子が一瞬浮かぶ
   → 0.35s 中身が滑らかに点灯・見出しが左から現れる → 0.45s 四隅にブラケットが飛び込む → 0.55s 縁が一度発光
   閉じる＝逆再生（約 0.8 秒・2026-09-08 ユーザー要望）: 0.00s 縁が発光しブラケットが四隅へ飛び去る・見出しが左へ消える
   → 0.04s 中身が滑らかに消灯 → 0.16s 格子が浮かぶ → 0.32s 走査線が上下の縁から中央へ集まりパネルが中央の線へ閉じる
   → 0.65s 光線が縮んで消灯 → FAB が戻る。
   擬似要素（走査線・格子・ブラケット）の基本スタイルは .open と .closing の両方に当て、アニメーションだけ分ける。 */
#chat-root[data-anim="c"].open #chat-panel:not(.wide) {
  animation: chat-open-c .5s cubic-bezier(.2,.8,.2,1) .1s backwards, chat-ring-c .7s ease-out .55s backwards;
}
#chat-root[data-anim="c"].closing #chat-panel:not(.wide) {
  animation: chat-close-c .46s cubic-bezier(.6,0,.4,1) .32s both, chat-ring-c .32s ease-out both;
}
@keyframes chat-open-c {
  0%   { opacity: 1; clip-path: inset(calc(50% - 2px) 0 calc(50% - 2px) 0); }
  100% { opacity: 1; clip-path: inset(0 0 0 0); }
}
@keyframes chat-close-c {
  0%   { opacity: 1; clip-path: inset(0 0 0 0); }
  72%  { opacity: 1; clip-path: inset(calc(50% - 2px) 0 calc(50% - 2px) 0); }
  100% { opacity: 0; clip-path: inset(calc(50% - 2px) 0 calc(50% - 2px) 0); }
}
@keyframes chat-ring-c {
  0%   { box-shadow: 0 0 0 0 rgba(51,98,143,0), 0 2px 10px rgba(30,42,56,0.12), 0 14px 34px rgba(30,42,56,0.12); }
  30%  { box-shadow: 0 0 0 2px rgba(51,98,143,0.6), 0 0 34px rgba(51,98,143,0.45), 0 14px 34px rgba(30,42,56,0.12); }
  100% { box-shadow: 0 0 0 0 rgba(51,98,143,0), 0 2px 10px rgba(30,42,56,0.12), 0 14px 34px rgba(30,42,56,0.12); }
}
/* 走査線: 開く＝中央で点灯して横に伸び上下の縁へ走る／閉じる＝縁から中央へ集まり縮んで消える */
#chat-root[data-anim="c"]:is(.open, .closing) #chat-panel::before, #chat-root[data-anim="c"]:is(.open, .closing) #chat-panel::after {
  content: ""; position: absolute; left: 0; right: 0; height: 2px; pointer-events: none; z-index: 3;
  background: linear-gradient(90deg, rgba(51,98,143,0), rgba(51,98,143,0.95) 30%, rgba(170,210,255,1) 50%, rgba(51,98,143,0.95) 70%, rgba(51,98,143,0));
  box-shadow: 0 0 12px rgba(80,140,210,0.95), 0 0 28px rgba(51,98,143,0.6);
  transform-origin: 50% 50%;
}
#chat-root[data-anim="c"].open #chat-panel::before { animation: chat-scan-up .62s cubic-bezier(.2,.8,.2,1) both; }
#chat-root[data-anim="c"].open #chat-panel::after  { animation: chat-scan-down .62s cubic-bezier(.2,.8,.2,1) both; }
@keyframes chat-scan-up   { 0% { top: 50%; transform: scaleX(.05); opacity: 1; } 16% { top: 50%; transform: scaleX(1); opacity: 1; } 88% { opacity: 1; } 100% { top: 0; transform: scaleX(1); opacity: 0; } }
@keyframes chat-scan-down { 0% { top: 50%; transform: scaleX(.05); opacity: 1; } 16% { top: 50%; transform: scaleX(1); opacity: 1; } 88% { opacity: 1; } 100% { top: 100%; transform: scaleX(1); opacity: 0; } }
#chat-root[data-anim="c"].closing #chat-panel::before { animation: chat-unscan-top .46s cubic-bezier(.6,0,.4,1) .32s both; }
#chat-root[data-anim="c"].closing #chat-panel::after  { animation: chat-unscan-bottom .46s cubic-bezier(.6,0,.4,1) .32s both; }
@keyframes chat-unscan-top    { 0% { top: 0; transform: scaleX(1); opacity: 0; } 10% { opacity: 1; } 72% { top: 50%; transform: scaleX(1); opacity: 1; } 100% { top: 50%; transform: scaleX(.05); opacity: 0; } }
@keyframes chat-unscan-bottom { 0% { top: 100%; transform: scaleX(1); opacity: 0; } 10% { opacity: 1; } 72% { top: 50%; transform: scaleX(1); opacity: 1; } 100% { top: 50%; transform: scaleX(.05); opacity: 0; } }
/* 青い格子（ブループリント）が開閉の途中に浮かんで消える */
#chat-root[data-anim="c"] #chat-log { position: relative; }
#chat-root[data-anim="c"]:is(.open, .closing) #chat-log::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2; opacity: 0;
  background:
    repeating-linear-gradient(0deg, rgba(51,98,143,0.28) 0 1px, transparent 1px 18px),
    repeating-linear-gradient(90deg, rgba(51,98,143,0.28) 0 1px, transparent 1px 18px);
}
#chat-root[data-anim="c"].open #chat-log::before    { animation: chat-grid-c .75s ease-out .12s both; }
#chat-root[data-anim="c"].closing #chat-log::before { animation: chat-grid-c .42s ease-out .16s both; }
@keyframes chat-grid-c { 0% { opacity: 0; } 25% { opacity: .55; } 100% { opacity: 0; } }
/* 中身: 開く＝走査線が通ったあと滑らかに点灯／閉じる＝滑らかに消灯
   （初版は steps(1,end) で点滅させていたが、各段が 30〜60ms＝2〜4 フレームしか続かず「一瞬のちらつき」に見えたため
   2026-09-08 ユーザー指摘でフェードに変更。ヘッドレス Chrome のフレーム記録で、輝度の急な跳びが点滅キーフレームだけだったことを確認） */
#chat-root[data-anim="c"].open .chat-head, #chat-root[data-anim="c"].open #chat-log, #chat-root[data-anim="c"].open #chat-form {
  animation: chat-boot-c .4s ease-out .34s backwards;
}
#chat-root[data-anim="c"].closing .chat-head, #chat-root[data-anim="c"].closing #chat-log, #chat-root[data-anim="c"].closing #chat-form {
  animation: chat-shutdown-c .26s ease-in .04s both;
}
@keyframes chat-boot-c { 0% { opacity: 0; } 100% { opacity: 1; } }
@keyframes chat-shutdown-c { 0% { opacity: 1; } 100% { opacity: 0; } }
/* 見出しは開く＝左から現れる／閉じる＝左へ消える */
#chat-root[data-anim="c"].open .chat-head-title    { animation: chat-wipe-c .4s cubic-bezier(.2,.8,.2,1) .4s backwards; }
#chat-root[data-anim="c"].closing .chat-head-title { animation: chat-wipe-c .22s cubic-bezier(.6,0,.4,1) reverse both; }
@keyframes chat-wipe-c { 0% { clip-path: inset(0 100% 0 0); } 100% { clip-path: inset(0 0 0 0); } }
/* 四隅のブラケット: 開く＝外から飛び込んで固定され薄く残る／閉じる＝来た方向へ飛び去る */
#chat-root[data-anim="c"] .chat-head, #chat-root[data-anim="c"] #chat-form { position: relative; }
#chat-root[data-anim="c"]:is(.open, .closing) .chat-head::before, #chat-root[data-anim="c"]:is(.open, .closing) .chat-head::after,
#chat-root[data-anim="c"]:is(.open, .closing) #chat-form::before, #chat-root[data-anim="c"]:is(.open, .closing) #chat-form::after {
  content: ""; position: absolute; width: 14px; height: 14px; pointer-events: none; z-index: 4;
  border: 0 solid rgba(51,98,143,0.9); opacity: 0;
}
#chat-root[data-anim="c"].open .chat-head::before, #chat-root[data-anim="c"].open .chat-head::after,
#chat-root[data-anim="c"].open #chat-form::before, #chat-root[data-anim="c"].open #chat-form::after {
  animation: chat-bracket-c .45s cubic-bezier(.2,.9,.2,1) .48s both;
}
#chat-root[data-anim="c"].closing .chat-head::before, #chat-root[data-anim="c"].closing .chat-head::after,
#chat-root[data-anim="c"].closing #chat-form::before, #chat-root[data-anim="c"].closing #chat-form::after {
  animation: chat-bracket-out-c .28s cubic-bezier(.5,0,.8,.4) both;
}
#chat-root[data-anim="c"]:is(.open, .closing) .chat-head::before { top: 4px; left: 4px; border-top-width: 2px; border-left-width: 2px; --dx: -12px; --dy: -12px; }
#chat-root[data-anim="c"]:is(.open, .closing) .chat-head::after  { top: 4px; right: 4px; border-top-width: 2px; border-right-width: 2px; --dx: 12px; --dy: -12px; }
#chat-root[data-anim="c"]:is(.open, .closing) #chat-form::before { bottom: 4px; left: 4px; border-bottom-width: 2px; border-left-width: 2px; --dx: -12px; --dy: 12px; }
#chat-root[data-anim="c"]:is(.open, .closing) #chat-form::after  { bottom: 4px; right: 4px; border-bottom-width: 2px; border-right-width: 2px; --dx: 12px; --dy: 12px; }
@keyframes chat-bracket-c { 0% { opacity: 0; transform: translate(var(--dx), var(--dy)); } 60% { opacity: 1; transform: none; } 100% { opacity: .55; transform: none; } }
@keyframes chat-bracket-out-c { 0% { opacity: .55; transform: none; } 30% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)); } }

/* 拡大（ワイド）表示: 画面中央の大パネル */
#chat-panel.wide {
  width: min(1000px, 78vw); height: 78vh; max-height: 78vh;
  bottom: 50%; right: 50%; transform: translate(50%, 50%);
}

/* ---- ヘッダー ---- */
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid rgba(30,42,56,0.12);
}
.chat-head-en { display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: .16em; color: var(--accent); }
.chat-head-ja { display: block; font-size: 13px; font-weight: 700; color: #26374a; }
.chat-head-btns { display: flex; gap: 6px; }
.chat-head-btns button {
  font: 11px/1 var(--font-ja); color: #53637a;
  background: rgba(255,255,255,0.7); border: 1px solid rgba(30,42,56,0.16); border-radius: 3px;
  padding: 5px 8px; cursor: pointer; transition: border-color .15s, color .15s;
}
.chat-head-btns button:hover { border-color: var(--accent); color: var(--accent); }

/* ---- ログ ---- */
#chat-log { flex: 1 1 auto; overflow-y: auto; padding: 12px; min-height: 180px; }
.chat-msg { display: flex; margin-bottom: 10px; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: 86%; padding: 8px 11px; border-radius: 3px;
  font-size: 13px; line-height: 1.7; word-break: break-word; overflow-wrap: anywhere;
}
.chat-msg.user .chat-bubble {
  background: rgba(51,98,143,0.12); border: 1px solid rgba(51,98,143,0.25);
  white-space: pre-wrap;
}
.chat-msg.assistant .chat-bubble {
  background: rgba(255,255,255,0.85); border: 1px solid rgba(255,255,255,0.9);
  box-shadow: 0 1px 4px rgba(30,42,56,0.08);
}
.chat-msg.chat-error .chat-bubble { border-color: rgba(168,60,42,0.4); color: #8a3a2a; }
.chat-bubble p { margin: 0 0 6px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul { margin: 0 0 6px; padding-left: 18px; }
.chat-bubble li { margin: 2px 0; }
.chat-bubble code {
  font-family: var(--font-mono); font-size: 12px;
  background: rgba(30,42,56,0.07); padding: 1px 5px; border-radius: 3px;
}
.chat-bubble a { color: var(--accent); word-break: break-all; }

/* ---- 質問候補チップ（初回のみ） ---- */
.chat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 10px; }
.chat-chip {
  font: 12px/1.4 var(--font-ja); color: var(--accent);
  background: rgba(255,255,255,0.7); border: 1px solid rgba(51,98,143,0.35); border-radius: 3px;
  padding: 6px 10px; cursor: pointer; transition: background .15s;
}
.chat-chip:hover { background: rgba(51,98,143,0.08); }

/* ---- タイピングインジケータ ---- */
.chat-typing .chat-bubble { display: flex; gap: 4px; align-items: center; padding: 12px 14px; }
.chat-typing .dot {
  width: 6px; height: 6px; border-radius: 50%; background: #8695a8;
  animation: chat-blink 1.2s infinite both;
}
.chat-typing .dot:nth-child(2) { animation-delay: .2s; }
.chat-typing .dot:nth-child(3) { animation-delay: .4s; }
@keyframes chat-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---- 入力フォーム ---- */
#chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid rgba(30,42,56,0.12); }
#chat-input {
  flex: 1 1 auto; resize: none;
  font: 13px/1.6 var(--font-ja); color: var(--ink);
  background: rgba(255,255,255,0.85); border: 1px solid rgba(30,42,56,0.2); border-radius: 3px;
  padding: 7px 9px;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
#chat-input:disabled { opacity: .6; }
#chat-send {
  align-self: flex-end;
  font: 13px/1 var(--font-ja); color: #fff;
  background: var(--accent); border: 1px solid var(--accent); border-radius: 3px;
  padding: 9px 14px; cursor: pointer; transition: opacity .15s;
}
#chat-send:hover { opacity: .88; }
#chat-send:disabled { opacity: .5; cursor: default; }

/* ---- レスポンシブ（スマホ利用なし・小さめ画面の破綻防止のみ） ---- */
@media (max-width: 900px) {
  #chat-panel { width: 320px; }
  #chat-panel.wide { width: 92vw; }
}

/* ---- モーション低減 ----
   FAB の光走査（chat-glint）は「ボタンを目立たせる」要望仕様のため、OS のアニメーション
   効果オフ（prefers-reduced-motion）でも止めない（Windows は企業PCでオフが多く、止めると
   「ホバー時しか光らない」見え方になるため）。 */
@media (prefers-reduced-motion: reduce) {
  #chat-fab { transition: none; }
  .chat-typing .dot { animation: none; opacity: .6; }
}
