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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Login Screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
}

.login-modal {
  background: white;
  border-radius: 16px;
  padding: 40px 30px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 350px;
  text-align: center;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #333;
}

.login-subtitle {
  font-size: 14px;
  color: #666;
  margin-bottom: 24px;
}

.login-helper {
  font-size: 12px;
  color: #c44545;
  margin-top: -16px;
  margin-bottom: 20px;
}

.login-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}

.login-input:focus {
  outline: none;
  border-color: #667eea;
}

.login-button {
  width: 100%;
  padding: 12px 16px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.login-button.secondary {
  margin-top: 10px;
  background: white;
  color: #667eea;
  border: 1.5px solid #667eea;
}

.login-button.secondary:hover {
  background: #eef0ff;
  transform: scale(1.02);
}

.login-button.secondary:active {
  transform: scale(0.98);
}

.login-button:hover {
  background: #5568d3;
  transform: scale(1.02);
}

.login-button:active {
  transform: scale(0.98);
}

.login-error {
  color: #f44336;
  font-size: 12px;
  margin-top: 12px;
  min-height: 16px;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  background: white;
}

/* Header */
.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 20px;
  box-shadow: 0 2px 8px rgba(102, 0, 234, 0.2);
  flex-shrink: 0;
  safe-area-inset-top: env(safe-area-inset-top);
  padding-top: calc(16px + env(safe-area-inset-top));
}

.header-info {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.status-text {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.9;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
  transition: background 0.3s;
}

.status-dot.connected {
  background: #4caf50;
  box-shadow: 0 0 8px #4caf50;
}

/* Chat messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: white;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* Messages */
.message {
  display: flex;
  margin-bottom: 8px;
  align-items: flex-start;
  touch-action: pan-y;
  transition: transform 0.2s;
}

.message.admin {
  flex-direction: row;
}

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

.message.pending {
  opacity: 0.6;
}

.message.error {
  opacity: 0.5;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #667eea;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
  font-size: 14px;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.message.admin .message-avatar {
  background: #e53e3e;
  margin-right: 8px;
}

.message.user .message-avatar {
  margin-left: 8px;
}

.message-avatar.admin-photo {
  background-color: #e53e3e; /* fallback color if image missing */
  background-image: url('/img/image.png');
  background-size: cover;
  background-position: center;
  color: #fff;
}

.message.admin .message-avatar.admin-photo {
  background-color: #e53e3e;
  background-image: url('/img/image.png');
  background-size: cover;
  background-position: center;
  color: #fff;
}

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

.message.user .message-content {
  text-align: right;
}

.message.admin .message-content {
  text-align: left;
  align-items: flex-start;
}

.message-bubble {
  background: white;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  word-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
  max-width: 100%;
}

.message.user .message-bubble {
  background: #667eea;
  color: white;
}

/* Reply Indicator */
.message-reply-indicator {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  border-left: 3px solid #667eea;
}

.message.user .message-reply-indicator {
  background: rgba(255, 255, 255, 0.15);
  border-left-color: white;
}

.message-reply-indicator .reply-icon {
  flex-shrink: 0;
  margin-top: 1px;
  color: #667eea;
}

.message.user .message-reply-indicator .reply-icon {
  color: white;
}

.message-reply-indicator .reply-text strong {
  color: #667eea;
  font-weight: 600;
}

.message.user .message-reply-indicator .reply-text strong {
  color: white;
}

.message-reply-indicator .reply-message-text {
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 250px;
  margin-top: 2px;
  font-size: 11px;
}

.message.user .message-reply-indicator .reply-message-text {
  color: rgba(255, 255, 255, 0.8);
}

/* Message actions */
.message-actions {
  display: none !important; /* Ẩn hoàn toàn, chỉ dùng context menu */
  position: absolute;
  top: -10px;
  right: -10px;
  gap: 4px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 4px;
}

.message:hover .message-actions {
  display: none !important;
}

.action-btn {
  background: transparent;
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  transition: all 0.2s;
}

.action-btn:hover {
  background: #f0f0f0;
  color: #667eea;
}

/* Attachment previews */
.message-image {
  max-width: 250px;
  max-height: 250px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
  margin-bottom: 5px;
}

.message-audio {
  width: 250px;
  margin-bottom: 5px;
}

.message-video {
  max-width: 250px;
  max-height: 250px;
  border-radius: 10px;
  margin-bottom: 5px;
}

.message-file {
  display: inline-block;
  padding: 8px 12px;
  background: rgba(0,0,0,0.05);
  border-radius: 5px;
  text-decoration: none;
  color: inherit;
  margin-bottom: 5px;
}

.message.user .message-file {
  background: rgba(255,255,255,0.2);
  color: white;
}

.message-text {
  word-break: break-word;
}

.message-time {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
}

/* Input container */
.chat-input-container {
  background: white;
  border-top: 1px solid #e0e0e0;
  padding: 12px 12px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-items: flex-end;
  safe-area-inset-bottom: env(safe-area-inset-bottom);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

/* Icon buttons */
.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #f7f7f8;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  flex-shrink: 0;
}

.icon-button svg {
  display: block;
}

.icon-button:hover:not(:disabled) {
  background: #e2e8f0;
  transform: scale(1.05);
  color: #333;
}

.icon-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.voice-btn.recording {
  background: #ffebee;
  animation: pulse-red 1s infinite;
}

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

/* Message input */
#messageInput {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid #e0e0e0;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 100px;
  font-family: inherit;
  transition: border-color 0.2s;
}

#messageInput:focus {
  border-color: #667eea;
}

#messageInput:disabled {
  background: #f5f5f5;
  color: #999;
  cursor: not-allowed;
}

/* Send button */
#sendButton {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #667eea;
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

#sendButton:hover:not(:disabled) {
  background: #5568d3;
  transform: scale(1.05);
}

#sendButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Reply preview */
.reply-preview {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #f7f7f8;
  border-left: 3px solid #667eea;
  border-radius: 8px;
  margin: 0 12px 10px 12px;
  font-size: 13px;
}

.reply-icon {
  color: #667eea;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

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

.reply-label {
  font-size: 11px;
  color: #667eea;
  font-weight: 600;
  margin-bottom: 2px;
}

.reply-message {
  font-size: 13px;
  color: #4a5568;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  transition: all 0.2s;
  flex-shrink: 0;
}

.reply-close:hover {
  background: #e2e8f0;
  color: #666;
}

/* Attachment preview */
.attachment-preview {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.preview-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
}

.preview-close {
  position: absolute;
  top: -40px;
  right: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: white;
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.preview-close:hover {
  background: #f0f0f0;
  transform: scale(1.1);
}

.file-preview {
  background: white;
  padding: 30px;
  border-radius: 12px;
  font-size: 18px;
}

/* Context menu */
.context-menu {
  position: fixed;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 4px 0;
  z-index: 1000;
  min-width: 140px;
}

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

.context-menu-item:hover {
  background: #f5f5f5;
}

.context-menu-item svg {
  color: #666;
}

/* Responsive adjustments */
@media (min-width: 768px) {
  .message-content {
    max-width: 50%;
  }
}

@media (max-width: 600px) {
  .header-title {
    font-size: 16px;
  }
  
  .message-content {
    max-width: 80%;
  }
  
  .message-image,
  .message-video {
    max-width: 200px;
    max-height: 200px;
  }
  
  .message-audio {
    width: 200px;
  }
}

