/* ② チャットページ（質問する人が使う画面。public/chat.html・chat.js、サーバーは lib/cs/chat.js）
   値は ui.css・style.css の :root の名前だけで呼ぶ（rules/UIレギュレーション.md 5 節）
   塗った面に文字を載せただけの形（吹き出し・札）は作らない。発言は白い面の中に罫線で区切って並べ、誰の発言かは名前で示す
   セレクタは .chat- で始める（ほかの画面に効かせない） */

/* ui.css は作り直しの途中（2026-09-29）。使うのは残ると決まった名前だけ（ui-btn・--fs-*・--lh-*・--sp-*・--z-*・--tap・--r-* と style.css の色と影） */
body.chat-page { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
/* 上の帯はツール画面のヘッダーと同じく、丸く浮かせる（UIレギュレーション 1・2 節「丸みと奥行き」） */
.chat-hd {
  position: sticky; top: var(--sp-3); z-index: var(--z-topbar);
  width: min(720px, calc(100% - 2 * var(--sp-4))); margin: var(--sp-3) auto 0;
  border-radius: var(--r-pill); background: var(--c-surface); box-shadow: var(--e2);
}
.chat-hd-in {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: calc(var(--tap) + var(--sp-3)); padding: 0 var(--sp-3) 0 var(--sp-6);
}
.chat-wm { font-size: var(--fs-16); font-weight: 900; line-height: var(--lh-tight); letter-spacing: .16em; color: var(--c-text); white-space: nowrap; }
.chat-sys {
  padding-left: var(--sp-3); border-left: 1px solid var(--c-line);
  font-size: var(--fs-13); font-weight: 700; line-height: var(--lh-tight); letter-spacing: var(--ls-label); color: var(--c-text-3);
}
.chat-sys { display: inline-flex; align-items: center; gap: var(--sp-2); white-space: nowrap; }
.chat-reset { margin-left: auto; }
/* サポートエージェントのアイコン（原本は 03_promotion/creative/assets/brand/support-agent/） */
.chat-av { flex: none; width: var(--ar); height: var(--ar); border-radius: 50%; }

.chat-main { width: min(720px, calc(100% - 2 * var(--sp-4))); margin: 0 auto; padding: var(--sp-6) 0 var(--sp-10); }
.chat-panel { border-radius: var(--r-l); background: var(--c-surface); box-shadow: var(--e1); }

.chat-log { display: flex; flex-direction: column; min-height: 50vh; padding: var(--sp-1) var(--sp-6); }
.chat-msg { padding: var(--sp-5) 0; }
.chat-msg + .chat-msg, .chat-msg + .chat-contact { border-top: 1px solid var(--c-line-soft); }
.chat-msg.is-them { padding-left: 15%; }
.chat-msg.is-sending { opacity: .6; }
.chat-who { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-1); font-size: var(--fs-12); font-weight: 700; line-height: var(--lh-tight); letter-spacing: var(--ls-label); color: var(--c-text-3); }
.chat-text { font-size: var(--fs-16); line-height: var(--lh-text); color: var(--c-text); white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-msg.is-them .chat-text { color: var(--c-text-sub); }
.chat-wait .chat-text { color: var(--c-text-3); animation: chat-blink 1.4s ease-in-out infinite; }
@keyframes chat-blink { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

/* よくある質問（最初の一言の下と、FAQ に無かったときの近い質問）。押すとその答えが返る。札にせず、罫線で区切った行の並びにする */
.chat-faq-h { margin: var(--sp-4) 0 var(--sp-1); font-size: var(--fs-12); font-weight: 700; line-height: var(--lh-tight); letter-spacing: var(--ls-label); color: var(--c-text-3); }
.chat-faq { display: flex; flex-direction: column; margin-top: var(--sp-2); border-top: 1px solid var(--c-line-soft); }
.chat-faq-h + .chat-faq { margin-top: 0; }
.chat-faq-q {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  width: 100%; min-height: var(--tap); margin: 0; padding: var(--sp-2) 0; border: 0; border-bottom: 1px solid var(--c-line-soft);
  background: transparent; font-family: var(--f); font-size: var(--fs-14); font-weight: 700; line-height: var(--lh-ui); color: var(--c-text);
  text-align: left; cursor: pointer;
}
.chat-faq-q::after { content: ''; flex: none; width: 6px; height: 6px; border-top: 1.5px solid currentColor; border-right: 1.5px solid currentColor; transform: rotate(45deg); color: var(--c-text-3); }
.chat-faq-q:hover { color: var(--c-brand); }
.chat-faq-q:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 2px; }
.chat-staff { margin-top: var(--sp-3); }

.chat-contact { padding: var(--sp-5) 0 var(--sp-6); }
.chat-contact-q { min-height: calc(var(--tap) * 2); resize: vertical; }
.chat-contact-h { margin-bottom: var(--sp-3); font-size: var(--fs-14); font-weight: 700; line-height: var(--lh-tight); color: var(--c-text); }
.chat-contact .field { max-width: 420px; margin-bottom: var(--sp-4); }
.chat-contact .input { font-size: var(--fs-16); }
.chat-contact-act { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-4); }
.chat-contact-err { margin: 0 0 var(--sp-3); font-size: var(--fs-14); line-height: var(--lh-ui); color: var(--c-text); }

