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

:root {
  --primary-color: #4267b2;
  --primary-hover: #365899;
  --success-color: #28a745;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --info-color: #17a2b8;
  --light-gray: #f8f9fa;
  --medium-gray: #e9ecef;
  --dark-gray: #6c757d;
  --border-color: #dee2e6;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  --border-radius: 8px;
  --transition: all 0.3s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.chat-app {
  width: 100%;
  max-width: 1200px;
  height: 90vh;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.chat-header {
  background: var(--primary-color);
  color: white;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-left h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.header-subtitle {
  font-size: 0.875rem;
  opacity: 0.9;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  text-align: right;
  font-size: 0.875rem;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.status-connecting {
  background: rgba(255, 193, 7, 0.2);
  color: #fff3cd;
}
.status-connecting .status-dot {
  background: #ffc107;
}

.status-connected {
  background: rgba(40, 167, 69, 0.2);
  color: #d4edda;
}
.status-connected .status-dot {
  background: #28a745;
}

.status-disconnected {
  background: rgba(220, 53, 69, 0.2);
  color: #f8d7da;
}
.status-disconnected .status-dot {
  background: #dc3545;
}

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

/* Main Content */
.chat-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Messages Area */
.messages-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--light-gray);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  scroll-behavior: smooth;
}

.message {
  margin-bottom: 1rem;
  max-width: 70%;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.own {
  margin-left: auto;
  margin-right: 0;
}

.message-bubble {
  background: white;
  padding: 0.75rem 1rem;
  border-radius: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: relative;
}

.message.own .message-bubble {
  background: var(--primary-color);
  color: white;
}

.message-author {
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
  color: var(--primary-color);
}

.message.own .message-author {
  color: rgba(255, 255, 255, 0.9);
}

.message-content {
  line-height: 1.4;
  margin-bottom: 0.5rem;
  word-wrap: break-word;
}

.message-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--dark-gray);
}

.message.own .message-footer {
  color: rgba(255, 255, 255, 0.8);
}

.message-actions {
  display: flex;
  gap: 0.5rem;
}

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.action-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  transform: scale(1.05);
}

.message.own .action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.message-time {
  font-size: 0.75rem;
}

/* System Messages */
.system-message {
  text-align: center;
  margin: 1rem 0;
  padding: 0.5rem;
  background: rgba(23, 162, 184, 0.1);
  color: var(--info-color);
  border-radius: var(--border-radius);
  font-style: italic;
  font-size: 0.875rem;
}

/* Input Area */
.input-section {
  padding: 1rem;
  background: white;
  border-top: 1px solid var(--border-color);
}

.input-container {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  max-width: 100%;
}

.message-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--medium-gray);
  border-radius: 24px;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  min-height: 44px;
  max-height: 120px;
  transition: var(--transition);
}

.message-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(66, 103, 178, 0.1);
}

.message-input:disabled {
  background: var(--light-gray);
  cursor: not-allowed;
}

.send-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--dark-gray);
  cursor: not-allowed;
  transform: none;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: white;
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--light-gray);
}

.sidebar-title {
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.user-count {
  font-size: 0.875rem;
  color: var(--dark-gray);
}

.users-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--border-radius);
  margin-bottom: 0.25rem;
  transition: var(--transition);
}

.user-item:hover {
  background: var(--light-gray);
}

.user-item.current-user {
  background: rgba(66, 103, 178, 0.1);
  color: var(--primary-color);
  font-weight: 500;
}

.user-item.current-user .user-avatar {
  background: var(--primary-color);
  border: 2px solid var(--primary-color);
  box-shadow: 0 0 0 2px rgba(66, 103, 178, 0.2);
}

.logout-btn-inline {
  background: transparent;
  border: none;
  color: var(--dark-gray);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  margin-left: auto;
  transition: all 0.2s ease;
  opacity: 0.6;
}

.logout-btn-inline:hover {
  opacity: 1;
  color: var(--danger-color);
  transform: scale(1.1);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
}

.user-name {
  flex: 1;
  font-size: 0.875rem;
}

