/* ================================================================
   chat.css - チャット画面専用スタイル
================================================================ */

/* ---- Layout ---- */
.app-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 60px 1fr;
  height: 100vh;
  max-height: 100vh;   /* ページ全体スクロールを防ぐ */
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ---- Top Header ---- */
.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  z-index: 100;
  /* position:sticky は overflow:hidden の親内では無効 → 削除してグリッド行計算を安定させる */
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.header-brand img { width: 36px; height: 36px; }
.header-brand-text {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.header-brand-sub {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--transition);
}
.header-user .avatar {
  width: 36px;
  height: 36px;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.header-user:hover { border-color: var(--border-amber); }
.header-user-name { font-size: 0.8rem; color: var(--text-secondary); }

/* ---- Sidebar ---- */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  min-height: 0;   /* グリッド内でflexがはみ出さないよう */
}
.sidebar-section {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.room-list {
  flex: 1;
  min-height: 0;   /* flex子でoverflow-y:autoが効くために必須 */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px;
}
.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.room-item:hover { background: var(--bg-elevated); }
.room-item.active {
  background: var(--amber-subtle);
  border: 1px solid var(--border-amber);
}
.room-item.active .room-name { color: var(--amber); }
.room-icon { font-size: 1.1rem; flex-shrink: 0; }
.room-info { flex: 1; min-width: 0; }
.room-name { font-size: 0.85rem; font-weight: 500; color: var(--text-primary); truncate: 1; }

.tag-pill {
  display: inline-block;
  padding: 1px 6px;
  background: rgba(244,166,32,0.12);
  color: var(--amber);
  border-radius: 999px;
  font-size: 0.65rem;
  margin-right: 3px;
  border: 1px solid rgba(244,166,32,0.25);
}
.room-category { font-size: 0.7rem; color: var(--text-muted); }
.room-badge {
  width: 8px;
  height: 8px;
  background: var(--amber);
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(244,166,32,0.6);
}

/* Category filter */
.category-filters {
  display: flex;
  flex-wrap: nowrap;        /* 折り返し禁止 → 1行固定 */
  gap: 5px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  scrollbar-width: none;    /* Firefox */
  -ms-overflow-style: none; /* IE */
}
.category-filters::-webkit-scrollbar { display: none; } /* Chrome/Safari */
.category-btn {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}
.category-btn:hover { border-color: var(--border-amber); color: var(--amber); }
.category-btn.active { background: var(--amber-subtle); color: var(--amber); border-color: var(--border-amber); }

/* ---- Main Chat Area ---- */
.chat-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-dark);
  height: 100%;
  min-height: 0;   /* グリッドセル内でオーバーフローしないよう */
}

/* Chat header */
.chat-header {
  padding: 14px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-room-info { display: flex; align-items: center; gap: 12px; }
.chat-room-icon { font-size: 1.4rem; }
.chat-room-name { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.chat-room-desc { font-size: 0.75rem; color: var(--text-muted); }
.chat-room-tags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  box-sizing: border-box;
}
.messages-date-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}
.messages-date-divider::before, .messages-date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.messages-date-divider span { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; }

.message-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 2px 0;
}
.message-row.own { flex-direction: row-reverse; }
.message-avatar-wrap { display: none; }
.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}
.message-row.own .message-meta { flex-direction: row-reverse; }
.message-author { font-size: 0.76rem; font-weight: 600; color: var(--text-secondary); }

/* チャット内ユーザー名（吹き出し上部） */
.message-username {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
  padding-left: 2px;
  letter-spacing: 0.02em;
}
.message-time   { font-size: 0.75rem; color: var(--text-muted); }

.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.message-bubble {
  max-width: 100%;
  padding: 9px 14px;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  word-break: break-word;
  position: relative;
}
.message-row.own .message-bubble {
  background: var(--bg-elevated);
  border-color: var(--border-amber);
  border-bottom-right-radius: 4px;
}
.message-row:not(.own) .message-bubble { border-bottom-left-radius: 4px; }
/* 削除ボタン：バブルの横に常時表示 */
.msg-delete-btn {
  opacity: 0;
  align-self: center;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.message-row:hover .msg-delete-btn { opacity: 1; }
.msg-delete-btn:hover {
  color: #ef5350;
  background: rgba(239,83,80,0.12);
}

/* Message media */
.message-image {
  max-width: 300px;
  max-height: 250px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform var(--transition);
  display: block;
  object-fit: cover;
}
.message-image:hover { transform: scale(1.02); }
.message-video {
  max-width: 300px;
  border-radius: var(--radius-md);
  display: block;
}
.message-tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; }

/* System message */
.message-system {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 6px 16px;
  background: var(--bg-surface);
  border-radius: 999px;
  align-self: center;
  border: 1px solid var(--border);
}