.chat-form {
  position: sticky; bottom: 0; z-index: var(--z-actionbar);
  display: flex; align-items: flex-end; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--c-line); border-radius: 0 0 var(--r-l) var(--r-l);
  background: var(--c-surface);
}
.chat-input {
  flex: 1; min-width: 0; min-height: var(--tap); max-height: 180px; margin: 0; padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--c-edge, var(--c-ring)); border-radius: var(--r-m); background: var(--c-surface);
  font-family: var(--f); font-size: var(--fs-16); font-weight: 500; line-height: var(--lh-ui); color: var(--c-text);
  resize: none; overflow-y: auto;
}
.chat-input:focus { border-color: var(--c-brand); outline: 1px solid var(--c-brand); outline-offset: 0; }
.chat-input:disabled { background: var(--c-bg); }
.chat-send { flex: none; height: var(--tap); padding-right: calc((var(--tap) - var(--ar)) / 2); }
.chat-err { margin: 0; padding: 0 var(--sp-4) var(--sp-3); font-size: var(--fs-14); line-height: var(--lh-ui); color: var(--c-text); }

/* 閉じる（埋め込みのときだけ出す） */
.chat-close {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); margin: 0; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--c-text); cursor: pointer;
}
.chat-reset[hidden] + .chat-close { margin-left: auto; }
.chat-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.chat-close:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 2px; }

/* 埋め込み（ai-builderz.com のトップの右下の枠の中。?embed=1）: 枠いっぱいに、上の帯・会話・入力欄を縦に並べ、会話（.chat-log）だけ流す */
body.chat-page.chat-embed { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; background: var(--c-surface); }
.chat-embed .chat-hd { position: static; flex: none; width: 100%; margin: 0; border-radius: 0; box-shadow: none; border-bottom: 1px solid var(--c-line-soft); }
.chat-embed .chat-hd-in { padding: 0 var(--sp-2) 0 var(--sp-5); }
.chat-embed .chat-wm { font-size: var(--fs-13); }
.chat-embed .chat-sys-t { display: none; }
.chat-embed .chat-main { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; padding: 0; }
.chat-embed .chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; border-radius: 0; box-shadow: none; }
.chat-embed .chat-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-1) var(--sp-5); }
.chat-embed .chat-msg.is-them { padding-left: 10%; }
.chat-embed .chat-form { position: static; flex: none; border-radius: 0; }

@media (prefers-reduced-motion: reduce) {
  .chat-wait .chat-text { animation: none; }
}
@media (max-width: 767px) {
  /* 上の帯に入りきらないので、呼び名はアイコンだけにする（呼び名は発言ごとに出る） */
  .chat-hd-in { padding: 0 var(--sp-2) 0 var(--sp-5); }
  .chat-wm { font-size: var(--fs-13); }
  .chat-sys-t { display: none; }
  .chat-main { flex: 1; display: flex; flex-direction: column; width: 100%; padding: 0; }
  .chat-panel { flex: 1; display: flex; flex-direction: column; border: 0; border-radius: 0; box-shadow: none; }
  .chat-log { flex: 1; min-height: 0; padding: var(--sp-1) var(--sp-4); }
  .chat-msg.is-them { padding-left: 10%; }
  .chat-form { border-radius: 0; }
}

