/*
 * chat-widget.css
 * LP接客AIチャットウィジェット スタイル
 * 配色: LP デザインシステム v1 トークン（--ink, --accent-emp）に準拠
 * LP既存スタイルとの干渉を防ぐため、すべてのセレクタを .cw- プレフィックスで閉じる
 */

/* ===== CSS 変数（LP と同一トークン） ===== */
.cw-root {
  --cw-navy:        #1F2D6B;
  --cw-navy-hover:  #18244F;
  --cw-gold:        #E0A23C;
  --cw-gold-deep:   #B07D1E;
  --cw-text:        #1A2540;
  --cw-text-soft:   #5B6679;
  --cw-surface:     #F4F7FB;
  --cw-base:        #FFFFFF;
  --cw-line:        #E3E8F0;
  --cw-radius:      12px;
  --cw-shadow:      0 8px 32px rgba(31, 45, 107, 0.18);
}

/* ===== 起動ボタン ===== */
.cw-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9900;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--cw-navy);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(31, 45, 107, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  outline: none;
}
.cw-fab:hover {
  background: var(--cw-navy-hover);
  transform: scale(1.07);
}
.cw-fab:focus-visible {
  outline: 3px solid var(--cw-gold);
  outline-offset: 2px;
}
.cw-fab svg {
  width: 28px;
  height: 28px;
  fill: #FFFFFF;
}
/* 閉じるときのX表示 */
.cw-fab[aria-expanded="true"] .cw-fab-icon-open { display: none; }
.cw-fab[aria-expanded="false"] .cw-fab-icon-close { display: none; }
.cw-fab-icon-close svg { fill: #FFFFFF; }

/* 未読バッジ（将来拡張用・現在は非表示） */
.cw-badge {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  width: 14px;
  height: 14px;
  background: #E53935;
  border-radius: 50%;
  border: 2px solid var(--cw-base);
}

/* ===== パネル（共通） ===== */
.cw-panel {
  position: fixed;
  z-index: 9901;
  background: var(--cw-base);
  display: flex;
  flex-direction: column;
  box-shadow: var(--cw-shadow);
  border-radius: var(--cw-radius);
  overflow: hidden;
  transition: opacity 0.2s, transform 0.2s;
}
.cw-panel[hidden] {
  display: none;
}

/* PC レイアウト */
@media (min-width: 600px) {
  .cw-panel {
    bottom: 100px;
    right: 28px;
    width: 380px;
    height: 560px;
  }
}

/* モバイルレイアウト（画面下部から85%） */
@media (max-width: 599px) {
  .cw-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 85dvh;
    height: 85vh; /* フォールバック */
    border-radius: var(--cw-radius) var(--cw-radius) 0 0;
  }
  .cw-fab {
    bottom: 20px;
    right: 20px;
  }
}

/* ===== ヘッダー ===== */
.cw-header {
  background: var(--cw-navy);
  color: var(--cw-base);
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.cw-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== ヘッダーアバター（静止画1枚・アニメなし） ===== */
.cw-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--cw-gold);
  background: #f0ede8;
  user-select: none;
  pointer-events: none;
}

.cw-header-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  font-family: 'Noto Sans JP', sans-serif;
}
.cw-header-sub {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  font-family: 'Noto Sans JP', sans-serif;
  margin-top: 1px;
}
.cw-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.8);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  outline: none;
}
.cw-close-btn:hover { color: #fff; }
.cw-close-btn:focus-visible {
  outline: 2px solid var(--cw-gold);
}
.cw-close-btn svg {
  width: 20px;
  height: 20px;
}

/* ===== メッセージエリア ===== */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
/* スクロールバーを細く */
.cw-messages::-webkit-scrollbar { width: 4px; }
.cw-messages::-webkit-scrollbar-thumb {
  background: var(--cw-line);
  border-radius: 2px;
}

/* ===== メッセージバブル ===== */
.cw-bubble-wrap {
  display: flex;
  flex-direction: column;
}
.cw-bubble-wrap.cw-user { align-items: flex-end; }
.cw-bubble-wrap.cw-bot  {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
}

/* ===== 吹き出しアバター（静止画 img・LINE風: アイコン左・吹き出し右） ===== */
.cw-bot-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 0 0 1.5px var(--cw-gold);
  background: #f0ede8;
  user-select: none;
  pointer-events: none;
}

/* エントリーチップはアバター幅(30)+gap(8)分インデントして吹き出しと左端を揃える */
.cw-root #cw-chips-wrap { margin-left: 38px; }