/* ---- Input Area ---- */
.input-area {
  padding: 16px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.preview-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-amber);
}
.preview-item img, .preview-item video {
  height: 80px;
  max-width: 120px;
  object-fit: cover;
  display: block;
}
.preview-remove {
  position: absolute;
  top: 2px; right: 2px;
  width: 18px; height: 18px;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tag-input-area {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border: 1px solid var(--border);
  min-height: 36px;
  display: none;
}
.tag-input-area.active { display: flex; }
.tag-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: var(--amber-subtle);
  border: 1px solid var(--border-amber);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--amber);
}
.tag-chip button {
  background: none;
  border: none;
  color: var(--amber-dim);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0;
  line-height: 1;
}
.tag-text-input {
  background: none;
  border: none;
  outline: none;
  font-size: 0.8rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  flex: 1;
  min-width: 80px;
}
.tag-text-input::placeholder { color: var(--text-muted); }
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 14px;
  transition: border-color var(--transition);
}
.input-row:focus-within { border-color: var(--amber-dim); }
.message-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  resize: none;
  line-height: 1.5;
  max-height: 40vh;
  min-height: 20px;
  overflow-y: auto;
}
.message-textarea::placeholder { color: var(--text-muted); }
.input-tools { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.send-btn {
  width: 38px; height: 38px;
  background: var(--amber);
  border: none;
  border-radius: var(--radius-md);
  color: var(--bg-deep);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.send-btn:hover { background: #ffbe45; transform: scale(1.05); }
.send-btn:disabled { background: var(--bg-elevated); color: var(--text-muted); transform: none; cursor: default; }

/* ---- Empty state ---- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  text-align: center;
}
.empty-icon { font-size: 3rem; opacity: 0.4; }

/* ---- Right Panel (room info) ---- */
.right-panel {
  width: 260px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(260px);
  transition: transform 0.3s ease;
  position: absolute;
  right: 0;
  top: 60px;
  bottom: 0;
  z-index: 50;
}
.right-panel.open { transform: translateX(0); }
.right-panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.members-list { padding: 12px; overflow-y: auto; }
.member-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm); }
.member-item:hover { background: var(--bg-elevated); }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #4caf50; flex-shrink: 0; }

/* ---- Image lightbox ---- */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.lightbox.active { opacity: 1; pointer-events: all; }
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius-md); object-fit: contain; }
.lightbox-close { position: absolute; top: 20px; right: 20px; }

/* ---- Typing indicator ---- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  height: 24px;
}
.typing-dots { display: flex; gap: 3px; }
.typing-dots span {
  width: 5px; height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---- New room modal extra ---- */
.icon-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.icon-option {
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 1.1rem;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
}
.icon-option:hover, .icon-option.selected { border-color: var(--border-amber); background: var(--amber-subtle); }

/* ---- No room selected state ---- */
.no-room-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 20px;
  text-align: center;
  padding: 40px;
}
.no-room-state .big-icon { font-size: 5rem; opacity: 0.2; }
.no-room-state h2 { font-family: var(--font-serif); color: var(--text-secondary); }

/* ---- Room delete button ---- */
.room-delete-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border: none;
  background: rgba(239,83,80,0.15);
  color: #ef5350;
  border-radius: 50%;
  font-size: 0.65rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  margin-left: auto;
  line-height: 1;
}
.room-item:hover .room-delete-btn { display: flex; }
.room-delete-btn:hover { background: rgba(239,83,80,0.35); transform: scale(1.1); }

/* ---- Room creator ---- */
.room-creator { font-size: 0.65rem; color: var(--text-muted); margin-bottom: 2px; }

/* ---- User Profile Modal ---- */
.user-profile-modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.user-profile-modal-overlay.active { display: flex; }

.user-profile-modal-card {
  background: var(--bg-secondary, #0f1525);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 28px;
  width: 400px;
  max-width: 92vw;
  position: relative;
  animation: modal-in .18s ease;
}
@keyframes modal-in {
  from { opacity:0; transform:scale(.94) translateY(8px); }
  to   { opacity:1; transform:scale(1)  translateY(0); }
}

.user-profile-close {
  position: absolute; top: 12px; right: 12px;
  background: rgba(255,255,255,0.06);
  border: none; border-radius: 50%;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-muted);
}
.user-profile-close:hover { background: rgba(255,255,255,0.12); }

.profile-sns-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.profile-sns-btn:hover { background: rgba(255,255,255,0.14); color: var(--text-primary); }

/* SNS未登録グレーアウト */
.profile-sns-disabled {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  color: rgba(255,255,255,0.18);
  cursor: not-allowed;
}