/* key SALES の窓口（?w=ks。body.chat-bubbles）だけ吹き出しのチャットにする（2026-10-07 板垣さん「もう少しチャット UI に」）
   AIBUILDERZ のチャットは上のまま（吹き出しにしない） */
.chat-bubbles .chat-log { background: var(--c-bg); gap: var(--sp-3); padding-top: var(--sp-4); padding-bottom: var(--sp-4); }
.chat-bubbles .chat-msg { padding: 0; border: 0; max-width: 88%; }
.chat-bubbles .chat-msg + .chat-msg, .chat-bubbles .chat-msg + .chat-contact { border-top: 0; }
.chat-bubbles .chat-msg.is-them { align-self: flex-end; padding-left: 0; }
.chat-bubbles .chat-msg.is-them .chat-who { display: none; }
.chat-bubbles .chat-msg.is-ai, .chat-bubbles .chat-msg.is-staff { align-self: flex-start; }
.chat-bubbles .chat-text { padding: var(--sp-3) var(--sp-4); border-radius: var(--r-l) var(--r-l) var(--r-l) var(--r-s); background: var(--c-surface); box-shadow: var(--e1); font-size: var(--fs-14); line-height: var(--lh-text); }
.chat-bubbles .chat-msg.is-them .chat-text { border-radius: var(--r-l) var(--r-l) var(--r-s) var(--r-l); background: var(--c-select); box-shadow: none; color: var(--c-text); }
.chat-bubbles .chat-faq-h { margin: var(--sp-3) 0 var(--sp-2); }
.chat-bubbles .chat-msg .chat-faq { flex-direction: row; flex-wrap: wrap; gap: var(--sp-2); margin-top: 0; border-top: 0; }
.chat-bubbles .chat-msg .chat-faq-q { width: auto; min-height: var(--ctl-h-sm); padding: var(--sp-1) var(--sp-4); border: 0; border-radius: var(--r-pill); background: var(--g-ghost); box-shadow: var(--e-ghost); font-size: var(--fs-13); }
.chat-bubbles .chat-msg .chat-faq-q::after { display: none; }
.chat-faq-more { margin-top: var(--sp-2); padding: 0; border: 0; background: none; font: inherit; font-size: var(--fs-13); font-weight: 700; color: var(--c-text-3); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.chat-faq-more:hover { color: var(--c-brand); }
.chat-faq-btn { margin-left: auto; min-height: var(--ctl-h-sm); padding: 0 var(--sp-4); border: 0; border-radius: var(--r-pill); background: var(--g-ghost); box-shadow: var(--e-ghost); font-family: var(--f); font-size: var(--fs-13); font-weight: 700; color: var(--c-text); cursor: pointer; white-space: nowrap; }
.chat-faq-btn[aria-expanded="true"] { box-shadow: var(--e-ghost-hi); }
.chat-faq-btn + .chat-reset { margin-left: var(--sp-2); }
.chat-faqp { flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--sp-5) var(--sp-4); background: var(--c-surface); }
.chat-faqp[hidden] { display: none; }
.chat-faqp-hd { position: sticky; top: 0; display: flex; align-items: baseline; gap: var(--sp-2); padding: var(--sp-4) 0 var(--sp-2); background: var(--c-surface); }
.chat-faqp-hd b { font-size: var(--fs-16); }
.chat-faqp-hd span { font-size: var(--fs-13); color: var(--c-text-3); }
.chat-faqp-x { margin-left: auto; padding: 0; border: 0; background: none; font: inherit; font-size: var(--fs-13); font-weight: 700; color: var(--c-text-3); cursor: pointer; }
.chat-bubbles .chat-faqp:not([hidden]) ~ .chat-log { display: none; }
.chat-bubbles .chat-form { border-top: 1px solid var(--c-line-soft); }
.chat-bubbles .chat-input { border-radius: var(--r-pill); padding-left: var(--sp-5); }
.chat-bubbles .chat-contact { align-self: stretch; padding: var(--sp-4) var(--sp-5); border-radius: var(--r-l); background: var(--c-surface); box-shadow: var(--e1); }
/* 埋め込みの幅が狭いとき（key-sales.jp の LP のスマホの窓など。2026-11-14）: 上の帯を1行に収め、閉じるを必ず見せる。幅は決まりの 767px */
@media (max-width: 767px) {
  .chat-embed .chat-hd-in { gap: 6px; padding: 0 var(--sp-2) 0 var(--sp-4); }
  .chat-embed .chat-sys { display: none; }
  .chat-embed .chat-faq-btn { padding: 0 var(--sp-3); font-size: 12px; }
  .chat-embed .chat-reset .ui-btn-t { font-size: 12px; white-space: nowrap; }
  .chat-embed .chat-faq-btn + .chat-reset { margin-left: 0; }
  .chat-embed .chat-close { flex: none; }
}

