/* ============ 全局样式 - 微信风格 ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  background: #ededed;
  color: #333;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 750px;
  margin: 0 auto;
  min-height: 100vh;
  background: #ededed;
  position: relative;
  overflow-x: hidden;
}

/* ============ 通用组件 ============ */
.btn-primary {
  background: #07c160;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
  width: 100%;
}
.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: #fff;
  color: #576b95;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:active { background: #f5f5f5; }

.input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  font-size: 16px;
  background: #fff;
  outline: none;
  transition: border-color 0.2s;
}
.input:focus { border-color: #07c160; }

.card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 9999;
  pointer-events: none;
  animation: fadeInOut 2s ease;
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

.hidden { display: none !important; }

/* ============ 主页样式 ============ */
.home-container {
  padding: 24px 20px;
  min-height: 100vh;
  background: linear-gradient(135deg, #07c160 0%, #10ad6a 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.home-header {
  text-align: center;
  margin-bottom: 32px;
}
.home-header .logo {
  width: 80px;
  height: 80px;
  background: #fff;
  border-radius: 20px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
}
.home-header h1 {
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  margin-bottom: 10px;
  letter-spacing: 2px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.4);
}
.home-header p {
  color: #fff;
  font-size: 14px;
  opacity: 0.95;
  text-shadow: 0 1px 4px rgba(0,0,0,0.35);
}

.home-tabs {
  display: flex;
  background: rgba(0,0,0,0.18);
  border-radius: 12px;
  padding: 5px;
  margin-bottom: 24px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.15);
}
.home-tabs .tab {
  flex: 1;
  text-align: center;
  padding: 13px;
  border-radius: 9px;
  color: rgba(255,255,255,0.95);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.25s;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.home-tabs .tab.active {
  background: #fff;
  color: #07c160;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  text-shadow: none;
}

.home-form {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

/* 自动昵称提示 */
.auto-nick-tip {
  margin-top: 12px;
  font-size: 12px;
  color: #999;
  text-align: center;
  line-height: 1.5;
}
.auto-nick-tip b {
  color: #07c160;
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.room-number-display {
  font-size: 36px;
  font-weight: 700;
  color: #07c160;
  letter-spacing: 8px;
  text-align: center;
  padding: 20px;
  background: #f7f7f7;
  border-radius: 12px;
  margin-bottom: 16px;
  font-family: 'Courier New', monospace;
}

.share-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.share-actions button {
  flex: 1;
}

/* ============ 聊天页面样式 - 微信风格 ============ */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #ededed;
}

/* 顶部导航栏 */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  background: #ededed;
  border-bottom: 1px solid #d6d6d6;
  position: sticky;
  top: 0;
  z-index: 100;
}
.chat-header .back-btn {
  position: absolute;
  left: 12px;
  background: none;
  border: none;
  font-size: 20px;
  color: #333;
  cursor: pointer;
  padding: 8px;
}
.chat-header .title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}
.chat-header .actions {
  position: absolute;
  right: 12px;
  display: flex;
  gap: 8px;
}
.chat-header .icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: #333;
  cursor: pointer;
  padding: 6px;
}

/* 消息列表 */
.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}

/* 系统消息 */
.system-message {
  text-align: center;
  padding: 8px 16px;
  font-size: 12px;
  color: #999;
}
.system-message .sys-content {
  background: rgba(0,0,0,0.08);
  padding: 4px 10px;
  border-radius: 4px;
}

