* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
}

.chat-container {
  width: 100%;
  max-width: 420px;
  height: calc(100vh - 20px);
  max-height: 700px;
  min-height: 500px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-header .avatar {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.chat-header .info {
  flex: 1;
}

.chat-header .info h3 {
  font-size: 16px;
  margin-bottom: 4px;
  font-weight: 600;
}

.chat-header .info p {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-header .status-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f5f7fb;
  -webkit-overflow-scrolling: touch;
}

.message {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.sent {
  align-items: flex-end;
}

.message.received {
  align-items: flex-start;
}

.message .bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.sent .bubble {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.message.received .bubble {
  background: #fff;
  color: #333;
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.recalled-message {
  color: #999 !important;
  font-style: italic;
  background: rgba(0, 0, 0, 0.03) !important;
  padding: 8px 12px;
  border-radius: 8px;
}

.message.sent .recalled-message {
  color: rgba(255, 255, 255, 0.7) !important;
  background: rgba(255, 255, 255, 0.1) !important;
}

.message .time {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
  padding: 0 4px;
}

.message .sender-name {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
  font-weight: 500;
}

.message.received .sender-name {
  margin-left: 4px;
}

.message.sent .sender-name {
  margin-right: 4px;
}

.message.system {
  align-items: flex-start;
}

.message.system .bubble {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: #fff;
  border-bottom-left-radius: 6px;
}

.message.system .sender-name {
  margin-left: 4px;
  color: #f5576c;
}

.message .file-bubble {
  max-width: 85%;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
}

.message.sent .file-bubble {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.message.received .file-bubble {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.message .file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.message.sent .file-card {
  color: #fff;
}

.message.received .file-card {
  color: #333;
}

.message .file-icon {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.message.received .file-icon {
  background: #f0f0f0;
}

.message .file-info {
  flex: 1;
  min-width: 0;
}

.message .file-name {
  font-size: 14px;
  font-weight: 500;
  word-break: break-all;
  line-height: 1.3;
}

.message .file-size {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

.message img.msg-image {
  max-width: 200px;
  max-height: 200px;
  border-radius: 12px;
  cursor: pointer;
  display: block;
}

.chat-input-area {
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #eee;
  flex-shrink: 0;
}

.input-toolbar {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.input-toolbar button {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: #666;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.input-toolbar button:hover {
  background: #f0f0f0;
}

.input-toolbar button.active {
  background: #667eea;
  color: #fff;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.input-wrapper textarea {
  width: 100%;
  border: 2px solid #eee;
  border-radius: 20px;
  resize: none;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
  max-height: 100px;
  min-height: 40px;
  padding: 10px 16px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.input-wrapper textarea:focus {
  border-color: #667eea;
}

.send-btn {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.emoji-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  display: none;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
  max-height: 200px;
  overflow-y: auto;
  z-index: 5;
}

.emoji-panel.show {
  display: block;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.emoji-item {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.emoji-item:hover {
  background: #f0f0f0;
}

.typing-indicator {
  padding: 12px 16px;
  background: #fff;
  border-radius: 18px;
  display: inline-flex;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-8px);
  }
}

.image-preview {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
}

.image-preview img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
}

.image-preview .close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
}

@media (max-width: 480px) {
  body {
    padding: 0;
  }

  .chat-container {
    max-width: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    min-height: 100dvh;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .chat-header .avatar {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .chat-header .info h3 {
    font-size: 15px;
  }

  .chat-header .info p {
    font-size: 11px;
  }

  .chat-messages {
    padding: 12px;
  }

  .message .bubble {
    max-width: 90%;
    font-size: 14px;
  }

  .message .time {
    font-size: 10px;
  }

  .chat-input-area {
    padding: 10px 12px;
  }

  .input-toolbar button {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  .input-wrapper textarea {
    font-size: 14px;
    padding: 8px 14px;
    min-height: 36px;
  }

  .send-btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  .emoji-grid {
    grid-template-columns: repeat(7, 1fr);
  }

  .emoji-item {
    font-size: 20px;
  }
}
