* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { 
  margin: 0; 
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; 
  background: #f0f2f5; 
  color: #333; 
  height: 100vh; 
  height: 100dvh; /* Better mobile support */
  overflow: hidden; 
  overscroll-behavior-y: none; /* Prevent pull-to-refresh */
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* Improve touch targets and remove delay */
button, input, .contact-item, .back-arrow {
  touch-action: manipulation;
}

/* Prevent auto-zoom on inputs */
input[type="text"], input[type="password"] {
  font-size: 16px !important; 
}

.hidden { display: none !important; }

/* 登录/初始化卡片 */
.view { height: 100%; display: flex; flex-direction: column; }
#view-setup, #view-login { align-items: center; justify-content: center; }

.card { background: white; padding: 2rem; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); width: 100%; max-width: 400px; text-align: center; }
.card input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #ddd; border-radius: 4px; }
.card button { width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; }
.card button:hover { background: #0056b3; }

/* 管理员面板 */
header { background: #333; color: white; padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; }
header button { background: #555; color: white; border: none; padding: 5px 10px; cursor: pointer; border-radius: 4px; }

/* 群组管理面板 */
.group-manager { grid-column: span 2; background: #fff; padding: 15px; border-radius: 8px; margin-top: 20px; }
.group-manager h3 { margin-top: 0; }
.user-select-list { max-height: 150px; overflow-y: auto; border: 1px solid #ddd; padding: 10px; margin: 10px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.user-select-item { display: flex; align-items: center; gap: 5px; }

.admin-container { padding: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; height: calc(100vh - 50px); overflow-y: auto; }
.panel { background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.full-width { grid-column: span 2; }
.scroll-box { height: 200px; overflow-y: auto; border: 1px solid #eee; padding: 5px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid #eee; }
.log-box div { padding: 4px 0; border-bottom: 1px solid #f9f9f9; font-size: 13px; }
.btn { display: inline-block; padding: 8px 15px; background: #28a745; color: white; text-decoration: none; border-radius: 4px; margin-right: 10px; }

.realtime-map { height: 360px; border: 1px solid #eee; border-radius: 8px; overflow: hidden; }
.realtime-user-list { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.realtime-user-badge { padding: 6px 10px; border-radius: 999px; border: 1px solid #eee; background: #f8f9fa; font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.realtime-user-dot { width: 10px; height: 10px; border-radius: 50%; background: #6c757d; }
.realtime-user-dot.live { background: #28a745; }
.realtime-user-dot.alert { background: #dc3545; }
.realtime-label { background: rgba(255,255,255,0.92); border: 1px solid #ddd; color: #222; padding: 2px 6px; border-radius: 999px; font-size: 12px; }
.leaflet-tooltip.realtime-label { box-shadow: none; }

/* 用户聊天界面 */
#view-user { flex-direction: row; }
.sidebar { width: 250px; background: white; border-right: 1px solid #ddd; display: flex; flex-direction: column; transition: transform 0.3s; }

.btn-disabled { background: #ccc !important; cursor: not-allowed; }
.btn-checkout { background: #dc3545 !important; margin-top: 10px; }

/* 统计卡片样式 */
#admin-stats-box { margin-bottom: 20px; border-bottom: 2px solid #eee; padding-bottom: 20px; }
.stats-list { display: flex; flex-wrap: wrap; gap: 10px; }
.stat-item { background: #fff3cd; padding: 5px 10px; border-radius: 4px; border: 1px solid #ffeeba; display: flex; align-items: center; gap: 5px; font-size: 13px; }
.stat-name { font-weight: bold; }
.stat-tag { color: #856404; background: rgba(0,0,0,0.05); padding: 2px 5px; border-radius: 3px; }
  @media (max-width: 768px) {
    body { height: 100dvh; } /* 适配移动端动态视口高度 */
    #view-user { position: relative; overflow: hidden; height: 100%; }
    
    .sidebar { 
      width: 100%; 
      position: absolute; 
      top: 0; left: 0; height: 100%; 
      z-index: 10; 
      background: white;
      transition: transform 0.3s; 
    }
    
    .sidebar.hidden-mobile { transform: translateX(-100%); }
    
    .chat-area { 
      width: 100%; 
      position: absolute; 
      top: 0; left: 0; height: 100%; 
      z-index: 5; /* 确保在 sidebar 下面 */
      display: flex; /* 确保布局正确 */
      flex-direction: column;
      background: #f0f2f5;
    }
    
    /* 移动端聊天头部增加返回按钮 */
    .chat-header {
      flex-shrink: 0;
    }
    .message-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior-y: contain; }
    .chat-input-area { position: sticky; bottom: 0; left: 0; width: 100%; z-index: 30; flex-shrink: 0; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    /* Removed pseudo-element style */
}

.user-info { padding: 20px; background: #f8f9fa; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }
.actions { padding: 10px; border-bottom: 1px solid #eee; text-align: center; }
.actions button { width: 100%; padding: 8px; background: #ffc107; border: none; border-radius: 4px; cursor: pointer; }
.contact-list { flex: 1; overflow-y: auto; }
.contact-item { padding: 15px; cursor: pointer; border-bottom: 1px solid #f0f0f0; }
.contact-item:hover, .contact-item.active { background: #e6f7ff; }
.contact-item .name { font-weight: bold; }
.contact-item .preview { font-size: 12px; color: #888; margin-top: 4px; }

.chat-area { flex: 1; display: flex; flex-direction: column; background: #fff; }
.chat-placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: #999; }
.chat-container { flex: 1; display: flex; flex-direction: column; height: 100%; }
.chat-header { display: flex; align-items: center; padding: 10px 15px; border-bottom: 1px solid #eee; font-weight: bold; background: #f8f9fa; z-index: 20; position: sticky; top: 0; min-height: 60px; }
.back-arrow { 
  font-size: 28px; 
  margin-right: 10px; 
  cursor: pointer; 
  display: none; 
  width: 44px; 
  height: 44px; 
  line-height: 44px; 
  text-align: center; 
  border-radius: 50%;
  -webkit-tap-highlight-color: rgba(0,0,0,0.1);
  user-select: none;
}
.back-arrow:active {
  background-color: #e2e6ea;
}

@media (max-width: 768px) {
  .back-arrow { display: block; }
  .chat-header::before { content: none; } /* Remove old pseudo-element */
}
.message-list { flex: 1; overflow-y: auto; padding: 20px; background: #f0f2f5; display: flex; flex-direction: column; gap: 10px; }

.msg { max-width: 70%; padding: 10px; border-radius: 8px; position: relative; word-break: break-all; }
.msg.self { align-self: flex-end; background: #007bff; color: white; }
.msg.other { align-self: flex-start; background: white; border: 1px solid #eee; }
.msg-meta { font-size: 11px; opacity: 0.7; margin-bottom: 4px; display: block; }
.msg-file { display: block; margin-top: 5px; background: rgba(255,255,255,0.2); padding: 5px; border-radius: 4px; text-decoration: none; color: inherit; }
.msg-file:hover { text-decoration: underline; }

.chat-input-area { 
  padding: 10px; 
  border-top: 1px solid #eee; 
  display: flex; 
  gap: 10px; 
  align-items: center; 
  background: white; /* 确保背景不透明 */
  position: relative; 
  z-index: 20; /* 提高层级 */
}
.chat-input-area input[type=text] { flex: 1; padding: 12px; border: 1px solid #ddd; border-radius: 20px; outline: none; font-size: 16px; }
.chat-input-area button { padding: 8px 20px; background: #007bff; color: white; border: none; border-radius: 20px; cursor: pointer; font-size: 16px; }
.btn-icon { font-size: 24px; cursor: pointer; padding: 5px 10px; color: #666; }

/* 安装引导弹窗 */
.install-guide {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.8); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.guide-content {
  background: white; width: 80%; max-width: 320px; padding: 20px;
  border-radius: 12px; text-align: center;
}
.guide-content h3 { margin-top: 0; color: #007bff; }
.guide-steps { text-align: left; background: #f9f9f9; padding: 10px; margin: 15px 0; border-radius: 8px; font-size: 14px; }
.guide-steps p { margin: 8px 0; }
.icon-share { font-size: 18px; vertical-align: middle; }

/* 通话界面 */
#call-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: #000; z-index: 10000;
  display: flex; flex-direction: column;
}
.call-container {
  flex: 1; position: relative; display: flex; flex-direction: column;
}
.video-wrapper {
  flex: 1; position: relative; background: #000;
  display: flex; align-items: center; justify-content: center;
}
#remote-video {
  width: 100%; height: 100%; object-fit: cover;
}
#local-video {
  position: absolute; top: 20px; right: 20px;
  width: 100px; height: 150px; background: #333;
  object-fit: cover; border-radius: 8px; border: 2px solid white;
  z-index: 2;
}
.call-info {
  position: absolute; top: 50px; left: 0; width: 100%;
  text-align: center; color: white; text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  z-index: 1; pointer-events: none;
}
.call-controls {
  position: absolute; bottom: 40px; left: 0; width: 100%;
  display: flex; justify-content: center; gap: 40px;
  z-index: 2;
}
.btn-call {
  width: 60px; height: 60px; border-radius: 50%; border: none;
  font-weight: bold; color: white; cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.btn-accept { background: #28a745; }
.btn-hangup { background: #dc3545; }
.btn-accept:active, .btn-hangup:active { transform: scale(0.95); }

