:root {
  --primary-color: #c8b472;
  --primary-dark: #a89962;
  --primary-light: #d8c98a;
  --text-light: #ffffff;
  --text-dark: #1a1a1a;
  --bubble-sent: #c8b472;
  --bubble-received: #2d3134;
  --background-dark: #1a1d21; /* Slightly lighter dark background */
  --background-darker: #15181c;
  --danger-red: #ff3b30;
}

/* Message bubbles with better contrast */
.message {
  margin-bottom: 0.8rem;
  padding: 0.8rem 1rem;
  border-radius: 18px;
  max-width: 80%;
  word-wrap: break-word;
  position: relative;
  line-height: 1.4;
  font-size: 1rem;
  animation: fadeIn 0.3s ease;
}

.message.sent {
  background-color: var(--bubble-sent);
  color: var(--text-dark); /* Dark text on gold background */
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.message.received {
  background-color: var(--bubble-received);
  color: var(--text-light); /* White text on dark background */
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

/* Time stamp contrast */
.message .time {
  color: rgba(0,0,0,0.6); /* Darker for sent */
  font-size: 0.75rem;
}

.message.received .time {
  color: rgba(255,255,255,0.6); /* Lighter for received */
}

/* Header Styles */
.chat-header {
  background: var(--primary-color);
  color: var(--text-dark);
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chat-header h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.current-user {
  font-weight: 500;
  background: rgba(0,0,0,0.1);
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.9rem;
}

/* Message Container - Reversed Order */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.5rem;
  background-color: var(--background-darker);
  background-image: url('data:image/svg+xml;utf8,<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path fill="%23c8b472" fill-opacity="0.03" d="M30,20 Q50,10 70,20 T90,40 Q100,60 80,70 T50,90 Q20,80 20,50 T30,20"/></svg>');
  background-repeat: repeat;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column-reverse; /* This reverses the order */
}

/* Message Bubbles */
.message {
  margin-bottom: 0.8rem;
  padding: 0.8rem 1rem 0.6rem;
  border-radius: 18px;
  max-width: 80%;
  word-wrap: break-word;
  position: relative;
  line-height: 1.4;
  font-size: 1rem;
  color: var(--text-light);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message strong {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--primary-light);
  font-weight: 500;
}

.message.sent {
  background-color: var(--bubble-sent);
  color: var(--text-dark);
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.message.received {
  background-color: var(--bubble-received);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

.message .time {
  display: inline-block;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
  margin-top: 0.3rem;
  margin-left: 0.5rem;
  float: right;
}

.message.sent .time {
  color: rgba(0,0,0,0.7);
}

/* Input Area - Keyboard Friendly */
.chat-input-container {
  position: sticky;
  bottom: 0;
  background: var(--background-dark);
  padding: 0.8rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  transition: transform 0.3s ease;
}

.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.chat-input textarea {
  flex: 1;
  padding: 0.8rem 1.2rem;
  border: none;
  border-radius: 24px;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  background: var(--bubble-received);
  color: var(--text-light);
  font-size: 1rem;
  line-height: 1.4;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chat-input textarea::placeholder {
  color: rgba(255,255,255,0.5);
}

/* Send Button with Icon */
.send-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary-color);
  color: var(--text-dark);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-button:hover {
  background: var(--primary-dark);
}

.send-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Mobile Keyboard Adjustments */
@media (max-width: 768px) {
  .chat-input-container.keyboard-visible {
    transform: translateY(calc(-1 * var(--keyboard-height, 250px)));
  }
  
  .chat-messages {
    padding-bottom: 1rem;
  }
}

/* Join Form Styles */
.simple-chatroom-form {
  max-width: 100%;
  margin: 0;
  padding: 2rem 1.5rem;
  background: var(--background-dark);
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.form-group {
  margin-bottom: 1.8rem;
}

.form-group label {
  display: block;
  margin-bottom: 1rem;
  font-weight: 500;
  color: var(--text-light);
  font-size: 1.2rem;
  text-align: center;
}

.form-group input {
  width: 100%;
  padding: 1.2rem;
  border: none;
  border-radius: 24px;
  font-size: 1rem;
  background: var(--bubble-received);
  color: var(--text-light);
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.join-button {
  display: block;
  width: 100%;
  padding: 1.2rem;
  background: var(--primary-color);
  color: var(--text-dark);
  border: none;
  border-radius: 24px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
  font-size: 1rem;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.join-button:hover {
  background: var(--primary-dark);
}

/* Additional WhatsApp-like Features */
.message-status {
  display: inline-block;
  margin-left: 0.5rem;
}

.message-status.read svg {
  width: 16px;
  height: 16px;
  fill: var(--primary-color);
}

.date-separator {
  text-align: center;
  margin: 1.5rem 0;
  position: relative;
}

.date-separator span {
  background: var(--background-dark);
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.7);
  position: relative;
  z-index: 1;
  display: inline-block;
}

.date-separator:before {
  content: "";
  position: absolute;
  top: 50%;
  left: 1rem;
  right: 1rem;
  height: 1px;
  background: rgba(255,255,255,0.1);
  z-index: 0;
}

.chat-input-container {
  transition: margin-bottom 0.2s ease;
  background: var(--background-dark);
  padding: 10px;
  position: sticky;
  bottom: 0;
}

/* Input Field Styling */
.chat-input textarea {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  background: #2d3134;
  color: white;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  min-height: 50px;
  max-height: 120px;
  transition: all 0.3s ease;
}

/* Placeholder Styling */
.chat-input textarea::placeholder {
  color: rgba(255, 255, 255, 0.5);
  opacity: 1; /* Fix for Firefox */
}

/* Join Button Styling */
.join-button {
  display: block;
  width: 100%;
  padding: 14px;
  background: #c8b472;
  color: #1a1a1a;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  margin-top: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.join-button:hover {
  background: #d8c98a;
  transform: translateY(-1px);
}

/* Send Button Styling */
.send-button {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #c8b472;
  color: #1a1a1a;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-left: 10px;
  flex-shrink: 0;
}

.send-button:hover {
  background: #d8c98a;
}

.send-button svg {
  width: 24px;
  height: 24px;
}

/* Sticky Message Input Container */
.chat-input-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a1d21;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 1000;
  transition: transform 0.3s ease;
}

/* Message Input Field */
.chat-input {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 800px;
  margin: 0 auto;
}

#chat-message {
  flex: 1;
  min-height: 50px;
  max-height: 120px;
  padding: 12px 16px;
  border-radius: 25px;
  border: none;
  background: #2d3134;
  color: white;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

#chat-message::placeholder {
  color: rgba(255, 255, 255, 0.5);
  opacity: 1;
}

#chat-message:focus {
  outline: none;
  box-shadow: 0 0 0 2px #c8b472;
}

/* Send Button */
#send-message {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #c8b472;
  color: #1a1a1a;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

#send-message:hover {
  background: #d8c98a;
  transform: scale(1.05);
}

#send-message:active {
  transform: scale(0.95);
}

#send-message svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Join Chat Button */
.join-button {
  display: block;
  width: 100%;
  padding: 15px;
  background: #c8b472;
  color: #1a1a1a;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-top: 25px;
}

.join-button:hover {
  background: #d8c98a;
  transform: translateY(-2px);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

.join-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Keyboard Active State */
.keyboard-visible .chat-input-container {
  transform: translateY(calc(-1 * var(--keyboard-height, 0)));
}