/* 消息气泡 */
.message-item {
  display: flex;
  align-items: flex-start;
  max-width: 85%;
}
.message-item.self {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: linear-gradient(135deg, #07c160, #10ad6a);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
  flex-shrink: 0;
  overflow: hidden;
}
.message-item:not(.self) .avatar {
  background: linear-gradient(135deg, #576b95, #4a5d7f);
}

.message-content {
  margin: 0 10px;
  max-width: calc(100% - 60px);
}
.message-item .nickname {
  font-size: 12px;
  color: #888;
  margin-bottom: 4px;
}
.message-item.self .nickname {
  text-align: right;
}

.bubble {
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1.5;
  word-break: break-all;
  position: relative;
  max-width: 100%;
}
.message-item:not(.self) .bubble {
  background: #fff;
  color: #333;
  border-top-left-radius: 2px;
}
.message-item.self .bubble {
  background: #95ec69;
  color: #333;
  border-top-right-radius: 2px;
}

/* 气泡小三角 */
.message-item:not(.self) .bubble::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 12px;
  border: 8px solid transparent;
  border-right-color: #fff;
  border-left: 0;
}
.message-item.self .bubble::before {
  content: '';
  position: absolute;
  right: -8px;
  top: 12px;
  border: 8px solid transparent;
  border-left-color: #95ec69;
  border-right: 0;
}

/* 媒体消息 */
.bubble img, .bubble video {
  max-width: 220px;
  max-height: 220px;
  border-radius: 4px;
  display: block;
}
.bubble video {
  background: #000;
}

/* 正在输入提示 */
.typing-indicator {
  font-size: 12px;
  color: #999;
  padding: 4px 12px;
}
.typing-indicator::after {
  content: '...';
  animation: typingBlink 1.4s infinite;
}
@keyframes typingBlink {
  0%, 50% { opacity: 0.3; }
  100% { opacity: 1; }
}

/* 输入栏 */
.chat-input-bar {
  background: #f7f7f7;
  border-top: 1px solid #d6d6d6;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.input-icon {
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-textarea {
  flex: 1;
  border: none;
  background: #fff;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 16px;
  resize: none;
  max-height: 100px;
  min-height: 36px;
  outline: none;
  line-height: 1.4;
  font-family: inherit;
}

.send-btn {
  background: #07c160;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0 16px;
  height: 36px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:active { opacity: 0.85; }
.send-btn:disabled { background: #ccc; }

/* 扩展面板 */
.ext-panel {
  background: #f7f7f7;
  border-top: 1px solid #d6d6d6;
  padding: 20px;
  display: none;
}
.ext-panel.active { display: block; }

/* 表情面板 */
.emoji-panel {
  background: #f7f7f7;
  border-top: 1px solid #d6d6d6;
  padding: 12px;
  display: none;
}
.emoji-panel.active { display: block; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.emoji-item {
  border: none;
  background: none;
  font-size: 27px;
  padding: 7px 0;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
  line-height: 1;
  touch-action: manipulation;
}
.emoji-item:active { background: #e0e0e0; }

.ext-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.ext-item {
  text-align: center;
  cursor: pointer;
}
.ext-item .ext-icon {
  width: 56px;
  height: 56px;
  background: #fff;
  border-radius: 12px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.ext-item .ext-label {
  font-size: 12px;
  color: #666;
}

/* ============ 管理页面 ============ */
.admin-container {
  padding: 20px;
  min-height: 100vh;
  background: #f5f5f5;
}
.admin-login {
  max-width: 400px;
  margin: 100px auto;
}
.admin-login h2 {
  text-align: center;
  margin-bottom: 24px;
  color: #333;
}

.admin-dashboard {
  max-width: 900px;
  margin: 0 auto;
}
.admin-dashboard h2 {
  margin-bottom: 20px;
  color: #333;
}

.room-list {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 0.2s;
}
.room-item:last-child { border-bottom: none; }
.room-item:hover { background: #f9f9f9; }
.room-item .room-info h4 {
  color: #333;
  margin-bottom: 4px;
}
.room-item .room-info p {
  font-size: 12px;
  color: #999;
}
.room-item .room-status {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
}
.room-status.active { background: #e8f7ee; color: #07c160; }
.room-status.inactive { background: #f5f5f5; color: #999; }

/* 消息详情 */
.chat-detail {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-top: 16px;
}
.admin-msg-item {
  padding: 12px;
  border-bottom: 1px solid #f0f0f0;
}
.admin-msg-item:last-child { border-bottom: none; }
.admin-msg-item .msg-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.admin-msg-item .msg-nickname { font-weight: 600; color: #333; }
.admin-msg-item .msg-time { font-size: 12px; color: #999; }
.admin-msg-item .msg-body {
  font-size: 14px;
  color: #555;
  background: #f7f7f7;
  padding: 10px;
  border-radius: 4px;
  word-break: break-all;
}
.admin-msg-item img {
  max-width: 200px;
  border-radius: 4px;
}
.admin-msg-item video {
  max-width: 300px;
}

/* ============ 响应式适配 ============ */
@media (max-width: 375px) {
  .home-header .logo { width: 64px; height: 64px; font-size: 32px; }
  .room-number-display { font-size: 28px; letter-spacing: 6px; }
  .bubble { font-size: 15px; }
  .avatar { width: 36px; height: 36px; font-size: 14px; }
}

/* iPhone X 刘海屏适配 */
@supports (padding: max(0px)) {
  .chat-header { padding-top: max(12px, env(safe-area-inset-top)); }
}

/* ============ 历史记录区域 ============ */
.history-section {
  background: rgba(255,255,255,0.95);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 600;
  color: #333;
}
.history-clear {
  font-size: 12px;
  color: #999;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 12px;
}
.history-clear:active { background: #f0f0f0; color: #e74c3c; }
.history-clear.hidden { display: none; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.history-empty {
  text-align: center;
  padding: 24px;
  font-size: 13px;
  color: #bbb;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: #f7f7f7;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.history-item:active { background: #e8f5ee; }
.history-item.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.history-item.disabled:active { background: #f7f7f7; }

.h-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.h-avatar {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #07c160, #10ad6a);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
}
.h-info {
  flex: 1;
  min-width: 0;
}
.h-name {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.h-sub {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.h-number { color: #07c160; font-weight: 500; }
.h-divider { margin: 0 4px; color: #ccc; }

.h-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.h-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
}
.h-status.active { background: #e8f7ee; color: #07c160; }
.h-status.inactive { background: #f5f5f5; color: #999; }
.h-status.new { background: #fff0f0; color: #e74c3c; font-weight: 600; animation: hBlink 1.2s ease-in-out infinite; }
@keyframes hBlink { 0%,100% { opacity:1; } 50% { opacity:0.55; } }

/* 房间卡片 + 角标 */
.history-item { position: relative; }
.h-badge {
  position: absolute; top: -4px; right: -4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #e74c3c; color: #fff; font-size: 8px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px #fff;
  animation: hPulse 1.2s ease-in-out infinite;
}
@keyframes hPulse { 0%,100% { transform:scale(1); } 50% { transform:scale(1.2); } }
.history-item.has-new { border-left: 3px solid #e74c3c; }

.h-delete {
  width: 24px;
  height: 24px;
  border: none;
  background: #eee;
  color: #999;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.h-delete:active { background: #ffecec; color: #e74c3c; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.modal-mask.hidden { display: none; }
.modal-box {
  background: #fff;
  border-radius: 14px;
  width: 280px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  padding: 18px 16px 6px;
  color: #333;
}
.modal-content {
  font-size: 14px;
  text-align: center;
  padding: 4px 16px 18px;
  color: #666;
  line-height: 1.5;
}
.modal-btns {
  display: flex;
  border-top: 1px solid #eee;
}
.modal-btn {
  flex: 1;
  padding: 14px;
  border: none;
  background: none;
  font-size: 15px;
  cursor: pointer;
}
.modal-btn:active { background: #f5f5f5; }
.modal-cancel { color: #999; border-right: 1px solid #eee; }
.modal-ok { color: #07c160; font-weight: 600; }
.modal-ok:active { background: #e8f7ee; }

/* ============ 房间名显示（主页创建成功） ============ */
.room-name-display {
  font-size: 20px;
  font-weight: 600;
  color: #333;
  text-align: center;
  padding: 12px;
  background: #f7f7f7;
  border-radius: 8px;
  margin-bottom: 16px;
  word-break: break-all;
}

/* ============ 聊天页标题可编辑 ============ */
.title-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 55%;
}
.chat-header .title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  cursor: default;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title-sub {
  font-size: 11px;
  color: #999;
  margin-top: 1px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title-edit {
  position: absolute;
  right: -28px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #07c160;
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  opacity: 0.6;
}
.title-edit:active { opacity: 1; }

/* 失效媒体占位 */
.msg-broken {
  color: #b0b0b0;
  font-size: 13px;
  font-style: italic;
}
