/*
 * いい任売 AIチャット
 * ai-agent-site/static/index.html のチャットウィジェットのスタイルを移植。
 * テーマ（Bootstrap / FLOCSS）と干渉しないよう、すべて #estyle-chat-root 配下に限定している。
 */

#estyle-chat-root {
  --primary: #1e3a5f;
  --primary-dark: #142840;
  --accent: #c89858;
  --panel: #ffffff;
  --border: #e6e3dc;
  --text: #2a2a2a;
  --muted: #6f7178;
  --soft: #f3f1ec;
  --user-bubble: #1e3a5f;
  --bot-bubble: #f1eee7;
  --shadow: 0 10px 30px rgba(20, 40, 64, 0.10);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Segoe UI",
               -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  line-height: 1.7;
  text-align: left;
}
#estyle-chat-root *,
#estyle-chat-root *::before,
#estyle-chat-root *::after { box-sizing: border-box; }
#estyle-chat-root a { color: var(--primary); text-decoration: none; }
#estyle-chat-root img { max-width: none; }

/* ────────── ランチャー（ピル型・ラベル常時表示） ──────────
 * テーマの「ページの先頭へ」ボタン（右下 30px・70×84px）の真上に配置 */
#estyle-chat-root .chat-launcher {
  position: fixed; bottom: 126px; right: 24px;
  background: #fff;
  height: 64px; padding: 4px 20px 4px 6px; margin: 0;
  border-radius: 40px;
  border: none; cursor: pointer; box-shadow: var(--shadow);
  z-index: 10000;
  display: inline-flex; align-items: center; gap: 10px;
  animation: estyle-launcher-pulse 2.4s ease-in-out 1.5s 3;
  transition: transform .15s, box-shadow .15s;
  font: inherit; text-align: left;
}
#estyle-chat-root .chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(20,40,64,0.16);
  animation: none;
}
#estyle-chat-root .launcher-img {
  width: 56px; height: 56px; object-fit: cover; border-radius: 50%;
  background: var(--soft); flex-shrink: 0; display: block;
}
#estyle-chat-root .launcher-label {
  display: flex; flex-direction: column; align-items: flex-start;
  line-height: 1.15; white-space: nowrap;
}
#estyle-chat-root .launcher-label .ll-main { font-size: 14px; font-weight: 700; color: var(--primary); }
#estyle-chat-root .launcher-label .ll-sub { font-size: 10.5px; color: var(--muted); margin-top: 2px; letter-spacing: .02em; }
/* スマホ: ラベルは表示、サブは非表示 */
@media (max-width: 480px) {
  #estyle-chat-root .chat-launcher { height: 56px; padding: 4px 14px 4px 4px; gap: 8px; right: 16px; bottom: 122px; }
  #estyle-chat-root .launcher-img { width: 48px; height: 48px; }
  #estyle-chat-root .launcher-label .ll-main { font-size: 13px; }
  #estyle-chat-root .launcher-label .ll-sub { display: none; }
}
/* 起動時に3回だけ「はねる」 */
@keyframes estyle-launcher-pulse {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
  50% { transform: translateY(0); }
  70% { transform: translateY(-4px); }
}
@media (prefers-reduced-motion: reduce) {
  #estyle-chat-root .chat-launcher { animation: none; }
}

/* ヘッダーのキャラアイコン */
#estyle-chat-root .chat-header .header-id { display: flex; align-items: center; gap: 10px; }
#estyle-chat-root .header-img {
  width: 38px; height: 38px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0; background: #fff;
}
/* AI応答の左に出すキャラアバター */
#estyle-chat-root .bot-avatar {
  flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%;
  overflow: hidden; align-self: flex-start; background: #fff;
}
#estyle-chat-root .bot-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ────────── パネル ────────── */
#estyle-chat-root .chat-panel {
  position: fixed; bottom: 202px; right: 24px;
  width: min(420px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 300px));
  min-height: 360px;
  background: var(--panel); border-radius: 14px;
  box-shadow: var(--shadow); display: none;
  flex-direction: column; overflow: hidden; z-index: 10001;
  border: 1px solid var(--border);
}
#estyle-chat-root .chat-panel.open { display: flex; }