/* 2026-11-22 板垣さん「サポートエージェントの UI、チャット画面をもっと欲しいってなるデザインに」
   key SALES の窓口（body.chat-bubbles）だけ。色と影は style.css の :root の --ks-*（key-sales.jp のトンマナ）。
   すりガラス（backdrop-filter）・ポチマーク・色を敷いた札は使わない */
body.chat-page.chat-bubbles { background: var(--ks-bg); }
.chat-bubbles .chat-hd { background: var(--c-surface); box-shadow: var(--e-ks); }
.chat-bubbles.chat-embed .chat-hd { position: relative; z-index: var(--z-sticky); border-bottom: 0; box-shadow: var(--e-ks-hd); }
.chat-bubbles.chat-embed .chat-hd::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--ks-g); }
.chat-bubbles .chat-wm { color: var(--ks-navy); letter-spacing: .1em; }
.chat-bubbles .chat-hd .chat-av { box-shadow: var(--e-ks-av); }
.chat-bubbles .chat-faq-btn { background: var(--c-surface); box-shadow: var(--e-ks-line); color: var(--ks-navy); }
.chat-bubbles .chat-faq-btn[aria-expanded="true"] { box-shadow: var(--e-ks-line-hi); }

/* 会話の地：淡い水色に、ミントと青の光をにじませる */
.chat-bubbles .chat-log { background: var(--ks-log-bg); gap: var(--sp-4); padding-top: var(--sp-5); padding-bottom: var(--sp-5); }

/* 頭の紹介 */
.chat-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--sp-1) 0 var(--sp-2); animation: ksIn .5s cubic-bezier(.2, .7, .2, 1) both; }
.chat-hero-av { position: relative; width: 72px; height: 72px; border-radius: 50%; padding: 3px; background: var(--ks-g); box-shadow: var(--e-ks-glow); }
.chat-hero-av::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 1.5px solid var(--ks-cyan-a); animation: ksRing 2.8s ease-out infinite; }
.chat-hero-av img { display: block; width: 100%; height: 100%; border-radius: 50%; border: 1.5px solid var(--c-surface); background: var(--c-surface); }
.chat-hero-t { margin: var(--sp-3) 0 var(--sp-hair); font-size: var(--fs-16); font-weight: 900; letter-spacing: .04em; color: var(--ks-navy); }
.chat-hero-s { margin: 0; font-size: var(--fs-12); font-weight: 700; line-height: 1.6; color: var(--ks-sub); }
@keyframes ksRing { 0% { transform: scale(.92); opacity: .9; } 100% { transform: scale(1.25); opacity: 0; } }
@keyframes ksIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 吹き出し */
.chat-bubbles .chat-msg { animation: ksIn .38s cubic-bezier(.2, .7, .2, 1) both; }
.chat-bubbles .chat-who { color: var(--ks-sub); }
.chat-bubbles .chat-who .chat-av { width: 22px; height: 22px; box-shadow: var(--e-ks-av); }
.chat-bubbles .chat-text { padding: var(--sp-3) var(--sp-4); border-radius: var(--r-l) var(--r-l) var(--r-l) 0; background: var(--c-surface); box-shadow: var(--e-ks); color: var(--ks-navy); font-size: var(--fs-14); line-height: 1.75; }
.chat-bubbles .chat-msg.is-them .chat-text { border-radius: var(--r-l) var(--r-l) 0 var(--r-l); background: var(--ks-g); box-shadow: var(--e-ks-me); color: var(--c-on-dark); font-weight: 700; }
.chat-bubbles .chat-msg.is-staff .chat-text { box-shadow: var(--e-ks-staff); }
.chat-bubbles .chat-wait .chat-text { color: transparent; background: var(--e-ksim) 0 0 / 200% 100% no-repeat; -webkit-background-clip: text; background-clip: text; box-shadow: none; padding-left: var(--sp-1); animation: ksShim 1.4s linear infinite; }
@keyframes ksShim { to { background-position: -200% 0; } }

