/* 重置和基礎樣式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent; /* 消除行動端點擊藍框 */
}

:root {
  --primary-color: #3b82f6;
  --primary-dark: #2563eb;
  --primary-glow: rgba(59, 130, 246, 0.5);
  --secondary-color: #10b981;
  --accent-color: #8b5cf6;
  --text-dark: #1f2937;
  --text-light: #9ca3af;
  --text-white: #ffffff;
  --bg-dark: #0a0e27;
  --bg-darker: #050714;
  --bg-card: #111827;
  --bg-card-hover: #1f2937;
  --border-color: rgba(59, 130, 246, 0.3);
  --border-glow: rgba(59, 130, 246, 0.6);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --glow: 0 0 20px var(--primary-glow);
  /* 鍵盤修正用：JS 會動態寫入真實可視高度，CSS fallback 為 100dvh */
  --chat-height: 100dvh;
  /* iOS Safari offsetTop 補償：鍵盤推高 layout viewport 時，JS 同步寫入偏移量 */
  --chat-offset: 0px;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* 防止背景滾動與晃動 */
}

body {
  font-family: 'Noto Sans TC', sans-serif;
  line-height: 1.6;
  color: var(--text-white);
  background: var(--bg-darker);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  height: 100%;
  position: relative;
}

/* 科技感網格背景 */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
      linear-gradient(rgba(59, 130, 246, 0.1) 1px, transparent 1px),
      linear-gradient(90deg, rgba(59, 130, 246, 0.1) 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
  z-index: 0;
  animation: gridMove 20s linear infinite;
}

@keyframes gridMove {
  0% { transform: translate(0, 0); }
  100% { transform: translate(50px, 50px); }
}

/* 動態粒子背景效果 */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
      radial-gradient(circle at 20% 50%, rgba(59, 130, 246, 0.1) 0%, transparent 50%),
      radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 50%),
      radial-gradient(circle at 40% 20%, rgba(16, 185, 129, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
  animation: pulse 15s ease-in-out infinite;
}

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

#chat {
  /* position:fixed + --chat-offset 修正 iOS Safari 的 layout viewport 位移問題：
     iOS 鍵盤彈出時，fixed 元素是錨定到 layout viewport 頂端，
     當 layout viewport 被推高（vp.offsetTop > 0），必須同步把 top 往下補回來，
     才能讓 #chat 頂端精確對齊 visual viewport 的頂端 */
  position: fixed;
  top: var(--chat-offset, 0px);
  /* 桌機端水平置中：left:50% + translateX(-50%)
     行動端 @media 內會覆寫為 left:0 / transform:none（全寬） */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  max-width: 700px;
  width: 100%;
  /* height 由 JS 透過 --chat-height 動態寫入，fallback 為 100dvh */
  height: var(--chat-height, 100dvh);
  background: rgba(17, 24, 39, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(59, 130, 246, 0.2);
  z-index: 1;
}

/* 聊天室內部的科技感網格 */
#chat::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
      linear-gradient(rgba(59, 130, 246, 0.05) 1px, transparent 1px),
      linear-gradient(90deg, rgba(59, 130, 246, 0.05) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
  z-index: -1;
  animation: gridMove 20s linear infinite;
}

/* 聊天室內部的動態光暈 */
#chat::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
      radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.05) 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
  animation: pulse 10s ease-in-out infinite;
}

/* 科技感背景層鋪滿整個視窗 */
.tech-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
      linear-gradient(180deg, rgba(10, 14, 39, 0.7) 0%, rgba(10, 14, 39, 0.9) 100%),
      repeating-linear-gradient(
          0deg,
          transparent,
          transparent 2px,
          rgba(59, 130, 246, 0.03) 2px,
          rgba(59, 130, 246, 0.03) 4px
      );
}

.gradient-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
      linear-gradient(180deg, rgba(10, 14, 39, 0.7) 0%, rgba(10, 14, 39, 0.9) 100%),
      repeating-linear-gradient(
          0deg,
          transparent,
          transparent 2px,
          rgba(59, 130, 246, 0.03) 2px,
          rgba(59, 130, 246, 0.03) 4px
      );
}

.hero-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
      radial-gradient(circle at 30% 50%, rgba(59, 130, 246, 0.3) 0%, transparent 50%),
      radial-gradient(circle at 70% 50%, rgba(139, 92, 246, 0.3) 0%, transparent 50%),
      linear-gradient(135deg, var(--bg-darker) 0%, var(--bg-dark) 100%);
  z-index: -1;
  animation: gradientShift 10s ease infinite;
}