#estyle-chat-root .chat-header {
  background: var(--primary); color: #fff;
  padding: 14px 18px; display: flex; justify-content: space-between; align-items: center;
}
#estyle-chat-root .chat-header .title { font-weight: 600; font-size: 14px; line-height: 1.4; }
#estyle-chat-root .chat-header .sub { font-size: 11px; opacity: 0.8; margin-top: 2px; line-height: 1.4; }
#estyle-chat-root .chat-close {
  background: transparent; color: #fff; border: none;
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px; margin: 0;
}
#estyle-chat-root .chat-messages {
  flex: 1; overflow-y: auto; padding: 16px; background: #fcfbf8;
}
#estyle-chat-root .msg { display: flex; margin-bottom: 12px; }
#estyle-chat-root .msg.user { justify-content: flex-end; }
#estyle-chat-root .bubble {
  max-width: 80%; padding: 10px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.55; white-space: pre-wrap;
  word-break: break-word;
}
#estyle-chat-root .msg.user .bubble {
  background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px;
}
#estyle-chat-root .msg.bot .bubble {
  background: var(--bot-bubble); color: var(--text); border-bottom-left-radius: 4px;
}
#estyle-chat-root .msg.bot .bubble.error-bubble {
  background: #fff7e0; border: 1px solid #e8dcc0; color: #6b5a2a;
}

#estyle-chat-root .chat-form {
  display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border);
  background: #fff; margin: 0;
}
#estyle-chat-root .chat-form textarea {
  flex: 1; resize: none; height: 42px; max-height: 100px; margin: 0;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font: inherit; font-size: 16px; line-height: 1.35;
  color: var(--text); background: #fff; box-shadow: none;
}
#estyle-chat-root .chat-form textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
#estyle-chat-root .chat-send {
  background: var(--primary); color: #fff; border: none;
  border-radius: 8px; padding: 0 16px; margin: 0; cursor: pointer;
  font-weight: 600; font-size: 13px; font-family: inherit;
}
#estyle-chat-root .chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

#estyle-chat-root .privacy-note {
  font-size: 11px; line-height: 1.5; color: var(--muted); padding: 8px 12px; background: #fff;
  border-top: 1px solid var(--border); text-align: center; margin: 0;
}

/* 考え中インジケータ (●●● バウンス) */
#estyle-chat-root .bubble.thinking {
  display: inline-flex; gap: 5px; align-items: center;
  padding: 14px 16px;
}
#estyle-chat-root .bubble.thinking span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); display: inline-block;
  animation: estyle-thinking-bounce 1.3s infinite ease-in-out both;
}
#estyle-chat-root .bubble.thinking span:nth-child(1) { animation-delay: -0.26s; }
#estyle-chat-root .bubble.thinking span:nth-child(2) { animation-delay: -0.13s; }
@keyframes estyle-thinking-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* 3択アクションパネル (事例を見る / 相談する / 詳細を書く) */
#estyle-chat-root .action-panel {
  background: #fff !important; border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; padding: 12px 14px;
  white-space: normal;
}
#estyle-chat-root .action-btn {
  background: #fafaf7; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin: 0; font-size: 13.5px; color: var(--text);
  text-align: left; cursor: pointer; text-decoration: none;
  display: flex; align-items: center; gap: 8px; font-family: inherit;
  transition: all .15s; line-height: 1.4;
}
#estyle-chat-root .action-btn:hover { text-decoration: none; }
#estyle-chat-root .action-btn.primary { background: #eaf3ea; border-color: #c5e0c5; color: var(--primary); }
#estyle-chat-root .action-btn.primary:hover { background: #dbeadb; border-color: #a8ce9f; }
#estyle-chat-root .action-btn.contact { background: #fff3e6; border-color: #f0c48c; color: #7a5220; }
#estyle-chat-root .action-btn.contact:hover { background: #ffe9d1; }
#estyle-chat-root .action-btn.write { background: #f3f6fb; border-color: #d6e1f0; color: var(--link); }
#estyle-chat-root .action-btn.write:hover { background: #e5edf7; }
#estyle-chat-root .action-btn .btn-icon { flex-shrink: 0; }

