/* ── 全体 ─────────────────────────────────────────── */
#app {
  background: #92afda;
  /* ビューポート固定高さにして chat-body を内部スクロール領域にする
     （min-height だけだと #app が伸びて chatBody.scrollTo が効かない） */
  height: 100vh;
  height: 100dvh;
}

/* ── ヘッダー ─────────────────────────────────────── */
.chat-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #06c755;
  padding: 0 10px 0 4px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.header-back {
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 2px;
  text-decoration: none;
  display: flex;
  align-items: center;
}

.header-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

.header-icon img,
.header-icon svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
  color: #fff;
  font-size: 20px;
}

.header-actions svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

/* ── チャット本文エリア ──────────────────────────── */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px 72px;
  display: flex;
  flex-direction: column;
  gap: 0;
  /* スクロールは有効なままバーだけ非表示 */
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* 旧Edge/IE */
}

/* Chrome / Safari / Edge */
.chat-body::-webkit-scrollbar {
  display: none;
}

/* ── メッセージグループ（同一送信者の連続） ────────── */
.msg-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}

/* ── 1行（アバター＋吹き出し＋時刻） ─────────────── */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

/* アバター：グループ内の最後のバブル行にのみ表示 */
.msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  align-self: flex-end;
}

.msg-avatar img,
.msg-avatar svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* アバター非表示のプレースホルダー（幅だけ確保） */
.msg-avatar.hidden {
  visibility: hidden;
}

/* 吹き出し＋時刻のラッパー */
.msg-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  max-width: calc(100% - 56px);
}

/* 左側吹き出し（受信） */
.msg-bubble {
  position: relative;
  background: #fff;
  border-radius: 18px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.6;
  color: #1a1a1a;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 240px;
}

/* 左側しっぽ（画像） */
.msg-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 16px;
  height: 16px;
  background: url('../images/bubble-tail.png') no-repeat 0 0;
  background-size: 16px 16px;
}

/* 時刻：吹き出しの右外・下端揃え */
.msg-time {
  font-size: 10px;
  color: rgba(0,0,0,0.4);
  white-space: nowrap;
  flex-shrink: 0;
  align-self: flex-end;
  padding-bottom: 1px;
}

/* ── 入場アニメーション ──────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-group.new {
  animation: fadeInUp 0.2s ease forwards;
}

/* ── タイピングインジケーター ─────────────────────── */
.typing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 2px 0 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.typing-indicator.visible {
  opacity: 1;
}

.typing-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

.typing-avatar img,
.typing-avatar svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.typing-dots {
  position: relative;
  background: #fff;
  border-radius: 18px;
  padding: 10px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dots::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 16px;
  height: 16px;
  background: url('../images/bubble-tail.png') no-repeat 0 0;
  background-size: 16px 16px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: #c0c0c0;
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); background: #c0c0c0; }
  30%           { transform: translateY(-5px); background: #999; }
}

/* ── トースト ─────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(0,0,0,0.72);
  color: #fff;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 20px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── フッター ─────────────────────────────────────── */
.chat-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: #f5f5f5;
  border-top: 1px solid #ddd;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
}

/* デスクトップではアプリ幅に合わせる */
@media (min-width: 601px) {
  .chat-footer {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 390px;
  }
}

.footer-icon {
  color: #888;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.footer-icon svg {
  width: 24px;
  height: 24px;
  fill: #888;
}

.footer-input {
  flex: 1;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 15px;
  color: #bbb;
  outline: none;
  font-family: inherit;
  resize: none;
  pointer-events: none;
  line-height: 1.4;
}

.footer-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #06c755;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  flex-shrink: 0;
}

.footer-send svg {
  width: 17px;
  height: 17px;
  fill: #fff;
  margin-left: 2px;
}