.cw-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.65;
  word-break: break-word;
  font-family: 'Noto Sans JP', sans-serif;
}
.cw-bubble.cw-user {
  background: var(--cw-navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.cw-bubble.cw-bot {
  background: var(--cw-surface);
  color: var(--cw-text);
  border-bottom-left-radius: 4px;
}

/* タイピングインジケータ */
.cw-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 13px;
  background: var(--cw-surface);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.cw-dot {
  width: 7px;
  height: 7px;
  background: var(--cw-text-soft);
  border-radius: 50%;
  animation: cw-bounce 1.2s infinite ease-in-out;
}
.cw-dot:nth-child(2) { animation-delay: 0.2s; }
.cw-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes cw-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1; }
}

/* TimeRex リンクボタン */
.cw-timerex-link {
  display: inline-block;
  margin-top: 8px;
  padding: 9px 16px;
  background: var(--cw-gold);
  color: var(--cw-navy) !important;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  font-family: 'Noto Sans JP', sans-serif;
  transition: background 0.15s;
  word-break: keep-all;
}
.cw-timerex-link:hover {
  background: var(--cw-gold-deep);
  color: var(--cw-base) !important;
}

/* ===== エントリーチップ ===== */
.cw-chips {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 4px 0;
}
.cw-chip {
  display: inline-block;
  padding: 8px 14px;
  border: 1.5px solid var(--cw-navy);
  border-radius: 999px;
  background: var(--cw-base);
  color: var(--cw-navy);
  font-size: 12.5px;
  font-family: 'Noto Sans JP', sans-serif;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
  outline: none;
}
.cw-chip:hover {
  background: var(--cw-navy);
  color: #fff;
}
.cw-chip:focus-visible {
  outline: 2px solid var(--cw-gold);
  outline-offset: 2px;
}
.cw-chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== 入力フォーム ===== */
.cw-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--cw-line);
  background: var(--cw-base);
}
.cw-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
}
.cw-input {
  flex: 1;
  border: 1.5px solid var(--cw-line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: 'Noto Sans JP', sans-serif;
  color: var(--cw-text);
  background: var(--cw-base);
  resize: none;
  min-height: 40px;
  max-height: 100px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
}
.cw-input:focus {
  border-color: var(--cw-navy);
}
.cw-input:disabled {
  background: var(--cw-surface);
  color: var(--cw-text-soft);
}
/* iOS自動ズーム防止（16px未満だとフォーカス時にズームされる）
   ※ベースの .cw-input(13.5px) より後に置くこと＝media queryは特異度を上げないため前に置くと上書きされる */
@media (max-width: 599px) {
  .cw-input { font-size: 16px; }
}
.cw-send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: var(--cw-navy);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  outline: none;
}
.cw-send-btn:hover:not(:disabled) {
  background: var(--cw-navy-hover);
}
.cw-send-btn:disabled {
  background: var(--cw-line);
  cursor: not-allowed;
}
.cw-send-btn:focus-visible {
  outline: 2px solid var(--cw-gold);
  outline-offset: 2px;
}
.cw-send-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* ===== プライバシー同意カード ===== */
.cw-consent {
  background: var(--cw-surface);
  border: 1px solid var(--cw-line);
  border-radius: 12px;
  padding: 14px;
  margin: 4px 0;
  font-family: 'Noto Sans JP', sans-serif;
}
.cw-consent-head {
  font-weight: 700;
  font-size: 13px;
  color: var(--cw-text);
  margin-bottom: 8px;
}
.cw-consent-text {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--cw-text);
  margin: 0 0 8px;
}
.cw-consent-link {
  font-size: 12.5px;
  color: var(--cw-navy);
  text-decoration: underline;
}
.cw-consent-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}
.cw-consent-approve {
  padding: 9px 20px;
  background: var(--cw-gold);
  color: var(--cw-navy);
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: 'Noto Sans JP', sans-serif;
  transition: background 0.15s, color 0.15s;
}
.cw-consent-approve:hover {
  background: var(--cw-gold-deep);
  color: #fff;
}
.cw-consent-approve:focus-visible {
  outline: 2px solid var(--cw-gold);
  outline-offset: 2px;
}
.cw-consent-decline {
  padding: 9px 18px;
  background: var(--cw-base);
  color: var(--cw-text-soft);
  border: 1.5px solid var(--cw-line);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  font-family: 'Noto Sans JP', sans-serif;
  transition: border-color 0.15s;
}
.cw-consent-decline:hover {
  border-color: var(--cw-text-soft);
}
.cw-consent-declined-note {
  color: var(--cw-text-soft);
}