@keyframes gradientShift {
  0%, 100% {
      filter: hue-rotate(0deg);
  }
  50% {
      filter: hue-rotate(20deg);
  }
}

/* 科技感裝飾元素 */
.tech-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* 內部裝飾專屬樣式，調低透明度以免干擾閱讀 */
.internal-tech {
    opacity: 0.3;
    z-index: -1; 
}

.internal-tech .tech-circle {
    transform: scale(0.6); 
}

.internal-tech .tech-line {
    opacity: 0.4;
}

.tech-circle {
  position: absolute;
  border: 2px solid rgba(59, 130, 246, 0.3);
  border-radius: 50%;
  animation: pulseCircle 4s ease-in-out infinite;
}

.circle-1 {
  width: 300px;
  height: 300px;
  top: 10%;
  right: 5%;
  box-shadow: 0 0 30px rgba(59, 130, 246, 0.3);
}

.circle-2 {
  width: 250px;
  height: 250px;
  bottom: 10%;
  left: 5%;
  border-color: rgba(139, 92, 246, 0.3);
  box-shadow: 0 0 30px rgba(139, 92, 246, 0.3);
  animation-delay: 1s;
}

.circle-3 {
  width: 180px;
  height: 180px;
  top: 40%;
  left: 30%;
  border-color: rgba(16, 185, 129, 0.3);
  box-shadow: 0 0 30px rgba(16, 185, 129, 0.3);
  animation-delay: 2s;
}

.circle-4 {
    width: 120px;
    height: 120px;
    top: 20%;
    left: 10%;
    border-color: rgba(59, 130, 246, 0.2);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
    animation-delay: 1.5s;
}

.circle-5 {
    width: 220px;
    height: 220px;
    bottom: 30%;
    right: 15%;
    border-color: rgba(139, 92, 246, 0.2);
    box-shadow: 0 0 25px rgba(139, 92, 246, 0.2);
    animation-delay: 2.5s;
}

@keyframes pulseCircle {
  0%, 100% {
      opacity: 0.2;
      transform: scale(1);
  }
  50% {
      opacity: 0.5;
      transform: scale(1.05);
  }
}

.tech-line {
  position: absolute;
  background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.6), transparent);
  animation: lineMove 8s linear infinite;
  transform: rotate(var(--rotation));
}

.line-1 {
  width: 300px;
  height: 1px;
  top: 25%;
  left: -50px;
  --rotation: 45deg;
  animation-delay: 0s;
}

.line-2 {
  width: 250px;
  height: 1px;
  bottom: 25%;
  right: -50px;
  --rotation: -45deg;
  animation-delay: 3s;
}

.line-3 {
  width: 200px;
  height: 1px;
  top: 70%;
  left: 10%;
  --rotation: 30deg;
  animation-delay: 6s;
}

.line-4 {
    width: 280px;
    height: 1px;
    top: 15%;
    right: 20%;
    --rotation: 15deg;
    background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.5), transparent);
    animation-delay: 1.5s;
}

.line-5 {
    width: 240px;
    height: 1px;
    bottom: 40%;
    left: 20%;
    --rotation: -15deg;
    background: linear-gradient(90deg, transparent, rgba(16, 185, 129, 0.5), transparent);
    animation-delay: 4.5s;
}

@keyframes lineMove {
  0% {
      opacity: 0;
      transform: translateX(-100px) rotate(var(--rotation));
  }
  15%, 85% {
      opacity: 0.8;
  }
  100% {
      opacity: 0;
      transform: translateX(100px) rotate(var(--rotation));
  }
}

.tech-dot {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(59, 130, 246, 0.8);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.8);
    animation: dotPulse 3s ease-in-out infinite;
}

.dot-1 { top: 15%; left: 15%; animation-delay: 0s; }
.dot-2 { top: 80%; right: 20%; animation-delay: 0.5s; background: rgba(139, 92, 246, 0.8); }
.dot-3 { top: 40%; right: 10%; animation-delay: 1.2s; }
.dot-4 { bottom: 15%; left: 30%; animation-delay: 1.8s; background: rgba(16, 185, 129, 0.8); }

