/* ============================================================
   chatbot.css — AI チャットボット フローティングウィジェット
   依存: common.css の CSS 変数（--primary, --radius 等）
   ============================================================ */

/* ── FAB（フローティングアクションボタン） ────────────── */
.chatbot-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary, #1a3a5c);
  color: #fff;
  border: none;
  border-radius: 32px;
  padding: 12px 20px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}

.chatbot-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.3);
}

.chatbot-fab-icon {
  font-size: 1.1rem;
  line-height: 1;
}

/* ── チャットパネル ─────────────────────────────────────── */
.chatbot-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  z-index: 9999;
  width: 360px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-lg, 0 8px 40px rgba(0, 0, 0, 0.12));
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 0.2s, transform 0.2s;
}

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

/* パネル開閉アニメーション */
.chatbot-panel.chatbot-panel--opening {
  animation: chatbot-open 0.22s ease-out forwards;
}

.chatbot-panel.chatbot-panel--closing {
  animation: chatbot-close 0.18s ease-in forwards;
}

@keyframes chatbot-open {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes chatbot-close {
  from { opacity: 1; transform: scale(1) translateY(0); }
  to   { opacity: 0; transform: scale(0.92) translateY(8px); }
}

/* ── ヘッダー ───────────────────────────────────────────── */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary, #1a3a5c);
  color: #fff;
  padding: 14px 16px;
  flex-shrink: 0;
}

.chatbot-header-title {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.3;
}

.chatbot-header-title small {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.8;
  margin-top: 2px;
}

.chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.chatbot-header-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.chatbot-header-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}

/* 拡大状態 */
.chatbot-panel--expanded {
  width: 560px;
  max-height: 80dvh;
}

/* ── メッセージエリア ────────────────────────────────────── */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f5f5f3;
  scroll-behavior: smooth;
}

/* バブル共通 */
.chatbot-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.8125rem;
  line-height: 1.65;
  word-break: break-word;
}

/* Bot メッセージ */
.chatbot-bubble--bot {
  align-self: flex-start;
  background: #fff;
  color: var(--text, #222);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
}

/* ユーザメッセージ */
.chatbot-bubble--user {
  align-self: flex-end;
  background: var(--primary, #1a3a5c);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* 参照URLリンク */
.chatbot-source-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--primary-light, #2a5a8c);
  text-decoration: underline;
  word-break: break-all;
}

/* タイピングインジケータ */
.chatbot-typing {
  align-self: flex-start;
  background: #fff;
  border-radius: 12px 12px 12px 4px;
  padding: 10px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
}

.chatbot-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 18px;
}

.chatbot-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--primary, #1a3a5c);
  border-radius: 50%;
  opacity: 0.4;
  animation: chatbot-dot-bounce 1.2s infinite;
}

.chatbot-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-4px); opacity: 1; }
}

/* ── 入力エリア ──────────────────────────────────────────── */
.chatbot-input-area {
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e8e6e0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

.chatbot-input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chatbot-input {
  width: 100%;
  border: 1px solid #d0ccc4;
  border-radius: 8px;
  padding: 8px 12px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.8125rem;
  line-height: 1.5;
  resize: none;
  /* 2行固定（line-height 1.5 × font 13px × 2 + padding） */
  min-height: calc(1.5em * 2 + 16px);
  max-height: calc(1.5em * 2 + 16px);
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s, max-height 0.2s;
  box-sizing: border-box;
}

.chatbot-input:focus {
  border-color: var(--primary, #1a3a5c);
}

.chatbot-input::placeholder {
  color: #aaa;
  font-size: 0.75rem;
}

/* 拡大時は4行相当 */
.chatbot-panel--expanded .chatbot-input {
  min-height: calc(1.5em * 4 + 16px);
  max-height: calc(1.5em * 4 + 16px);
}

/* ── 文字カウンター ──────────────────────────────────────── */
.chatbot-char-count {
  display: block;
  text-align: right;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.68rem;
  color: #bbb;
  line-height: 1;
  transition: color 0.15s;
  user-select: none;
}

.chatbot-char-count.is-warn {
  color: #e07b00;
}

.chatbot-char-count.is-over {
  color: #c0392b;
  font-weight: 700;
}

.chatbot-send-btn {
  background: var(--primary, #1a3a5c);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  font-size: 1rem;
}

.chatbot-send-btn:hover:not(:disabled) {
  background: var(--primary-light, #2a5a8c);
}

.chatbot-send-btn:active:not(:disabled) {
  transform: scale(0.93);
}

.chatbot-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── 免責フッター ────────────────────────────────────────── */
.chatbot-disclaimer {
  padding: 6px 12px 8px;
  background: #fff;
  border-top: 1px solid #f0ede8;
  text-align: center;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.69rem;
  color: #999;
  flex-shrink: 0;
  line-height: 1.4;
}

/* ── モバイル対応 ────────────────────────────────────────── */
@media (max-width: 480px) {
  .chatbot-fab {
    bottom: 16px;
    right: 16px;
    padding: 11px 16px;
    font-size: 0.8125rem;
  }

  .chatbot-panel,
  .chatbot-panel--expanded {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 85dvh;
    border-radius: var(--radius-lg, 16px) var(--radius-lg, 16px) 0 0;
  }
}