/* ---- 管理者削除ボタン ---- */
.admin-delete-btn {
  color: rgba(239, 83, 80, 0.6) !important;
}
.admin-delete-btn:hover {
  color: #ef5350 !important;
}

/* ================================================================
   チャットメッセージ動的エフェクト
================================================================ */

/* 新着メッセージフェードインスライド：.msg-animate クラスのみに適用 */
.message-row.msg-animate {
  opacity: 0;
  animation: msgReveal 0.38s cubic-bezier(0.22,1,0.36,1) forwards;
}
@keyframes msgReveal {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* 自分のメッセージは右から */
.message-row.own.msg-animate {
  animation: msgRevealOwn 0.38s cubic-bezier(0.22,1,0.36,1) forwards;
}
@keyframes msgRevealOwn {
  from { opacity: 0; transform: translateX(16px) scale(0.98); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* メッセージバブルホバー */
.message-bubble {
  transition: box-shadow 0.2s ease, transform 0.15s ease !important;
}
.message-bubble:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.4) !important;
}

/* 送信ボタン送信アニメーション */
@keyframes sendPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(0.85) rotate(-8deg); }
  70%  { transform: scale(1.15) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}
.send-pop { animation: sendPop 0.35s cubic-bezier(0.34,1.56,0.64,1); }

/* ================================================================
   CHAT RESPONSIVE OVERHAUL
================================================================ */

/* ---- タブレット ---- */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 60px 1fr;
    max-height: 100vh;
    overflow: hidden;
  }
  .sidebar {
    position: fixed;
    left: 0; top: 60px; bottom: 0;
    width: 80vw; max-width: 300px;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.22,1,0.36,1);
    z-index: 200;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed; inset: 0; top: 60px;
    background: rgba(0,0,0,0.5);
    z-index: 199;
    display: none;
  }
  .sidebar-overlay.active { display: block; }
  .header-menu-btn { display: flex !important; }
  .bubble-wrap { max-width: 70vw; }
  .message-bubble { max-width: 100%; }
}
@media (min-width: 769px) {
  .header-menu-btn { display: none; }
}

/* ---- スマホ ---- */
@media (max-width: 600px) {
  /* ヘッダー: fixed 固定 */
  .app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    padding: 0 10px;
    z-index: 200;
  }
  /* fixed になったヘッダーはグリッドフローから外れるので、
     grid-template-rows から header 行を削除し padding-top で補う */
  .app-layout {
    grid-template-rows: 1fr;
    padding-top: 52px;
    box-sizing: border-box;
  }
  .header-brand img { width: 28px; height: 28px; }
  .header-brand-text, .header-brand-sub { display: none; }
  .header-user-name { display: none; }
  .header-user      { padding: 4px 8px 4px 4px; }
  .sidebar          { top: 52px; }
  .sidebar-overlay  { top: 52px; }

  /* ナビ: アイコンのみ */
  .nav-item { padding: 5px 7px; gap: 0; }
  .nav-item span:not(#dm-nav-badge) { display: none; }
  .nav-item svg { width: 17px; height: 17px; }

  /* チャット入力エリア */
  .chat-input-area { padding: 8px 10px; gap: 6px; }
  .chat-input { font-size: 16px; padding: 8px 12px; }
  .send-btn { min-width: 38px; min-height: 38px; padding: 8px; }

  /* メッセージ吹き出し: 画面幅の70% */
  .bubble-wrap    { max-width: 70vw; }
  .message-bubble { max-width: 100%; font-size: .85rem; padding: 8px 12px; }
  .message-author { font-size: .8rem; }
  .message-time   { font-size: .68rem; }
  .message-image  { max-width: 200px; max-height: 200px; }
  .messages-container { padding: 10px; }

  /* ルーム一覧 */
  .room-item { padding: 10px 12px; }
  .room-name  { font-size: .85rem; }

  /* プロフィールモーダル */
  .user-profile-modal-card { padding: 20px 16px; width: calc(100vw - 32px); max-height: 90vh; overflow-y: auto; }
}

/* ---- 72時間自動削除注意書き ---- */
.auto-delete-notice-mobile { display: none; }
@media (max-width: 600px) {
  .auto-delete-notice { display: none; }
  .auto-delete-notice-mobile {
    display: block;
    text-align: center;
    font-size: 0.62rem;
    color: var(--text-muted);
    opacity: 0.6;
    padding-top: 6px;
  }
}
/* ---- ↓最新ボタン ---- */
#jump-to-latest {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 18px;
  background: var(--amber);
  color: #060c18;
  border: none;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  transition: transform 0.25s cubic-bezier(0.22,1,0.36,1), opacity 0.25s;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
}
#jump-to-latest.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: all;
}
#jump-to-latest:hover { filter: brightness(1.1); }
