/* ===== Chat Styles ===== */

/* チャットページ全体: page.active の中で flex:1 を使って全高を占める */
#page-chat {
  overflow: hidden;
}

.chat-layout {
  display: flex;
  width: 100%;
  height: 100%;          /* page-chat の高さいっぱい */
  overflow: hidden;
}

/* ============================
   左サイドバー（ルーム一覧）
   ============================ */
.chat-sidebar {
  width: 280px;
  min-width: 220px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  flex-shrink: 0;
  height: 100%;
}

.chat-sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-sidebar-header h3 {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 10px;
}

.chat-search {
  position: relative;
}

.chat-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

.chat-search .input {
  padding-left: 32px;
  font-size: 13px;
}

.chat-room-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.chat-room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
  border-radius: var(--radius-sm);
  margin: 1px 6px;
  position: relative;
}

.chat-room-item:hover  { background: var(--bg-hover); }
.chat-room-item.active { background: rgba(108,99,255,0.12); box-shadow: inset 2px 0 0 var(--primary); }

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

.chat-room-name {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-preview {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-room-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.chat-room-time {
  font-size: 10px;
  color: var(--text-muted);
}

.chat-unread-badge {
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ============================
   右メインエリア
   ============================ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  min-width: 0;
}

/* ヘッダー */
.chat-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  flex-shrink: 0;
  min-height: 54px;
}

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

.chat-header-name {
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-status {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ============================
   メッセージエリア
   ============================ */
.messages-container {
  flex: 1;          /* 残り高さを全部使う */
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* 下から積み上げにする */
  justify-content: flex-start;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-row.mine {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
}

.msg-avatar.hidden { visibility: hidden; }

.msg-bubble {
  max-width: 60%;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-row.mine   .msg-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-bottom-right-radius: 4px;
}
.msg-row.theirs .msg-bubble {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg-image {
  max-width: 220px;
  max-height: 220px;
  border-radius: 10px;
  cursor: pointer;
  object-fit: cover;
  display: block;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.msg-row.mine .msg-meta { flex-direction: row-reverse; }

.msg-time  { font-size: 10px; color: var(--text-muted); }
.msg-read  { font-size: 11px; color: var(--accent); }
.msg-read.unread { color: var(--text-muted); }

.msg-sender-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-light);
  margin-bottom: 2px;
  margin-left: 36px;
}

.msg-system {
  text-align: center;
  padding: 5px 14px;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255,255,255,0.03);
  border-radius: 20px;
  margin: 6px auto;
  max-width: 280px;
}

/* ============================
   入力中インジケーター
   ============================ */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 6px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.typing-indicator.visible { display: flex; }

.typing-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s ease infinite;
}

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

@keyframes typingBounce {
  0%, 100% { transform: translateY(0);  opacity: 0.4; }
  50%       { transform: translateY(-4px); opacity: 1; }
}

/* ============================
   入力エリア（常に画面下に固定）
   ============================ */
.chat-input-area {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;          /* 絶対に縮まない */
}

/* 送信ボタンも入力欄に合わせて大きく */
.send-btn {
  width: 48px !important;
  height: 48px !important;
  font-size: 19px !important;
}

/* 画像プレビュー */
.img-preview-wrap {
  display: none;
  position: relative;
  margin-bottom: 8px;
  width: 72px;
  height: 72px;
}

.img-preview-wrap.visible { display: block; }

.img-preview {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.img-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: var(--danger);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: pointer;
  color: white;
  border: 2px solid var(--bg-card);
}

/* 入力行 */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  min-height: 60px;
  max-height: 160px;
  font-size: 14px;
  padding: 12px 16px;
  border-radius: 22px;
  overflow-y: auto;
  line-height: 1.6;
  font-family: inherit;
}

/* 送信ボタン */
.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: none;
  cursor: pointer;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 12px rgba(108,99,255,0.35);
  color: white;
}

.send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 18px rgba(108,99,255,0.5);
}

/* ============================
   空状態（ルーム未選択）
   ============================ */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
}

.chat-empty .empty-emoji { font-size: 64px; }

/* ============================
   戻るボタン（モバイル）
   ============================ */
.back-to-rooms {
  display: none;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ============================
   画像ライトボックス
   ============================ */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
}

/* ============================
   モバイル対応
   ============================ */
@media (max-width: 640px) {
  .chat-sidebar {
    width: 100%;
    position: absolute;
    z-index: 10;
    height: 100%;
    transition: transform 0.3s ease;
  }

  .chat-sidebar.hidden-mobile {
    display: none;
  }

  .chat-main {
    width: 100%;
  }

  .back-to-rooms {
    display: flex !important;
  }

  .msg-bubble {
    max-width: 78%;
  }
}