/* よくある質問：白い行に、Q の印と矢印。押すとその答えが返る */
.chat-bubbles .chat-faq-h { margin: var(--sp-4) 0 var(--sp-2); font-size: var(--fs-12); letter-spacing: .12em; color: var(--ks-sub); }
.chat-bubbles .chat-msg .chat-faq { flex-direction: column; flex-wrap: nowrap; gap: var(--sp-2); }
.chat-bubbles .chat-msg .chat-faq-q {
  position: relative; display: flex; align-items: center; justify-content: flex-start; gap: var(--sp-3); width: 100%; min-height: 52px;
  padding: var(--sp-2) 40px var(--sp-2) var(--sp-3); border-radius: var(--r-m); background: var(--c-surface); box-shadow: var(--e-ks-q);
  font-size: var(--fs-14); line-height: 1.5; color: var(--ks-navy); text-align: left;
  transition: transform .18s ease, box-shadow .18s ease;
}
.chat-bubbles .chat-msg .chat-faq-q::before {
  content: "Q"; flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--ks-g); color: var(--c-on-dark); font-size: var(--fs-14); font-weight: 900; box-shadow: var(--e-ks-glow-s);
}
.chat-bubbles .chat-msg .chat-faq-q::after {
  display: block; content: ""; position: absolute; right: var(--sp-4); top: 50%; width: 7px; height: 7px; margin-top: -4px;
  border-top: 1.5px solid var(--ks-cyan); border-right: 1.5px solid var(--ks-cyan); transform: rotate(45deg);
}
.chat-bubbles .chat-msg .chat-faq-q:hover { transform: translateY(-1px); box-shadow: var(--e-ks-q-hi); color: var(--ks-navy); }
.chat-bubbles .chat-msg .chat-faq-q:active { transform: scale(.985); }
.chat-bubbles .chat-faq-more { margin-top: var(--sp-3); color: var(--ks-link); text-decoration: none; }
.chat-bubbles .chat-faq-more::after { content: " ›"; }
.chat-bubbles .chat-faqp, .chat-bubbles .chat-faqp-hd { background: var(--ks-bg-2); }

/* 入力欄：丸い枠に、送るはグラデーションの丸 */
.chat-bubbles .chat-form { align-items: center; border-top: 0; background: var(--c-surface); box-shadow: var(--e-ks-form); }
.chat-bubbles .chat-input { min-height: 48px; padding-top: 11px; padding-bottom: 11px; border: 1.5px solid var(--ks-line); background: var(--ks-bg-2); color: var(--ks-navy); }
.chat-bubbles .chat-input:focus { border-color: var(--ks-cyan); outline: 0; background: var(--c-surface); box-shadow: var(--e-ks-focus); }
.chat-bubbles .chat-send { justify-content: center; width: 48px; height: 48px; min-width: 0; padding: 0; border: 0; border-radius: 50%; background: var(--ks-g); box-shadow: var(--e-ks-me); }
.chat-bubbles .chat-send .ui-btn-t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.chat-bubbles .chat-send .ui-btn-ar { width: auto; height: auto; background: transparent; }
.chat-bubbles .chat-send .ui-btn-ar .ic { width: 20px; height: 20px; stroke: var(--c-on-dark); stroke-width: 2.2; }
.chat-bubbles .chat-send:disabled { opacity: .45; }
.chat-bubbles .chat-contact { box-shadow: var(--e-ks); }

@media (prefers-reduced-motion: reduce) {
  .chat-hero, .chat-bubbles .chat-msg, .chat-hero-av::before, .chat-bubbles .chat-wait .chat-text { animation: none; }
}