@keyframes dotPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.4;
    }
    50% {
        transform: scale(1.5);
        opacity: 1;
        box-shadow: 0 0 15px rgba(59, 130, 246, 1);
    }
}

.chat img {
  max-width: 120px;
  max-height: 120px;
  display: block;
  border-radius: 8px;
  margin-top: 5px;
}

.chat-file-link {
  display: inline-block;
  margin-top: 5px;
  color: #3366cc;
  text-decoration: underline;
  word-break: break-all;
}

.my-message .chat-file-link {
  color: #ffffff;
}

.chat-file-link:hover {
  color: #224499;
}

.my-message .chat-file-link:hover {
  color: #e0e0e0;
}

#room-header {
  position: relative;       /* 讓子元素可以用 absolute 定位 */
  display: flex;
  align-items: center;
  padding: 10px 16px 6px;
  border-bottom: 1px solid rgba(59, 130, 246, 0.2);
  margin-bottom: 4px;
  flex-shrink: 0;
}

#room-header-name {
  font-size: 15px;
  font-weight: 600;
  color: #93c5fd;
  letter-spacing: 0.5px;
  flex: 1;              /* 撐滿整列 */
  text-align: center;   /* 文字在整列中置中 */
}

#leave-room-btn {
  position: absolute;   /* 脫離正常流，不影響標題置中 */
  right: 16px;
  padding: 3px 10px;
  font-size: 12px;
  color: #f87171;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
#leave-room-btn:hover {
  background: rgba(248, 113, 113, 0.25);
  border-color: rgba(248, 113, 113, 0.6);
}

#leave-room-btn {
  padding: 3px 10px;
  font-size: 12px;
  color: #f87171;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
  margin-left: auto;
}
#leave-room-btn:hover {
  background: rgba(248, 113, 113, 0.25);
  border-color: rgba(248, 113, 113, 0.6);
}

#online-count {
  text-align: center;
  font-style: italic;
  color: #9ca3af;
  padding: 8px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 8px;
  margin-bottom: 10px;
  border: 1px solid rgba(59, 130, 246, 0.1);
}

#user-list {
  padding: 0;
  background: transparent;
  border-radius: 0;
  margin-bottom: 0;
  font-size: 12px;
  max-height: 100px;
  overflow-y: auto;
}

.user-item {
  display: inline-block;
  margin: 2px 5px;
  padding: 2px 10px;
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  border-radius: 20px;
  border: 1px solid rgba(59, 130, 246, 0.3);
  font-size: 11px;
}

#typing-indicator {
  padding: 5px 10px;
  font-style: italic;
  color: #6b7280;
  font-size: 12px;
  background: transparent;
  border-top: 1px solid rgba(59, 130, 246, 0.1);
  flex-shrink: 0;
  margin-bottom: 0;
  z-index: 1;
  position: relative;
}

#messages {
  flex: 1;                
  min-height: 0; /* 防止撐破父容器 */
  overflow-y: auto;
  overscroll-behavior-y: contain; 
  display: flex;
  flex-direction: column;
  padding: 15px;
  gap: 10px;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: rgba(59, 130, 246, 0.3) transparent;
}

#messages::-webkit-scrollbar {
  width: 6px;
}

#messages::-webkit-scrollbar-thumb {
  background: rgba(59, 130, 246, 0.3);
  border-radius: 3px;
}

/* 訊息泡泡基礎樣式 */
.msg-text {
  word-break: break-word;
}

.system-time {
  display: block;
  font-size: 10px;
  color: #999;
  margin-top: 2px;
}

/* 自定義選單 */
.floating-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
}

