* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", sans-serif;
  font-size: 15px;
  background: #f5f5f5;
  color: #333;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  background: #fff;
  box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

header {
  background: #1a1a2e;
  color: #fff;
  padding: 12px 16px;
  flex-shrink: 0;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
}

header h1 span {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.7;
  margin-left: 8px;
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  display: flex;
  gap: 8px;
}

.message.customer {
  flex-direction: row-reverse;
}

.message.customer .message-content {
  display: flex;
  justify-content: flex-end;
}

.bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.6;
  word-break: break-word;
}

/* お客さまアバター（Phase B）*/
.avatar-customer {
  background: transparent;
}

/* お客さまメッセージバブル */
.message.customer .message-bubble {
  background: #1a1a2e;
  color: #fff;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  padding: 10px 14px;
  max-width: 75%;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Markdownレンダリング後の要素スタイル */
.message.assistant .bubble p { margin: 0 0 8px; }
.message.assistant .bubble p:last-child { margin-bottom: 0; }
.message.assistant .bubble ul,
.message.assistant .bubble ol { padding-left: 20px; margin: 4px 0 8px; }
.message.assistant .bubble li { margin: 2px 0; }
.message.assistant .bubble hr { border: none; border-top: 1px solid #ddd; margin: 10px 0; }
.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3 { font-size: 1em; font-weight: 600; margin: 8px 0 4px; }


.message.assistant .bubble {
  background: #f0f0f0;
  color: #333;
  border-bottom-left-radius: 4px;
}

.message.assistant .bubble a {
  color: #0066cc;
  word-break: break-all;
}

/* ストリーミング中のカーソル表示 */
.bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #999;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

footer {
  flex-shrink: 0;
  border-top: 1px solid #e0e0e0;
  padding: 12px 16px;
  background: #fff;
}

.input-area {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#user-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 20px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
}

#user-input:focus {
  border-color: #1a1a2e;
}

#send-btn {
  padding: 10px 20px;
  background: #1a1a2e;
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

#send-btn:hover { opacity: 0.85; }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ハンドオーバーバー */
#handover-bar {
  padding: 6px 16px;
  background: #f5f5f5;
  border-top: 1px solid #e0e0e0;
  text-align: right;
}

#request-handler-btn {
  padding: 6px 16px;
  background: #fff;
  border: 1px solid #1a1a2e;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  color: #1a1a2e;
}

#request-handler-btn:hover { background: #f0f0f8; }
#request-handler-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* 担当者メッセージ（Phase C: .message.handler、左側配置 ForMe と同構造）*/
.avatar-handler { background: transparent; }

.message.handler .message-bubble {
  background: #e3f2fd;
  color: #1a237e;
  border-bottom-left-radius: 4px;
}

.message.handler .message-bubble p { margin: 0 0 8px; }
.message.handler .message-bubble p:last-child { margin-bottom: 0; }
.message.handler .message-bubble a { color: #1565c0; text-decoration: underline; word-break: break-all; }
.message.handler .message-bubble ul,
.message.handler .message-bubble ol { padding-left: 20px; margin: 4px 0 8px; }
.message.handler .message-bubble li { margin: 2px 0; }
.message.handler .message-bubble hr { border: none; border-top: 1px solid #bbdefb; margin: 8px 0; }
.message.handler .message-bubble h1,
.message.handler .message-bubble h2,
.message.handler .message-bubble h3 { font-size: 1em; font-weight: 600; margin: 8px 0 4px; }

/* ===== Step 2.5: 商品提案カード化 ===== */
/* スコープ：.message.assistant .bubble ol > li のみ（論点 E：global 汚染禁止）*/

/* 既存 ol の padding-left をリセット（card 内 padding と二重になる左余白を解消）*/
.message.assistant .bubble ol {
  padding-left: 0;
  margin: 4px 0 8px;
}

.message.assistant .bubble ol > li {
  margin-bottom: 1em;
  padding: 12px 14px;
  border-left: 3px solid #0066cc;
  background: #f5f5f5;
  border-radius: 4px;
  list-style-position: inside;
}

/* 商品画像（ol > li 外の img も含む全 img）*/
.message.assistant .bubble img {
  max-width: min(280px, 100%);
  height: auto;
  display: block;
  margin: 8px 0;
  border-radius: 4px;
}

.message.assistant .bubble ol > li img {
  max-width: min(280px, 100%) !important; /* marked.js inline style を上書き */
  height: auto;
  display: block;
  margin: 8px 0;
}

.message.assistant .bubble ol > li a {
  display: inline-block;
  margin-top: 6px;
}

@media (max-width: 480px) {
  .message.assistant .bubble ol > li {
    padding: 10px 12px;
    margin-bottom: 0.8em;
  }
  .message.assistant .bubble ol > li img {
    max-width: 100% !important;
  }
  .avatar {
    width: 36px;
    height: 36px;
  }
  .message-bubble ol > li {
    padding: 10px 12px;
    margin-bottom: 0.8em;
  }
  .message-bubble ol > li img {
    max-width: 100% !important;
  }
}

/* システムメッセージ */
.message.system {
  justify-content: center;
  font-size: 12px;
  color: #888;
  font-style: italic;
  text-align: center;
  padding: 4px 0;
}

/* ===== Step 7.4 Phase A: ForMe アバター ===== */

/* アバター画像（40px 円形クロップ）*/
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  max-width: min(40px, 10vw); /* モバイル overflow 対策 */
}

.avatar-forme {
  background: #fff;
}

/* メッセージコンテンツラッパー（名前 + バブル）*/
.message-content {
  flex: 1;
  min-width: 0; /* バブル内の長い URL でオーバーフロー防止 */
}

/* 送信者名ラベル */
.message-author {
  font-size: 0.85em;
  color: #666;
  margin-bottom: 2px;
  font-weight: 500;
}

/* 時刻ラベル（担当者画面用、将来お客さま画面でも使用可）*/
.message-timestamp {
  font-size: 0.85em;
  color: #999;
  font-weight: normal;
  margin-left: 6px;
}

/* ForMe バブル本体 */
.message-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.6;
  word-break: break-word;
  background: #f0f0f0;
  color: #333;
  border-bottom-left-radius: 4px;
}

/* ストリーミング中のカーソル（.message-bubble 版）*/
.message-bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #999;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

/* message-bubble 内 Markdown スタイル */
.message-bubble p { margin: 0 0 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul,
.message-bubble ol { padding-left: 20px; margin: 4px 0 8px; }
.message-bubble li { margin: 2px 0; }
.message-bubble hr { border: none; border-top: 1px solid #ddd; margin: 10px 0; }
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 { font-size: 1em; font-weight: 600; margin: 8px 0 4px; }
.message-bubble a { color: #0066cc; word-break: break-all; }

/* message-bubble 内の商品画像 */
.message-bubble img {
  max-width: min(280px, 100%);
  height: auto;
  display: block;
  margin: 8px 0;
  border-radius: 4px;
}

/* message-bubble 内の商品提案カード（Step 2.5 パターン踏襲）*/
.message-bubble ol {
  padding-left: 0;
  margin: 4px 0 8px;
}

.message-bubble ol > li {
  margin-bottom: 1em;
  padding: 12px 14px;
  border-left: 3px solid #0066cc;
  background: #f5f5f5;
  border-radius: 4px;
  list-style-position: inside;
}

.message-bubble ol > li img {
  max-width: min(280px, 100%) !important;
  height: auto;
  display: block;
  margin: 8px 0;
}

.message-bubble ol > li a {
  display: inline-block;
  margin-top: 6px;
}
