/* ════════════════════════════════════════════════════════════
   _common/css/chat-bot.css
   Sprint 10 (rev3) / 実装日: 2026-05-09 / spec_revision: 3
   spec ref: 付録A Sprint 10 / F21
   ════════════════════════════════════════════════════════════
   役割:
     - .chat-bot-widget の右下固定ウィジェット（toggle ボタン + panel）
     - tokens.css の CSS カスタムプロパティのみ参照（色ハードコード禁止）
     - prefers-reduced-motion 対応
     - レスポンシブ（モバイルでほぼフルスクリーン）
   ════════════════════════════════════════════════════════════ */

/* ── ウィジェットのコンテナ（最上層 fixed） ────────────────── */
.chat-bot-widget {
  position: fixed;
  right: var(--space-6, 1.5rem);
  bottom: var(--space-6, 1.5rem);
  z-index: 9999;
  font-family: var(--font-en, 'Inter', sans-serif);
  color: var(--global-text, #EDF1FA);
}

/* ── トグルボタン（オレンジ円形 → ピル型） ────────────────── */
.chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3, 0.75rem);
  padding: 0.85rem 1.25rem;
  background: var(--color-primary);
  color: #FFFFFF;
  border: 0;
  border-radius: 999px;
  font-family: var(--font-en, 'Inter', sans-serif);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(0, 0, 0, 0.18));
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-toggle:hover,
.chat-toggle:focus-visible {
  background: var(--color-primary-h);
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.24);
  outline: none;
}

.chat-toggle:focus-visible {
  outline: 3px solid var(--global-secondary, #00B7C2);
  outline-offset: 3px;
}

.chat-status {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.85;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* パルス（ホバー外でもさり気なく目に入る・aria 状態に応じて切る） */
.chat-toggle[aria-expanded="false"]::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  border: 2px solid var(--color-primary);
  opacity: 0.4;
  animation: chat-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

.chat-toggle {
  position: relative;
}

@keyframes chat-pulse {
  0%   { transform: scale(1);    opacity: 0.45; }
  60%  { transform: scale(1.18); opacity: 0;    }
  100% { transform: scale(1.18); opacity: 0;    }
}

/* ── パネル本体 ────────────────────────────────────────── */
.chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + var(--space-3, 0.75rem));
  width: min(380px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 120px));
  background: var(--global-primary, #0F1B3D);
  background-image: linear-gradient(180deg,
    var(--global-primary-deep, #0B1428) 0%,
    var(--global-primary, #0F1B3D) 100%);
  color: var(--global-text, #EDF1FA);
  border-radius: 14px;
  box-shadow: var(--shadow-lg, 0 20px 48px rgba(0, 0, 0, 0.32));
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0, 183, 194, 0.22);
}

.chat-panel.is-open {
  display: flex;
  animation: chat-panel-in 0.22s ease-out;
}

.chat-panel[hidden] {
  display: none;
}

.chat-panel.is-open[hidden] {
  /* is-open 優先 */
  display: flex;
}

@keyframes chat-panel-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)  scale(1);     }
}

/* ── パネルヘッダ ─────────────────────────────────────── */
.chat-header {
  padding: var(--space-4, 1rem) var(--space-6, 1.5rem);
  background: var(--global-primary-mid, #16264F);
  border-bottom: 1px solid rgba(0, 183, 194, 0.22);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
}

.chat-header h3 {
  font-family: var(--font-en, 'Inter', sans-serif);
  font-size: 1rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: 0.01em;
}

.chat-header p {
  font-size: 0.78rem;
  margin: 0;
  opacity: 0.75;
}

.chat-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  opacity: 0.7;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.chat-close:hover,
.chat-close:focus-visible {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

/* ── ログ ─────────────────────────────────────── */
.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4, 1rem) var(--space-6, 1.5rem);
  display: flex;
  flex-direction: column;
  gap: var(--space-3, 0.75rem);
  min-height: 200px;
  font-size: 0.88rem;
  line-height: 1.55;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
}

/* ── メッセージバブル ─────────────────────────────────── */
.chat-msg {
  max-width: 86%;
  padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
  border-radius: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.88rem;
}

.chat-msg--bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  color: var(--global-text, #EDF1FA);
  border-bottom-left-radius: 4px;
}

.chat-msg--user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}

.chat-msg--system {
  align-self: stretch;
  max-width: 100%;
  text-align: center;
  background: rgba(0, 183, 194, 0.14);
  color: var(--global-secondary, #00B7C2);
  border: 1px solid rgba(0, 183, 194, 0.32);
  font-size: 0.78rem;
  border-radius: 8px;
}

/* ── タイピングインジケータ ──────────────────────────── */
.chat-msg.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
  background: rgba(255, 255, 255, 0.08);
}

.chat-msg.typing .dot {
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  opacity: 0.5;
  animation: chat-typing 1.2s infinite ease-in-out;
}

.chat-msg.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-msg.typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-typing {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1;   }
}

/* ── フォーム ──────────────────────────────────────── */
.chat-form {
  display: flex;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
  background: var(--global-primary-deep, #0B1428);
  border-top: 1px solid rgba(0, 183, 194, 0.22);
}

.chat-input {
  flex: 1 1 auto;
  padding: 0.6rem 0.9rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--global-text, #EDF1FA);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  font-size: 0.9rem;
  font-family: var(--font-en, 'Inter', sans-serif);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.chat-input::placeholder {
  color: rgba(237, 241, 250, 0.45);
}

.chat-input:focus {
  outline: none;
  border-color: var(--global-secondary, #00B7C2);
  background: rgba(255, 255, 255, 0.12);
}

.chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: var(--color-primary);
  color: #FFFFFF;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.chat-send:hover,
.chat-send:focus-visible {
  background: var(--color-primary-h);
  transform: scale(1.06);
  outline: none;
}

.chat-send:focus-visible {
  outline: 2px solid var(--global-secondary, #00B7C2);
  outline-offset: 2px;
}

/* ── ディスクレーマ ──────────────────────────────────── */
.chat-disclaimer {
  padding: var(--space-2, 0.5rem) var(--space-4, 1rem) var(--space-3, 0.75rem);
  margin: 0;
  font-size: 0.7rem;
  text-align: center;
  color: rgba(237, 241, 250, 0.55);
  background: var(--global-primary-deep, #0B1428);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* ── レスポンシブ ─────────────────────────────────── */
@media (max-width: 560px) {
  .chat-bot-widget {
    right: 12px;
    bottom: 12px;
  }
  .chat-toggle {
    padding: 0.7rem 1rem;
    font-size: 0.88rem;
  }
  .chat-status {
    display: none;
  }
  .chat-panel {
    width: calc(100vw - 24px);
    right: 0;
    max-height: calc(100vh - 96px);
  }
  .chat-msg {
    max-width: 92%;
  }
}

/* ── prefers-reduced-motion ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .chat-toggle,
  .chat-send,
  .chat-panel.is-open,
  .chat-msg.typing .dot {
    animation: none !important;
    transition: none !important;
  }
  .chat-toggle[aria-expanded="false"]::before {
    animation: none;
    opacity: 0;
  }
  .chat-toggle:hover,
  .chat-toggle:focus-visible,
  .chat-send:hover,
  .chat-send:focus-visible {
    transform: none;
  }
}
