/* NextCode CMS - AIチャットウィジェット */
#ncchat { position: fixed; right: 18px; bottom: 18px; z-index: 99990; font-family: inherit; }

/* 起動ボタン */
#ncchat-launcher {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--ncchat, #e21d7a); color: #fff; border: none; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
  transition: transform .15s ease, box-shadow .15s ease;
}
#ncchat-launcher:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(0, 0, 0, .26); }
#ncchat-launcher:active { transform: scale(.94); }
.ncchat-launcher-txt { font-size: 10px; font-weight: 700; letter-spacing: .05em; }

/* パネル */
/* ID指定の display:flex が UA の [hidden]{display:none} より強く効いてしまい、
   JSが hidden=true にしても閉じない不具合を防ぐ（同specificityのID指定で明示的に打ち消す）。 */
#ncchat-panel[hidden] { display: none; }
#ncchat-panel {
  position: absolute; right: 0; bottom: 72px;
  width: 360px; max-width: calc(100vw - 36px);
  height: 480px; max-height: min(70vh, 560px);
  display: flex; flex-direction: column;
  background: #fff; border-radius: 16px; overflow: hidden;
  box-shadow: 0 14px 44px rgba(0, 0, 0, .26);
  animation: ncchat-in .22s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes ncchat-in { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #ncchat-panel { animation: none; } }

.ncchat-head {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 13px; background: var(--ncchat, #e21d7a); color: #fff;
}
.ncchat-head-dot { width: 9px; height: 9px; border-radius: 50%; background: #6dff9e; box-shadow: 0 0 0 3px rgba(255, 255, 255, .25); flex: 0 0 auto; }
.ncchat-head-tx { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.ncchat-head-name { font-weight: 800; font-size: 15px; line-height: 1.2; text-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.ncchat-head-sub { font-size: 11px; opacity: .95; line-height: 1.3; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.ncchat-reset, .ncchat-close {
  flex: 0 0 auto; width: 32px; height: 32px; border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .16); color: #fff; line-height: 1; cursor: pointer;
}
.ncchat-reset { font-size: 18px; }
.ncchat-close { font-size: 20px; }
.ncchat-reset:hover, .ncchat-close:hover { background: rgba(255, 255, 255, .3); }
.ncchat-reset:active, .ncchat-close:active { transform: scale(.9); }

/* 音声ステータス（通話中バナー） */
.ncchat-vstat { display: none; text-align: center; font-size: 12.5px; font-weight: 800; color: var(--ncchat, #e21d7a); background: #f5f9f9; padding: 8px 6px; }
.ncchat-vstat.live { display: block; }
.ncchat-vstat .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #ff3b3b; margin-right: 7px; vertical-align: middle; animation: ncchat-blink 1s infinite; }
@keyframes ncchat-blink { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.ncchat-msgs { flex: 1 1 auto; overflow-y: auto; padding: 14px 12px; background: #f7f6f8; }
.ncchat-row { display: flex; margin: 0 0 10px; }
.ncchat-row-user { justify-content: flex-end; }
.ncchat-bubble {
  max-width: 82%; padding: 9px 13px; border-radius: 14px;
  font-size: 14px; line-height: 1.65; white-space: pre-wrap; word-break: break-word;
}
.ncchat-row-bot .ncchat-bubble { background: #fff; color: #333; border: 1px solid #e8e3e8; border-bottom-left-radius: 4px; }
.ncchat-row-user .ncchat-bubble { background: var(--ncchat, #e21d7a); color: #fff; border-bottom-right-radius: 4px; }
.ncchat-row-err .ncchat-bubble { background: #fff4f4; color: #b54343; border: 1px solid #f3c1c1; font-size: 13px; }

.ncchat-typing { display: inline-flex; gap: 4px; padding: 3px 2px; }
.ncchat-typing i { width: 7px; height: 7px; border-radius: 50%; background: #c9bfc9; animation: ncchat-blink 1.2s infinite; }
.ncchat-typing i:nth-child(2) { animation-delay: .2s; }
.ncchat-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes ncchat-blink { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.ncchat-inputrow { display: flex; align-items: center; gap: 8px; padding: 10px; background: #fff; border-top: 1px solid #eee; }
#ncchat-input {
  flex: 1 1 auto; resize: none; border: 2px solid #e4dde4; border-radius: 12px;
  padding: 9px 12px; font-size: 16px; line-height: 1.5; font-family: inherit; max-height: 96px;
  background: #fff; color: #333;
}
#ncchat-input:focus { outline: none; border-color: var(--ncchat, #e21d7a); }
#ncchat-send {
  flex: 0 0 auto; width: 42px; height: 42px; border: none; border-radius: 50%;
  background: var(--ncchat, #e21d7a); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s ease;
}
#ncchat-send:active { transform: scale(.92); }
#ncchat-send:disabled { background: #cdbac6; cursor: default; }

.ncchat-foot { text-align: center; font-size: 10px; color: #b5a9b1; padding: 4px 0 7px; background: #fff; }

/* モバイル: 下からのシート風 */
@media (max-width: 599px) {
  #ncchat { right: 14px; bottom: 14px; }
  #ncchat-panel {
    position: fixed; left: 10px; right: 10px; bottom: 84px;
    width: auto; height: 64vh; max-height: none;
  }
}

/* 音声チャット: 入力欄の「話す」ボタン（大きめ・押すと通話開始） */
.ncchat-mic {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--ncchat, #e21d7a); background: #fff; color: var(--ncchat, #e21d7a);
  transition: transform .1s ease;
}
.ncchat-mic:active { transform: scale(.92); }
.ncchat-mic.live { background: var(--ncchat, #e21d7a); color: #fff; border-color: var(--ncchat, #e21d7a); animation: ncchat-pulse 1.4s infinite; }
@keyframes ncchat-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,59,59,.5); } 60% { box-shadow: 0 0 0 10px rgba(255,59,59,0); } }

/* 通話中の波形（テキスト入力の代わりに表示） */
.ncchat-inputrow.live #ncchat-input, .ncchat-inputrow.live #ncchat-send { display: none; }
.ncchat-fwave { display: none; flex: 1; align-items: center; justify-content: center; gap: 12px; min-height: 44px;
  background: #f5f9f9; border: 2px solid rgba(14, 80, 80, .15); border-radius: 22px; padding: 6px 16px; }
.ncchat-inputrow.live .ncchat-fwave { display: flex; }
.ncchat-wave { display: inline-flex; align-items: center; gap: 4px; height: 30px; }
.ncchat-wave i { display: block; width: 4px; height: 30px; border-radius: 4px; background: var(--ncchat, #e21d7a);
  transform: scaleY(.2); transform-origin: center; animation: ncchat-wv 1s ease-in-out infinite; }
.ncchat-wave i:nth-child(2){animation-delay:.10s} .ncchat-wave i:nth-child(3){animation-delay:.20s} .ncchat-wave i:nth-child(4){animation-delay:.30s}
.ncchat-wave i:nth-child(5){animation-delay:.15s} .ncchat-wave i:nth-child(6){animation-delay:.25s} .ncchat-wave i:nth-child(7){animation-delay:.05s}
.ncchat-wave i:nth-child(8){animation-delay:.35s} .ncchat-wave i:nth-child(9){animation-delay:.20s} .ncchat-wave i:nth-child(10){animation-delay:.10s} .ncchat-wave i:nth-child(11){animation-delay:.30s}
@keyframes ncchat-wv { 0%,100% { transform: scaleY(.2); } 50% { transform: scaleY(1); } }
.ncchat-fwt { font-size: 13.5px; font-weight: 800; color: var(--ncchat, #e21d7a); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .ncchat-wave i { animation: none; transform: scaleY(.6); } }

/* ============================================================
   キャラクター起動ランチャー（スマホ君風・大きな立ちキャラ＋吹き出し＋左右切替）
   window.NC_CHAT.avatarFull に立ちキャラ画像がある時だけ有効
   ============================================================ */
#ncchat.has-ava { right: 20px; bottom: 20px; left: auto; }
#ncchat.has-ava.pos-left { left: 20px; right: auto; }
#ncchat.has-ava #ncchat-launcher {
  position: static; width: auto; height: auto; border-radius: 0;
  background: none; border: none; box-shadow: none; padding: 0;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  animation: ncchat-float 3.6s ease-in-out infinite;
}
#ncchat.has-ava.pos-left #ncchat-launcher { align-items: flex-start; }
#ncchat.has-ava #ncchat-launcher:active { transform: scale(.95); }
@keyframes ncchat-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
@media (prefers-reduced-motion: reduce) { #ncchat.has-ava #ncchat-launcher { animation: none; } }

/* 左右切替ボタン(⇄) */
.ncchat-side {
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; color: var(--ncchat, #0E8C86); border: 2px solid var(--ncchat, #0E8C86);
  border-radius: 999px; font-size: 13px; font-weight: 900; padding: 3px 11px; line-height: 1;
  cursor: pointer; box-shadow: 0 3px 10px rgba(14, 80, 80, .22); font-family: inherit;
  -webkit-tap-highlight-color: transparent; white-space: nowrap;
}
.ncchat-side:active { transform: scale(.92); }

/* 吹き出し（○○に聞く / タップで相談） */
.ncchat-callout {
  position: relative; background: #fff; color: var(--ncchat, #0E8C86);
  font-weight: 800; font-size: 15px; line-height: 1.2; padding: 10px 15px; border-radius: 16px;
  box-shadow: 0 6px 18px rgba(14, 80, 80, .26); white-space: nowrap; margin-right: 6px;
  border: 2px solid var(--ncchat, #0E8C86);
}
.ncchat-callout small { display: block; font-size: 10.5px; font-weight: 700; color: #FF6B4A; margin-top: 2px; opacity: .92; }
.ncchat-callout:after {
  content: ""; position: absolute; right: 26px; bottom: -9px; width: 16px; height: 16px; background: #fff;
  border-right: 2px solid var(--ncchat, #0E8C86); border-bottom: 2px solid var(--ncchat, #0E8C86); transform: rotate(45deg);
}
#ncchat.has-ava.pos-left .ncchat-callout { margin-left: 6px; margin-right: 0; }
#ncchat.has-ava.pos-left .ncchat-callout:after { left: 26px; right: auto; }
#ncchat.has-ava.is-open .ncchat-callout, #ncchat.has-ava.is-open .ncchat-side { display: none; }

/* 大きな立ちキャラ */
.ncchat-kun {
  height: 150px; width: auto; display: block; pointer-events: none;
  filter: drop-shadow(0 9px 14px rgba(14, 80, 80, .32));
  -webkit-filter: drop-shadow(0 9px 14px rgba(14, 80, 80, .32));
}
@media (max-width: 600px) { .ncchat-kun { height: 122px; } .ncchat-callout { font-size: 13px; padding: 8px 12px; } }
@media (max-width: 380px) { .ncchat-kun { height: 100px; } .ncchat-callout { display: none; } .ncchat-side { display: none; } }

/* ヘッダー／吹き出し横は「丸い顔」アバター（立ちキャラを上寄せクロップして顔を見せる） */
.ncchat-head-ava {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover; object-position: center 16%;
  border: 2px solid rgba(255, 255, 255, .85); background: #fff; flex: 0 0 auto;
}
.ncchat-head .ncchat-head-name { font-size: 15px; }
.ncchat-row-bot { align-items: flex-end; gap: 7px; }
.ncchat-row-ava {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover; object-position: center 16%; flex: 0 0 auto;
  background: #fff; border: 1.5px solid #e8e3e8; align-self: flex-end;
}
.ncchat-row-bot .ncchat-bubble { border-bottom-left-radius: 4px; }