/* 相談CTAカード (事例を見た後・電話・LINE案内) */
#estyle-chat-root .contact-cta {
  background: #fff !important; border: 2px solid var(--accent);
  border-radius: 12px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
  white-space: normal;
}
#estyle-chat-root .contact-cta-title {
  font-size: 13px; font-weight: 700; color: var(--primary);
  margin: 0; display: flex; align-items: center; gap: 6px;
}
#estyle-chat-root .contact-cta-note { font-size: 11.5px; color: var(--muted); margin: 0; line-height: 1.55; }
#estyle-chat-root .contact-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#estyle-chat-root .contact-actions a {
  flex: 1; min-width: 120px; padding: 10px 12px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
#estyle-chat-root .contact-actions .btn-tel { background: var(--accent); color: #fff !important; }
#estyle-chat-root .contact-actions .btn-tel:hover { background: #b88746; }
#estyle-chat-root .contact-actions .btn-line { background: #06C755; color: #fff !important; }
#estyle-chat-root .contact-actions .btn-line:hover { background: #059d47; }

/* スターターチップ (初回起動時のとっかかり) */
#estyle-chat-root .starter-panel {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 14px 12px; white-space: normal;
}
#estyle-chat-root .starter-title {
  font-size: 12px; color: var(--muted); font-weight: 600;
  letter-spacing: .04em; margin: 0 0 10px;
}
#estyle-chat-root .starter-chips {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px;
}
#estyle-chat-root .starter-chip {
  background: #fafaf7; border: 1px solid #e6e3dc; border-radius: 8px;
  padding: 10px 12px; margin: 0; font-size: 13.5px; color: var(--text);
  text-align: left; cursor: pointer; transition: all .15s;
  font-family: inherit; line-height: 1.4; display: flex; align-items: center; gap: 8px;
}
#estyle-chat-root .starter-chip:hover { background: #eaf1fb; border-color: var(--link); }
#estyle-chat-root .starter-chip .chip-icon { flex-shrink: 0; }
#estyle-chat-root .starter-divider {
  font-size: 11px; color: var(--muted); letter-spacing: .04em;
  margin: 0 0 8px; padding-top: 10px; border-top: 1px dashed var(--border);
}
#estyle-chat-root .starter-links { display: flex; gap: 8px; flex-wrap: wrap; }
#estyle-chat-root .starter-link {
  flex: 1; min-width: 130px; background: #f3f6fb; border: 1px solid #d6e1f0;
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; color: var(--link);
  text-decoration: none; text-align: center; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
#estyle-chat-root .starter-link:hover { background: #dfe7f4; text-decoration: none; }

/* 法務チェック関連 */
#estyle-chat-root .legal-checking {
  font-size: 11px; color: var(--muted); padding: 4px 12px;
  align-self: flex-start; font-style: italic;
}
#estyle-chat-root .legal-corrected-banner {
  background: #fff7e0; border-left: 3px solid var(--accent);
  padding: 6px 10px; font-size: 11px; color: #8a6608;
  margin-bottom: 4px; border-radius: 0 4px 4px 0;
}
#estyle-chat-root .legal-corrected-banner strong { color: var(--accent); }
#estyle-chat-root .legal-warning {
  background: #fff7e0; border: 1px solid #e8dcc0;
  padding: 8px 12px; font-size: 11.5px; color: #8a6608;
  border-radius: 6px; margin: 6px 0; align-self: flex-start;
  max-width: 90%;
}
#estyle-chat-root .legal-warning .law-tag {
  display: inline-block; background: #e8dcc0; color: #5a4500;
  padding: 1px 6px; border-radius: 3px; font-size: 10px;
  margin-right: 4px;
}

/* ────────── スマートフォン ──────────
 * テーマの固定ヘッダー（高さ60px）の下から画面いっぱいに開く */
@media (max-width: 767px) {
  #estyle-chat-root .chat-panel {
    top: 68px; bottom: 8px; left: 8px; right: 8px;
    width: auto; height: auto; min-height: 0;
  }
}