.online-indicator {
  width: 8px;
  height: 8px;
  background: var(--success-color);
  border-radius: 50%;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal {
  background: white;
  padding: 2rem;
  border-radius: var(--border-radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  max-width: 400px;
  width: 90%;
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal h2 {
  color: var(--primary-color);
  margin-bottom: 1rem;
  text-align: center;
}

.modal p {
  color: var(--dark-gray);
  margin-bottom: 1.5rem;
  text-align: center;
}

.form-group {
  margin-bottom: 1rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--medium-gray);
  border-radius: var(--border-radius);
  font-size: 1rem;
  transition: var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(66, 103, 178, 0.1);
}

.form-btn {
  width: 100%;
  padding: 0.75rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.form-btn:hover {
  background: var(--primary-hover);
}

.form-btn:disabled {
  background: var(--dark-gray);
  cursor: not-allowed;
}

.error-message {
  color: var(--danger-color);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  text-align: center;
}

/* Notifications */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 1rem 1.5rem;
  border-radius: var(--border-radius);
  color: white;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 1001;
  animation: notificationSlide 0.3s ease-out;
}

@keyframes notificationSlide {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.notification.success {
  background: var(--success-color);
}
.notification.error {
  background: var(--danger-color);
}
.notification.info {
  background: var(--info-color);
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 5px;
    min-height: 100vh;
    height: 100vh; /* Force full height */
  }

  .chat-app {
    height: 100vh; /* Use full viewport height */
    max-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  .chat-header {
    flex-shrink: 0; /* Don't shrink header */
  }

  .chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex child to shrink */
    overflow: hidden;
  }

  .messages-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex child to shrink */
    overflow: hidden;
  }

  .messages-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    min-height: 0; /* Allow flex child to shrink */
  }

  .input-section {
    flex-shrink: 0; /* Don't shrink input area */
  }

  .sidebar {
    position: fixed;
    right: -280px;
    top: 0;
    height: 100%;
    z-index: 999;
    transition: right 0.3s ease;
    width: 280px;
  }

  .sidebar.open {
    right: 0;
  }

  .message {
    max-width: 85%;
  }

  .input-container {
    flex-wrap: nowrap;
    min-width: 0; /* Allow flex items to shrink */
  }

  .message-input {
    min-width: 0; /* Prevent input from overflowing */
    flex-shrink: 1;
    max-height: 80px; /* Limit height on mobile */
  }

  .send-btn {
    flex-shrink: 0; /* Keep button size fixed */
    min-width: 60px;
  }

  .modal {
    margin: 10px;
    width: calc(100vw - 20px);
    max-width: 400px;
  }

  /* Ensure proper touch scrolling */
  .messages-container,
  .users-list {
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0); /* Enable hardware acceleration */
  }

  /* Handle mobile keyboard */
  .chat-app {
    position: relative;
  }

  /* Prevent zoom on input focus */
  input,
  textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* Additional mobile fixes for very small screens */
@media (max-width: 480px) {
  .chat-header {
    padding: 0.75rem 1rem;
  }

  .header-left h1 {
    font-size: 1.25rem;
  }

  .header-subtitle {
    font-size: 0.75rem;
  }

  .message-input {
    padding: 0.5rem 0.75rem;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  .send-btn {
    padding: 0.5rem;
    min-width: 50px;
  }
}

/* Scrollbar Styling */
.messages-container::-webkit-scrollbar,
.users-list::-webkit-scrollbar,
.message-input::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track,
.users-list::-webkit-scrollbar-track,
.message-input::-webkit-scrollbar-track {
  background: var(--light-gray);
}

.messages-container::-webkit-scrollbar-thumb,
.users-list::-webkit-scrollbar-thumb,
.message-input::-webkit-scrollbar-thumb {
  background: var(--medium-gray);
  border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover,
.users-list::-webkit-scrollbar-thumb:hover,
.message-input::-webkit-scrollbar-thumb:hover {
  background: var(--dark-gray);
}

/* Hide scrollbar for message input when not needed */
.message-input {
  scrollbar-width: thin;
  scrollbar-color: var(--medium-gray) transparent;
}

/* For Firefox */
.message-input {
  scrollbar-width: none;
}

/* Alternative: completely hide scrollbar for message input */
.message-input::-webkit-scrollbar {
  display: none;
}

/* Loading Animation */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--medium-gray);
  border-radius: 18px;
  margin-bottom: 1rem;
  max-width: 100px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--dark-gray);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}
.typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typingBounce {
  0%,
  80%,
  100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.hidden {
  display: none !important;
}