.floating-menu {
    position: fixed;
    background: rgba(17, 24, 39, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 10001;
    min-width: 150px;
}

.menu-item {
    padding: 10px 16px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s;
}

.menu-item:hover {
    background: rgba(59, 130, 246, 0.2);
}

.menu-item.danger {
    color: #ef4444;
}

/* 回覆樣式重構 */
.reply-quote {
    background: rgba(0, 0, 0, 0.1);
    border-left: 3px solid rgba(59, 130, 246, 0.5);
    padding: 6px 10px;
    margin-bottom: 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    overflow: hidden;
}

.reply-quote:hover {
    background: rgba(0, 0, 0, 0.2);
}

.reply-quote-preview {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.reply-quote-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    margin-top: 0 !important; /* 蓋掉通用 img 樣式 */
}

.reply-quote-preview .file-icon {
    font-size: 18px;
}

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

.reply-quote-user {
    font-weight: bold;
    display: block;
    margin-bottom: 2px;
}

.reply-quote-body {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
}

.other-message .reply-quote {
    background: rgba(0, 0, 0, 0.05);
    color: rgba(30, 41, 59, 0.9);
}

.other-message .reply-quote-body {
    color: rgba(30, 41, 59, 0.7);
}

/* 訊息高亮閃爍效果 */
@keyframes highlightFlash {
    0% { transform: scale(1); box-shadow: 0 0 0px rgba(59, 130, 246, 0); }
    50% { transform: scale(1.02); box-shadow: 0 0 15px rgba(59, 130, 246, 0.8); }
    100% { transform: scale(1); box-shadow: 0 0 0px rgba(59, 130, 246, 0); }
}

.highlight-flash {
    animation: highlightFlash 1.5s ease-in-out;
    z-index: 10;
}

.msg-actions {
    display: none !important; /* 徹底移除舊有的垃圾桶空間 */
}

.my-message {
  background: #3B82F6; 
  color: #FFFFFF;      
  border-radius: 18px 18px 0 18px;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.my-message::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 10px;
  border-width: 6px 0 6px 6px;
  border-style: solid;
  border-color: transparent transparent transparent #3B82F6;
}

.other-message {
  background: rgba(255, 255, 255, 0.8); 
  color: #1E293B;                     
  border-radius: 18px 18px 18px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.other-message::after {
  content: "";
  position: absolute;
  left: -6px;
  top: 10px;
  border-width: 6px 6px 6px 0;
  border-style: solid;
  border-color: transparent rgba(255, 255, 255, 0.8) transparent transparent;
}

.system {
  text-align: center;
  font-style: italic;
  font-size: 12px;
  opacity: 0.85;
}

/* 待傳區多圖預覽 */
.file-preview-grid {
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 10px;
    padding: 10px 0;
    max-height: 180px;
    overflow-y: auto;
    border-bottom: 1px solid rgba(59, 130, 246, 0.1);
}

.preview-item {
    position: relative;
    width: 70px;
    height: 70px;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    margin-top: 0 !important;
}

.preview-item .remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    z-index: 5;
    backdrop-filter: blur(2px);
    transition: background 0.2s;
}

.preview-item .remove-btn:hover {
    background: rgba(239, 68, 68, 0.8);
}

.preview-item .file-name {
    font-size: 10px;
    padding: 4px;
    text-align: center;
    word-break: break-all;
}

/* 智慧型圖片網格 */
.image-grid {
    display: grid;
    gap: 4px;
    margin-top: 8px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 400px;
}

.image-grid-item {
    position: relative;
    cursor: pointer;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.1);
}

.image-grid-item img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    display: block;
    margin-top: 0 !important;
    transition: transform 0.3s ease;
}

.image-grid-item:hover img {
    transform: scale(1.05);
}

/* 網格配置規則 */
.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-3 .image-grid-item { aspect-ratio: 1 / 1; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
.grid-1 .image-grid-item { aspect-ratio: auto; max-height: 400px; }
.grid-2 .image-grid-item, .grid-4 .image-grid-item { aspect-ratio: 1 / 1; }
.grid-more { grid-template-columns: repeat(3, 1fr); }
.grid-more .image-grid-item { aspect-ratio: 1 / 1; }

/* 影片訊息 */
.chat-video-wrapper {
    margin-top: 6px;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.15);
    max-width: 320px;
}

.chat-video {
    display: block;
    width: 100%;
    max-height: 260px;
    object-fit: contain;
    border-radius: 10px 10px 0 0;
}

.chat-video-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    gap: 6px;
}

.chat-video-name {
    font-size: 11px;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-video-dl-btn {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: background 0.2s;
}

.chat-video-dl-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.other-message .chat-video-dl-btn {
    background: rgba(0, 0, 0, 0.08);
}

.other-message .chat-video-dl-btn:hover {
    background: rgba(0, 0, 0, 0.18);
}

/* 一般檔案卡片 */
.chat-file-card {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    text-decoration: none;
    color: inherit;
    max-width: 280px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    transition: background 0.2s;
}

.chat-file-card:hover {
    background: rgba(255, 255, 255, 0.22);
}

.other-message .chat-file-card {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.1);
}

