/* ============================================================
   Telegram風 デザインシステム
   ============================================================ */

/* Tailwindカスタムカラー */
:root {
  --tg-blue: #2aabee;
  --tg-blue-dark: #229ed9;
  --tg-bg: #ffffff;
  --tg-chat-bg: #e7ebf0;
  --tg-app-bg: #ffffff;
  --tg-msg-mine: #effdde;
  --tg-msg-other: #ffffff;
  --tg-text: #222e3a;
  --tg-text-secondary: #707991;
}

.bg-app { background-color: var(--tg-app-bg); }
.bg-chat-bg {
  background-color: var(--tg-chat-bg);
  background-image:
    radial-gradient(circle at 25% 25%, rgba(255,255,255,0.3) 1px, transparent 1px),
    radial-gradient(circle at 75% 75%, rgba(255,255,255,0.2) 1px, transparent 1px);
  background-size: 24px 24px;
}
.bg-tg-blue { background-color: var(--tg-blue); }
.bg-tg-blue-dark { background-color: var(--tg-blue-dark); }
.text-tg-blue { color: var(--tg-blue); }
.hover\:bg-tg-blue-dark:hover { background-color: var(--tg-blue-dark); }
.focus\:ring-tg-blue:focus { --tg-ring-color: var(--tg-blue); box-shadow: 0 0 0 2px var(--tg-blue); }

/* ============================================================
   レスポンシブ サイドバー / メイン切替
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { display: flex; }
  .main-area { display: none; }
  body.show-chat .sidebar { display: none; }
  body.show-chat .main-area { display: flex; }
}

/* ============================================================
   ルーム一覧アイテム
   ============================================================ */
.room-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  gap: 12px;
  transition: background-color 0.1s;
  border-bottom: 1px solid #f1f5f9;
}
.room-item:hover {
  background-color: #f8fafc;
}
.room-item.active {
  background-color: var(--tg-blue);
  color: white;
}
.room-item.active .room-name,
.room-item.active .room-preview,
.room-item.active .room-time {
  color: white;
}
.room-item.active .room-preview {
  opacity: 0.85;
}

