/* ====== CSS変数 ====== */
:root {
  --bg-primary: #FFFFFF;
  --bg-secondary: #E5E7EB;
  --bg-tertiary: #D1D5DB;
  --text-primary: #1A1A1A;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --accent: #3B82F6;
  --accent-hover: #2563EB;
  --accent-light: #EFF6FF;
  --success: #10B981;
  --danger: #EF4444;
  --border: #E5E7EB;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 0.2s ease-out;
}

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-secondary);
  overflow: hidden;
}

/* ====== レイアウト ====== */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ====== サイドバー ====== */
.sidebar {
  width: 320px;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.sidebar-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.icon-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ユーザー情報 */
.user-info {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--bg-tertiary);
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-status {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ルーム一覧 */
.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}

.room-item {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1px;
}

.room-item:hover {
  background: var(--bg-secondary);
}

.room-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.room-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 16px;
  overflow: hidden;
  flex-shrink: 0;
}

.room-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.room-icon.text-avatar {
  color: white;
  font-weight: 600;
}

.room-icon .room-initial {
  font-size: 15px;
  line-height: 1;
}

.room-item.active .room-icon:not(.text-avatar) {
  background: var(--accent);
  color: white;
}

.room-name {
  font-weight: 500;
  font-size: 13px;
  flex: 1;
}

.unread-badge {
  background: var(--danger);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ====== チャットエリア ====== */
.chat-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.chat-header {
  padding: 16px 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.room-title {
  cursor: pointer;
  transition: var(--transition);
}

.room-title:hover {
  color: var(--accent);
}

.member-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.chat-header-info {
  font-size: 13px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* メンバーアイコン一覧 */
.member-avatars {
  display: flex;
  align-items: center;
}

.member-avatars .member-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--bg-primary);
  object-fit: cover;
  background: var(--bg-tertiary);
  margin-left: -8px;
}

.member-avatars .member-avatar:first-child {
  margin-left: 0;
}

.member-count {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 2px solid var(--bg-primary);
  margin-left: -8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* メンバー一覧 */
.members-list {
  max-height: 400px;
  overflow-y: auto;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.member-item:hover {
  background: var(--bg-secondary);
}

.member-item-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--bg-tertiary);
}

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

.member-item-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-primary);
}

.member-item-username {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ====== メッセージ表示 ====== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-secondary);
}

/* 日付区切り */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0;
}

.date-separator span {
  background: var(--bg-primary);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 11px;
  color: var(--text-tertiary);
  box-shadow: var(--shadow-sm);
}

/* 未読境界線 */
.unread-separator {
  display: flex;
  align-items: center;
  margin: 16px 0;
  gap: 12px;
}

.unread-separator::before,
.unread-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--danger);
}