.other-message .chat-file-card:hover {
    background: rgba(0, 0, 0, 0.12);
}

.chat-file-card-icon {
    font-size: 22px;
    flex-shrink: 0;
}

.chat-file-card-name {
    font-size: 13px;
    word-break: break-all;
    line-height: 1.3;
}

/* 全部下載按鈕 */
.download-all-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    transition: background 0.2s, opacity 0.2s;
    z-index: 5;
}
.download-all-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.other-message .download-all-btn {
    color: #1E293B;
    background: rgba(0, 0, 0, 0.1);
}
.other-message .download-all-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* 燈箱導覽按鈕 */
#lightbox-prev, #lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    user-select: none;
    transition: background 0.3s;
}

#lightbox-prev:hover, #lightbox-next:hover {
    background: rgba(59, 130, 246, 0.7);
}

#lightbox-prev { left: 20px; }
#lightbox-next { right: 20px; }

#lightbox-index {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 12px;
    border-radius: 20px;
}

/* 輸入框容器高度調整 */
#inputContainer {
    flex-shrink: 0;
    width: 100%;
    padding: 12px 15px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    background: rgba(17, 24, 39, 0.95);
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(59, 130, 246, 0.2);
    z-index: 10;
    display: flex;
    flex-direction: column;
    /* 確保動態推擠效果 */
}

#inputArea {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#input {
  flex: 1;
  padding: 10px;
  height: 44px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: white;
  outline: none;
  font-size: 16px;
  transition: border-color 0.3s;
}

#input:focus {
  border-color: var(--primary-color);
}

#send {
  padding: 0 16px;
  height: 44px; 
  min-width: 60px;
  border-radius: 8px;
  background-color: #7B61FF;
  color: white;
  border: none;
  cursor: pointer;
  font-size: 14px;
}

#send:hover {
  background-color: #5A3EFF;
}

.file-btn {
  font-size: 30px; 
  cursor: pointer;
  color: #bca7ff;
  line-height: 1;
}

#filePreview {
  padding: 0;
  margin: 0;
  min-height: 0;
  display: none; 
}

#filePreview img {
  max-width: 80px;
  max-height: 80px;
  margin: 5px 0;
}

#filePreview span {
  font-size: 14px;
  color: #3b82f6; 
  font-weight: bold;
}

.avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    color: white;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    user-select: none;
}

.avatar-A { background-color: rgba(59, 130, 246, 0.6); } 
.avatar-B { background-color: rgba(168, 85, 247, 0.6); } 
.avatar-C { background-color: rgba(245, 158, 11, 0.6); } 
.avatar-D { background-color: rgba(234, 179, 8, 0.6); } 
.avatar-E { background-color: rgba(132, 204, 22, 0.6); } 
.avatar-F { background-color: rgba(34, 197, 94, 0.6); } 
.avatar-G { background-color: rgba(16, 185, 129, 0.6); } 
.avatar-H { background-color: rgba(20, 184, 166, 0.6); } 
.avatar-I { background-color: rgba(6, 182, 212, 0.6); } 
.avatar-J { background-color: rgba(14, 165, 233, 0.6); } 
.avatar-K { background-color: rgba(59, 130, 246, 0.6); } 
.avatar-L { background-color: rgba(37, 99, 235, 0.6); } 
.avatar-M { background-color: rgba(139, 92, 246, 0.6); } 
.avatar-N { background-color: rgba(168, 85, 247, 0.6); } 
.avatar-O { background-color: rgba(192, 38, 211, 0.6); } 
.avatar-P { background-color: rgba(219, 39, 119, 0.6); } 
.avatar-Q { background-color: rgba(225, 29, 72, 0.6); } 
.avatar-R { background-color: rgba(71, 85, 105, 0.6); } 
.avatar-S { background-color: rgba(100, 116, 139, 0.6); } 
.avatar-T { background-color: rgba(82, 82, 82, 0.6); } 
.avatar-U { background-color: rgba(161, 98, 7, 0.6); } 
.avatar-V { background-color: rgba(21, 128, 61, 0.6); } 
.avatar-W { background-color: rgba(30, 58, 138, 0.6); } 
.avatar-X { background-color: rgba(109, 40, 217, 0.6); } 
.avatar-Y { background-color: rgba(157, 23, 77, 0.6); } 
.avatar-Z { background-color: rgba(15, 23, 42, 0.6); } 