.room-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2aabee, #229ed9);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 18px;
  flex-shrink: 0;
}
/* アバター色のバリエーション */
.avatar-c1 { background: linear-gradient(135deg, #ff885e, #ff516a); }
.avatar-c2 { background: linear-gradient(135deg, #ffcd6a, #ffa85c); }
.avatar-c3 { background: linear-gradient(135deg, #82b1ff, #665fff); }
.avatar-c4 { background: linear-gradient(135deg, #a0de7e, #54cb68); }
.avatar-c5 { background: linear-gradient(135deg, #53edd6, #28c9b7); }
.avatar-c6 { background: linear-gradient(135deg, #72d5fd, #2a9ef1); }
.avatar-c7 { background: linear-gradient(135deg, #e0a2f3, #d669ed); }

.room-info {
  flex: 1;
  min-width: 0;
}
.room-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.room-name {
  font-weight: 500;
  color: #222e3a;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-time {
  font-size: 12px;
  color: #95a3b3;
  flex-shrink: 0;
}
.room-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}
.room-preview {
  font-size: 13px;
  color: #707991;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.room-badge {
  background-color: var(--tg-blue);
  color: white;
  font-size: 11px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
}
.room-item.active .room-badge {
  background-color: white;
  color: var(--tg-blue);
}
.room-item.kicked {
  opacity: 0.5;
}

/* ============================================================
   メッセージ
   ============================================================ */
#messages {
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar {
  width: 8px;
}
#messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

.msg-row {
  display: flex;
  margin: 1px 0;
  padding: 0 4px;
}
.msg-row.mine {
  justify-content: flex-end;
}
.msg-row.other {
  justify-content: flex-start;
}
.msg-row.system {
  justify-content: center;
  margin: 8px 0;
}

.msg-bubble {
  max-width: 70%;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
  padding: 6px 10px 8px 10px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.msg-row.mine .msg-bubble {
  background-color: var(--tg-msg-mine);
  color: var(--tg-text);
  border-bottom-right-radius: 4px;
}
.msg-row.other .msg-bubble {
  background-color: var(--tg-msg-other);
  color: var(--tg-text);
  border-bottom-left-radius: 4px;
}

.msg-nickname {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--tg-blue);
}

.msg-time {
  font-size: 11px;
  color: #8a99a8;
  margin-left: 8px;
  float: right;
  margin-top: 4px;
}

.msg-content {
  display: inline;
}

.msg-image {
  max-width: 280px;
  max-height: 280px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  min-width: 200px;
}
.msg-file-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--tg-blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.msg-file-info {
  font-size: 13px;
  min-width: 0;
}
.msg-file-name {
  font-weight: 500;
  color: var(--tg-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: underline;
}
.msg-file-size {
  font-size: 11px;
  color: #8a99a8;
}

.msg-system {
  background-color: rgba(0, 0, 0, 0.4);
  color: white;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 12px;
}

.msg-deleted {
  font-style: italic;
  opacity: 0.6;
}

.msg-delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  font-size: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.msg-bubble:hover .msg-delete-btn {
  display: flex;
}

/* ============================================================
   モーダル
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal.hidden {
  display: none;
}
.modal-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 入力エリア */
textarea#msg-input {
  min-height: 40px;
}

/* ライトボックス */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* 参加者リスト (情報パネル) */
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

/* ============================================================
   新機能スタイル: リプライ / リアクション / メンション 等
   ============================================================ */

/* リプライ表示 (バブル内) */
.msg-reply {
  border-left: 3px solid var(--tg-blue);
  padding: 4px 8px;
  margin-bottom: 4px;
  background: rgba(42, 171, 238, 0.08);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.msg-reply-nick {
  font-weight: 600;
  color: var(--tg-blue);
  font-size: 12px;
}
.msg-reply-content {
  color: var(--tg-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
}
.msg-row.mine .msg-reply {
  background: rgba(42, 171, 238, 0.12);
}

/* 編集マーク */
.msg-edited {
  font-size: 10px;
  color: #8a99a8;
  margin-right: 4px;
  font-style: italic;
}

/* 既読チェックマーク */
.msg-receipt {
  display: inline-block;
  margin-left: 4px;
  font-size: 11px;
  color: #8a99a8;
}
.msg-receipt.read {
  color: var(--tg-blue);
}

/* メンション */
.mention {
  color: var(--tg-blue);
  font-weight: 600;
  background: rgba(42, 171, 238, 0.1);
  padding: 0 3px;
  border-radius: 3px;
}
.mention.self {
  background: rgba(255, 200, 0, 0.25);
  color: #b58900;
}

/* リアクション */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  padding: 2px 7px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.reaction-chip:hover {
  background: white;
}
.reaction-chip.mine {
  background: rgba(42, 171, 238, 0.15);
  border-color: var(--tg-blue);
  color: var(--tg-blue);
}
.reaction-chip-emoji { font-size: 14px; }
.reaction-chip-count { font-weight: 600; font-size: 11px; }

/* バブルアクションメニュー */
.msg-bubble {
  position: relative;
}
.msg-actions {
  position: absolute;
  top: -10px;
  display: none;
  gap: 2px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 2px;
  z-index: 5;
}
.msg-row.mine .msg-actions { right: 8px; }
.msg-row.other .msg-actions { left: 8px; }
.msg-bubble:hover .msg-actions { display: flex; }
.msg-action-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #707991;
  cursor: pointer;
  border: none;
  background: transparent;
}
.msg-action-btn:hover {
  background: #f1f5f9;
  color: var(--tg-blue);
}

/* 検索結果アイテム */
.search-result-item {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  font-size: 13px;
}
.search-result-item:hover {
  background: #f8fafc;
}
.search-result-meta {
  font-size: 11px;
  color: #8a99a8;
  margin-bottom: 2px;
}
.search-result-content {
  color: var(--tg-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-highlight {
  background: rgba(255, 220, 0, 0.4);
  font-weight: 600;
}

/* 入力中インジケーター */
#typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}
.typing-dots {
  display: inline-flex;
  gap: 3px;
}
.typing-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--tg-blue);
  animation: typingPulse 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 typingPulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* メンションドロップダウン */
#mention-dropdown {
  background: white;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}
.mention-item.active,
.mention-item:hover {
  background: #f1f5f9;
}
.mention-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
  color: white;
  flex-shrink: 0;
}

/* 絵文字ピッカー */
#emoji-picker-container {
  width: 320px;
  max-height: 280px;
  overflow-y: auto;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  padding: 8px;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}
.emoji-cell {
  font-size: 22px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  background: transparent;
  border: none;
}
.emoji-cell:hover {
  background: #f1f5f9;
}
.emoji-section-title {
  font-size: 11px;
  color: #8a99a8;
  text-transform: uppercase;
  margin: 6px 4px 2px 4px;
  font-weight: 600;
}

/* リアクションミニピッカー */
#reaction-picker {
  pointer-events: auto;
}
.reaction-pick-btn {
  font-size: 22px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  border: none;
  transition: transform 0.15s;
}
.reaction-pick-btn:hover {
  background: #f1f5f9;
  transform: scale(1.2);
}

/* ピン/ミュートマーク (ルームリスト) */
.room-name-icons {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.room-pin-icon { color: #f59e0b; font-size: 11px; }
.room-mute-icon { color: #94a3b8; font-size: 11px; }

/* ルーム情報モーダル: ルームアバター画像 */
.room-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* プロフィールアバター プレビュー */
#profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ハイライト (検索遷移時) */
.msg-row.highlight .msg-bubble {
  animation: highlightFlash 1.5s ease-out;
}
@keyframes highlightFlash {
  0%, 30% { background-color: rgba(255, 220, 0, 0.5); }
  100% { background-color: inherit; }
}

/* メンバーアバター画像 */
.member-avatar img,
.chat-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ============================================================
   管理ダッシュボード
   ============================================================ */
.admin-modal {
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.admin-body {
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.admin-tabs {
  scrollbar-width: thin;
}
.admin-tab {
  padding: 0.5rem 0.875rem;
  border-radius: 9999px;
  font-size: 0.8125rem;
  color: #475569;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s;
  background: transparent;
  border: none;
  cursor: pointer;
}
.admin-tab:hover { background: #e2e8f0; }
.admin-tab.active {
  background: #2aabee;
  color: #ffffff;
}
.admin-tab.active:hover { background: #229ed9; }

.stat-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 0.75rem;
  text-align: center;
}
.stat-num {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.1;
}
.stat-lbl {
  font-size: 0.6875rem;
  color: #64748b;
  margin-top: 0.25rem;
}

.badge-status {
  display: inline-block;
  font-size: 0.6875rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-weight: 500;
}

/* ============================================================
   トースト
   ============================================================ */
@keyframes fadein {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-fadein {
  animation: fadein 0.25s ease-out;
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

/* ============================================================
   QR コード全画面モード
   ============================================================ */
#qr-fullscreen-overlay {
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ============================================================
   スマホ最適化
   ============================================================ */
@media (max-width: 768px) {
  /* セーフエリア対応 */
  .modal-card {
    max-height: 92vh;
    border-radius: 1rem 1rem 0 0;
    margin-bottom: 0;
    align-self: flex-end;
    width: 100%;
    max-width: 100% !important;
  }
  .modal {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  /* タップ領域を確保 */
  button, .room-item, .admin-tab {
    -webkit-tap-highlight-color: transparent;
    min-height: 36px;
  }
  /* スクロール慣性 */
  #messages, .admin-body, #room-list, .modal-card {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  /* 入力欄キーボード追従 */
  #msg-form {
    padding-bottom: env(safe-area-inset-bottom, 0.5rem);
  }
  /* 上部ヘッダーセーフエリア */
  #sidebar > div:first-child,
  #chat-view > div:first-child {
    padding-top: max(0.75rem, env(safe-area-inset-top, 0.75rem));
  }
  /* iOS の文字拡大対策 */
  input[type="text"], input[type="password"], input[type="number"], textarea {
    font-size: 16px !important;
  }
  /* 管理ダッシュボードの統計をぎっしり */
  .stat-card { padding: 0.625rem 0.5rem; }
  .stat-num { font-size: 1.0625rem; }
}

/* スマホ用ボトムナビ風ボタン強化 */
@media (max-width: 768px) {
  #send-btn {
    width: 44px;
    height: 44px;
    border-radius: 9999px;
  }
}

/* スワイプ操作のヒント (オプション) */
.swipeable {
  touch-action: pan-y;
}

/* ============================================================
   PWA インストールバナー
   ============================================================ */
.pwa-install-banner {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  border-radius: 9999px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  padding: 0.5rem 1rem;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