.unread-separator span {
  color: var(--danger);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

/* メッセージ */
.message-row {
  display: flex;
  margin-bottom: 8px;
  animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.message-row.sending {
  opacity: 0.7;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

.message-row.me .avatar {
  display: none;
}

/* BOTメッセージ */
/* BOTメッセージ（翻訳文） */
.message-row.bot .avatar {
  display: none;
}

.message-row.bot {
  margin-top: -4px;
  margin-bottom: 8px;
}

/* 他人のメッセージの翻訳（左寄せ） */
.message-row.bot:not(.me) .message-content {
  margin-left: 32px;
}

/* 自分のメッセージの翻訳（右寄せ） */
.message-row.bot.me .message-content {
  margin-right: 0;
}

/* 他人のメッセージの翻訳 */
.message-row.bot:not(.me) .bubble {
  background: var(--bg-primary);
  padding: 6px 10px;
}

.message-row.bot:not(.me) .body {
  color: var(--text-secondary);
  font-size: 13px;
}

/* 自分のメッセージの翻訳 */
.message-row.bot.me .bubble {
  background: var(--accent);
  padding: 6px 10px;
}

.message-row.bot.me .body {
  color: white;
  font-size: 13px;
}

.message-content {
  max-width: 70%;
  margin: 0 4px;
  min-width: 0;
}

/* ユーザー名（吹き出しの上） */
.sender-name {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 2px;
  margin-left: 4px;
}

/* 吹き出しと時刻のラッパー */
.bubble-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.message-row.me .bubble-wrapper {
  flex-direction: row-reverse;
}

.bubble {
  padding: 4px 8px;
  border-radius: var(--radius-lg);
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
  position: relative;
  min-width: 0;
}

.message-row.me .bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-row:not(.me):not(.bot) .bubble {
  background: var(--bg-primary);
  border-bottom-left-radius: 4px;
}

.body {
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.3;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* 時刻表示（吹き出しの横） */
.message-time {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  flex-shrink: 0;
  padding-bottom: 2px;
}

.time {
  color: var(--text-tertiary);
}

/* 過去メッセージ読み込み中 */
.loading-older,
.no-more-messages {
  text-align: center;
  padding: 12px;
  color: var(--text-tertiary);
  font-size: 12px;
}

/* 既読マーク */
.read-status {
  font-size: 11px;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.read-status.sent {
  color: var(--text-tertiary);
}

.read-status.read {
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.read-users-modal .members-list {
  max-height: 60vh;
  overflow-y: auto;
}

.message-row.me .read-status.sent {
  color: var(--text-tertiary);
}

.message-row.me .read-status.read {
  color: var(--text-secondary);
}

.read-status.sending {
  animation: pulse 1s infinite;
}

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

.message-row:not(.me) .read-status {
  display: none;
}

/* ====== ファイル添付表示 ====== */
.file-attachments {
  margin-top: 10px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.05);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: var(--transition);
}

.message-row.me .file-item {
  background: rgba(255,255,255,0.15);
}

.file-item:hover {
  background: rgba(0,0,0,0.08);
}

.message-row.me .file-item:hover {
  background: rgba(255,255,255,0.25);
}

.file-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
}

.file-icon svg {
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
}

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

.file-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  font-size: 11px;
  opacity: 0.7;
}

.file-link {
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* 画像プレビュー */
.image-preview {
  margin-top: 10px;
}

.image-preview img {
  max-width: 50%;
  max-height: 300px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.image-preview img:hover {
  transform: scale(1.02);
}

.image-preview img.sending-image {
  opacity: 0.7;
  filter: grayscale(30%);
}

.image-loading {
  padding: 40px 60px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  font-size: 12px;
  text-align: center;
}

/* 動画プレビュー */
.video-preview {
  margin-top: 10px;
}

.video-preview video {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-md);
  background: #000;
}

.video-loading {
  padding: 40px 60px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  font-size: 12px;
  text-align: center;
}

/* ====== 入力エリア ====== */
.input-area {
  padding: 16px 24px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 1000;
}

.input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.input-box {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

/* ファイル選択ボタン */
.file-select-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.file-select-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.file-select-btn svg {
  width: 16px;
  height: 16px;
}

input[type="file"] {
  display: none;
}

/* 選択ファイルプレビュー */
.selected-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selected-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.selected-file-preview {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg-tertiary);
}

.selected-file-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: 4px;
  color: var(--text-secondary);
}

.selected-file-info {
  max-width: 120px;
}

.selected-file-name {
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-file-size {
  font-size: 11px;
  color: var(--text-tertiary);
}

.remove-file-btn {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--text-tertiary);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 12px;
  transition: var(--transition);
}

.remove-file-btn:hover {
  background: var(--danger);
}

/* テキストエリア */
.text-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  transition: var(--transition);
}

.text-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

textarea {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  resize: none;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  min-height: 44px;
  max-height: 120px;
  color: var(--text-primary);
  overflow-y: auto;
}

textarea:focus {
  outline: none;
}

textarea::placeholder {
  color: var(--text-tertiary);
}

/* 送信ボタン */
.send-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--text-tertiary);
  cursor: not-allowed;
}

.send-btn svg {
  width: 20px;
  height: 20px;
}

/* ドラッグオーバー表示 */
.drop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(59, 130, 246, 0.1);
  border: 3px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: none;
}