.message-wrapper {
    display: flex;
    align-items: flex-start; 
    margin-bottom: 15px;
    width: 100%;
    gap: 10px;
}

.my-message-wrapper {
    flex-direction: row-reverse; 
    justify-content: flex-start;
}

.other-message-wrapper {
    flex-direction: row; 
    justify-content: flex-start;
}

.msg-bubble-container {
    display: flex;
    flex-direction: column;
    max-width: 75%; 
}

.my-message-wrapper .msg-bubble-container {
    align-items: flex-end;
}

.other-message-wrapper .msg-bubble-container {
    align-items: flex-start;
}

.chat {
    width: fit-content;
    max-width: 100%;
    padding: 10px 14px;
    border-radius: 16px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word; 
    
    /* 核心修正：封殺原生長按行為 */
    -webkit-touch-callout: none; /* 禁用 iOS 長按選單 */
    -webkit-user-select: none;   /* 禁用文字選取 */
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;  /* 減少點擊延遲 */
}

.chat-img {
    max-width: 250px; 
    width: 100%;     
    height: auto;
    display: block;
    border-radius: 8px;
    margin-top: 5px;
    cursor: pointer;
    transition: transform 0.2s;
}

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

.msg-time {
    font-size: 11px;
    color: #94a3b8;
    margin: 4px 0;
}

.recalled-message {
    font-style: italic;
    color: #94a3b8 !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px dashed rgba(255, 255, 255, 0.2) !important;
    box-shadow: none !important;
    min-width: 120px;
    text-align: center;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 14, 39, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(10px);
}

.room-card {
    background: rgba(17, 24, 39, 0.85);
    padding: 40px;
    border-radius: 20px;
    border: 1px solid rgba(59, 130, 246, 0.3);
    box-shadow: 0 0 40px rgba(59, 130, 246, 0.2);
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.room-card h2 {
    margin-bottom: 30px;
    color: #3B82F6;
    font-size: 24px;
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.input-group {
    margin-bottom: 20px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #9ca3af;
}

.input-group input {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
    color: white;
    outline: none;
    transition: 0.3s;
}

.input-group input:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.button-group {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.button-group button {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    transition: 0.3s;
}

.primary-btn {
    background: #3B82F6;
    color: white;
}

.primary-btn:hover {
    background: #2563eb;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.secondary-btn {
    background: rgba(59, 130, 246, 0.1);
    color: #3B82F6;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
}

.secondary-btn:hover {
    background: rgba(59, 130, 246, 0.2);
}

.error-msg {
    color: #ef4444;
    font-size: 13px;
    margin-top: 15px;
    height: 18px;
}

#scroll-to-bottom {
  position: absolute;
  bottom: 100px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #7B61FF;
  color: white;
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  z-index: 100;
}

#scroll-to-bottom:hover {
  background: #5A3EFF;
}

#scroll-to-bottom.show {
  display: flex;
}

.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 5px;
  color: white;
  font-weight: bold;
  z-index: 10000;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
}

.notification.show {
  opacity: 1;
  transform: translateX(0);
}

.notification-success {
  background: #4CAF50;
}

.notification-error {
  background: #f44336;
}

.notification-warning {
  background: #ff9800;
}

.notification-info {
  background: #2196F3;
}

@media (max-width: 768px) {
  body {
    padding-top: 0;
    align-items: stretch;
  }

  #chat {
    /* 行動端全寬：取消桌機的水平置中偏移 */
    left: 0;
    transform: none;
    max-width: 100%;
    /* height 同樣由 --chat-height 控制，鍵盤彈出時 JS 即時更新 */
    height: var(--chat-height, 100dvh);
    border-radius: 0;
  }
  
  #messages {
    padding: 12px;
  }
  
  .msg-text {
    font-size: 15px;
  }

  #inputArea {
    gap: 12px;
  }

  #input {
    height: 40px;
    font-size: 15px;
  }
  
  #send {
    height: 40px;
  }
  
  .file-btn {
    font-size: 28px; 
  }

  #scroll-to-bottom {
    width: 48px;
    height: 48px;
    bottom: 110px;
    right: 16px;
  }
}

.system-message-wrapper {
    justify-content: center;
    width: 100%;
}

.system-message-wrapper .msg-time {
    display: none; 
}

.recalled-message .msg-text {
    color: #94a3b8 !important;
}

.recalled-message::after {
    display: none !important;
}