.drop-overlay-content {
  background: var(--bg-primary);
  padding: 32px 48px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.drop-overlay-content svg {
  width: 48px;
  height: 48px;
  color: var(--accent);
  margin-bottom: 12px;
}

.drop-overlay-content p {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
}

/* ====== モーダル ====== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-primary);
  padding: 32px;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
}

.close-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* テキスト選択モーダル */
.select-text-body {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 0;
}

/* フォーム */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 14px;
  color: var(--text-primary);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
}

/* アバタープレビュー */
.avatar-preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.avatar-preview {
  width: 100px;
  height: 100px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--bg-tertiary);
}

.avatar-upload-btn {
  padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.avatar-upload-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ====== レスポンシブ（モバイル）====== */
@media (max-width: 768px) {
  /* モバイル: bodyスクロール無効化 */
  html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease-out;
    width: 85%;
    max-width: 320px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }

  .overlay.show {
    display: block;
  }

  /* LINEスタイル: 各要素を個別に固定 */
  .chat-area {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  .mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    padding: 4px 8px;
    padding-top: calc(4px + env(safe-area-inset-top, 0px));
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    gap: 6px;
    min-height: 40px;
    box-sizing: border-box;
    z-index: 101;
  }

  .mobile-room-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
  }

  .mobile-room-info h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-header-actions {
    display: flex;
    gap: 2px;
  }

  .mobile-header-actions .icon-btn {
    width: 28px;
    height: 28px;
  }

  .mobile-header-actions .icon-btn svg {
    width: 16px;
    height: 16px;
  }

  .hamburger {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
  }

  .hamburger svg {
    width: 18px;
    height: 18px;
  }

  .chat-header {
    display: none;
  }

  .message-row .message-content {
    max-width: 80%;
  }

  .input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 8px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    overflow: visible;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    z-index: 101;
  }

  .messages {
    position: fixed;
    top: calc(40px + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: 44px;
    padding: 4px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .text-input-wrapper {
    padding: 2px;
    gap: 6px;
  }

  textarea {
    padding: 4px 8px;
    min-height: 28px;
    font-size: 14px;
    line-height: 1.3;
  }

  .send-btn {
    width: 32px;
    height: 32px;
  }

  .send-btn svg {
    width: 16px;
    height: 16px;
  }

  .file-select-btn {
    padding: 4px 6px;
  }

  .file-select-btn svg {
    width: 14px;
    height: 14px;
  }

  /* モバイルのみテキスト選択禁止（iOSメニュー対策） */
  .bubble {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .image-preview img {
    max-width: 70%;
  }

  /* ルーム未選択時: サイドバーを通常フロー表示 */
  .sidebar.mobile-main {
    position: static;
    transform: none;
    width: 100%;
    max-width: none;
    z-index: auto;
  }

  /* ルーム選択時: chat-areaを表示、未選択時は非表示 */
  .chat-area.mobile-hidden {
    display: none;
  }

  /* モーダル調整 */
  .modal {
    padding: 16px;
    align-items: flex-start;
    padding-top: 10vh;
  }

  .modal-content {
    width: 100%;
    max-width: none;
    padding: 24px;
  }

  .modal-footer {
    flex-direction: column;
    gap: 8px;
  }

  .modal-footer .btn {
    width: 100%;
  }

  /* タッチ操作の改善 */
  .room-item {
    min-height: 44px;
    padding: 6px 10px;
    -webkit-tap-highlight-color: transparent;
  }

  .btn, .icon-btn, .hamburger, .close-btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* プロフィールモーダルのボタン */
  .modal-content .btn {
    min-height: 48px;
  }

  /* リアクションパレットのモバイル対応 */
  .reaction-palette {
    flex-wrap: wrap;
    max-width: 180px;
  }

  .reaction-palette button {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  .message-actions {
    max-width: calc(100vw - 80px);
  }

  /* 返信プレビューのモバイル対応 */
  .reply-preview {
    padding: 6px 10px;
    width: 100%;
    box-sizing: border-box;
  }

  .reply-preview-content {
    overflow: hidden;
  }

  .reply-preview-label {
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .reply-preview-body {
    font-size: 12px;
  }
}

/* PC時モバイルヘッダー非表示 */
@media (min-width: 769px) {
  .mobile-header {
    display: none;
  }
}

/* ====== ログイン画面 ====== */
.login-view {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  background: var(--bg-secondary);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
}

/* モバイル: ログインボックスを上部に配置（キーボード対策） */
@media (max-width: 768px) {
  .login-view {
    align-items: flex-start;
    padding-top: 3vh;
    padding-bottom: 20px;
  }
}

.login-box {
  background: var(--bg-primary);
  padding: 48px 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-header h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.login-header p {
  font-size: 14px;
  color: var(--text-secondary);
}

.error-message {
  background: #FEF2F2;
  color: var(--danger);
  font-size: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
  text-align: center;
}

.forgot-password-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 14px;
  text-decoration: none;
}

.forgot-password-link:hover {
  color: var(--accent);
}

.alert-msg {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
  font-size: 14px;
}

.alert-msg.success {
  background: #D1FAE5;
  color: #047857;
}

.alert-msg.error {
  background: #FEE2E2;
  color: #DC2626;
}

.debug-info {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

/* ====== 選択なしの状態 ====== */
.no-room-selected {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  gap: 16px;
}

.no-room-selected svg {
  width: 64px;
  height: 64px;
  opacity: 0.5;
}

.no-room-selected p {
  font-size: 16px;
}

/* ====== メンション ====== */
.mention {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 500;
}

.mention.me {
  background: rgba(250, 204, 21, 0.3);
  color: #B45309;
}

.message-row.me .mention {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

.message-row.me .mention.me {
  background: rgba(250, 204, 21, 0.4);
  color: #FEF3C7;
}

/* メンションサジェストポップアップ */
.mention-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 99999;
  margin-bottom: 8px;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.mention-item:hover,
.mention-item.selected {
  background: var(--accent-light);
}

.mention-item-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--bg-tertiary);
}

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

.mention-item-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-primary);
}

.mention-item-username {
  font-size: 12px;
  color: var(--text-tertiary);
}

.text-input-wrapper {
  position: relative;
}

/* 画像ビューアモーダル */
.image-viewer-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px;
}

.image-viewer-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

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

.image-viewer-download {
  margin-top: 20px;
  padding: 12px 24px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}

.image-viewer-download:hover {
  background: var(--accent-hover);
}

/* ====== コンテキストメニュー（リアクション＋コピー） ====== */
.bubble-container {
  position: relative;
  -webkit-touch-callout: none;
}

.message-actions {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 4px;
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 8px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: fadeIn 0.15s ease-out;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.message-row.me .message-actions {
  left: auto;
  right: 0;
}

.reaction-palette {
  display: flex;
  gap: 4px;
}

.reaction-palette button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 20px;
  cursor: pointer;
  transition: var(--transition);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.reaction-palette button:hover {
  background: var(--bg-secondary);
  transform: scale(1.2);
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  font-family: inherit;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.action-btn svg {
  width: 14px;
  height: 14px;
}

.action-btn.delete-btn {
  color: #dc3545;
}

.action-btn.delete-btn:hover {
  background: #fff0f0;
  color: #c82333;
}

/* リアクションバッジ */
.reaction-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius-full);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.reaction-badge:hover {
  background: var(--bg-tertiary);
}

.reaction-badge.mine {
  background: var(--accent-light);
  border-color: var(--accent);
  font-weight: 600;
}

.reaction-badge .emoji {
  font-size: 14px;
}

.reaction-badge .count {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* 返信プレビュー */
.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.reply-preview-content {
  flex: 1;
  min-width: 0;
}

.reply-preview-label {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}

.reply-preview-body {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 8px;
}

.reply-cancel-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* 引用表示（メッセージ内） */
.quote-line {
  background: rgba(0,0,0,0.06);
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.message-row.me .quote-line {
  background: rgba(255,255,255,0.15);
  border-left-color: rgba(255,255,255,0.5);
  color: rgba(255,255,255,0.85);
}

.lang-prefix {
  font-weight: 600;
  color: var(--accent);
  margin-right: 2px;
}

.message-row.me .lang-prefix {
  color: rgba(255,255,255,0.9);
}

/* クリック可能な引用 */
.clickable-quote {
  cursor: pointer;
  transition: var(--transition);
}

.clickable-quote:hover {
  background: rgba(59, 130, 246, 0.1);
}

.message-row.me .clickable-quote:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* 元メッセージハイライト */
.highlight-flash {
  animation: highlightFlash 1.5s ease-out;
}

@keyframes highlightFlash {
  0%, 100% { background: transparent; }
  20% { background: rgba(59, 130, 246, 0.3); }
}

.quote-block {
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.quote-author {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}

.quote-text {
  font-size: 13px;
  color: var(--text-secondary);
}

/* トースト通知 */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 10px 24px;
  border-radius: var(--radius-full);
  font-size: 14px;
  z-index: 3000;
  animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 1.7s forwards;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* メッセージ文字サイズクラス */
.messages.font-size-medium .body {
  font-size: 17px;
}
.messages.font-size-medium .message-row.bot .body {
  font-size: 15px;
}

.messages.font-size-large .body {
  font-size: 19px;
}
.messages.font-size-large .message-row.bot .body {
  font-size: 17px;
}

/* 入力エリア文字サイズクラス */
.input-area.font-size-medium textarea {
  font-size: 17px;
}
.input-area.font-size-large textarea {
  font-size: 19px;
}

/* サイドバー（ルーム一覧）文字サイズクラス */
.sidebar.font-size-medium .room-name {
  font-size: 15px;
}
.sidebar.font-size-large .room-name {
  font-size: 17px;
}

/* カラーパレットポップオーバー */
.color-palette-btn {
  position: relative;
}

.color-palette-popover {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  z-index: 200;
  animation: fadeIn 0.15s ease-out;
}

.color-palette-popover .palette-label {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.color-palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.color-swatch.swatch-dark {
  border-color: #444;
}

/* 黒背景時の文字色調整 */
.messages.dark-bg .sender-name {
  color: rgba(255,255,255,0.6);
}

.messages.dark-bg .time {
  color: rgba(255,255,255,0.45);
}

.messages.dark-bg .read-status.sent {
  color: rgba(255,255,255,0.35);
}

.messages.dark-bg .read-status.read {
  color: rgba(255,255,255,0.6);
}

.messages.dark-bg .message-row.me .read-status.sent {
  color: rgba(255,255,255,0.35);
}

.messages.dark-bg .message-row.me .read-status.read {
  color: rgba(255,255,255,0.6);
}

.messages.dark-bg .date-separator span {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7);
}

.messages.dark-bg .loading-older,
.messages.dark-bg .no-more-messages {
  color: rgba(255,255,255,0.45);
}

.messages.dark-bg .unread-separator span {
  color: #FCA5A5;
}

.messages.dark-bg .unread-separator::before,
.messages.dark-bg .unread-separator::after {
  background: #FCA5A5;
}

.messages.dark-bg .message-row.bot:not(.me) .body {
  color: rgba(255,255,255,0.7);
}

.messages.dark-bg .message-row.me .bubble {
  background: rgba(255,255,255,0.22);
  color: #fff;
}

.messages.dark-bg .message-row.bot:not(.me) .bubble {
  background: rgba(255,255,255,0.13);
}

.messages.dark-bg .message-row:not(.me):not(.bot) .bubble {
  background: rgba(255,255,255,0.13);
  color: rgba(255,255,255,0.9);
}

.messages.dark-bg .quote-line {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
}

.messages.dark-bg .quote-block {
  background: rgba(255,255,255,0.12);
}

.messages.dark-bg .quote-text {
  color: rgba(255,255,255,0.7);
}

.messages.dark-bg .file-item {
  background: rgba(255,255,255,0.08);
}

.messages.dark-bg .file-icon {
  background: rgba(255,255,255,0.15);
}

.messages.dark-bg .file-icon svg {
  color: rgba(255,255,255,0.6);
}

.messages.dark-bg .mention {
  background: rgba(59, 130, 246, 0.3);
  color: #93C5FD;
}

.messages.dark-bg .mention.me {
  background: rgba(250, 204, 21, 0.3);
  color: #FDE047;
}

/* リアクションツールチップ */
.reaction-tooltip {
  position: fixed;
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  z-index: 3100;
  pointer-events: none;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow-lg);
}
