@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap');

:root {
  --body-bg: #f7f7f7;
  --wrapper-bg: #fff;
  --text-main: #333;
  --text-secondary: #67676a;
  --border-color: #e6e6e6;
  --input-bg: #fff;
  --input-border: #ccc;
  --outgoing-bg: #333;
  --outgoing-text: #fff;
  --incoming-bg: #fff;
  --incoming-text: #333;
  --header-border: #e6e6e6;
  --field-icon: #ccc;
  --error-bg: #f8d7da;
  --error-text: #721c24;
  --error-border: #f5c6cb;
  --chat-bg: #efe7dd;
  --theme-color: #00a884;
  --theme-color-dark: #008f6f;
  /* WhatsApp Light BG */
}

body.dark-theme {
  --body-bg: #202c33;
  /* Main Dark BG */
  --wrapper-bg: #111b21;
  --text-main: #e9edef;
  --text-secondary: #aebac1;
  --border-color: #2a3942;
  --input-bg: #2a3942;
  --input-border: #2a3942;
  --outgoing-bg: #005c4b;
  --outgoing-text: #e9edef;
  --incoming-bg: #202c33;
  --incoming-text: #e9edef;
  --header-border: #2a3942;
  --field-icon: #8696a0;
  --error-bg: #2a3942;
  --error-text: #f15c6d;
  --error-border: #8696a0;
  --chat-bg: #0b141a;
  /* WhatsApp Dark BG */
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  text-decoration: none;
  font-family: 'Poppins', sans-serif;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--body-bg);
  padding: 0 10px;
  transition: background 0.3s ease;
}

.wrapper {
  background: var(--wrapper-bg);
  max-width: 450px;
  width: 100%;
  border-radius: 16px;
  box-shadow: 0 0 128px 0 rgba(0, 0, 0, 0.1),
    0 32px 64px -48px rgba(0, 0, 0, 0.5);
  transition: background 0.3s ease;
}

/* Signup & Login Form CSS */
.form {
  padding: 25px 30px;
}

.form header {
  font-size: 25px;
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.form form {
  margin: 20px 0;
}

.form form .error-text {
  color: var(--error-text);
  padding: 8px 10px;
  text-align: center;
  border-radius: 5px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  margin-bottom: 10px;
  display: none;
}

.form form .name-details {
  display: flex;
}

.form .name-details .field:first-child {
  margin-right: 10px;
}

.form .name-details .field:last-child {
  margin-left: 10px;
}

.form form .field {
  display: flex;
  margin-bottom: 10px;
  flex-direction: column;
  position: relative;
}

.form form .field label {
  margin-bottom: 2px;
  color: var(--text-main);
}

.form form .input input {
  height: 40px;
  width: 100%;
  font-size: 16px;
  padding: 0 10px;
  border-radius: 5px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-main);
}

.form form .field input {
  outline: none;
}

.form form .image input {
  font-size: 17px;
  color: var(--text-main);
}

.form form .button input {
  height: 45px;
  border: none;
  color: #fff;
  font-size: 17px;
  background: var(--theme-color);
  border-radius: 5px;
  cursor: pointer;
  margin-top: 13px;
}

.form form .field i {
  position: absolute;
  right: 15px;
  top: 70%;
  color: var(--field-icon);
  cursor: pointer;
  transform: translateY(-50%);
}

.form form .field i.active::before {
  color: #333;
  content: "\f070";
}

.form .link {
  text-align: center;
  margin: 10px 0;
  font-size: 17px;
  color: var(--text-main);
}

.form .link a {
  color: var(--theme-color);
}

body.dark-theme .form .link a {
  color: var(--text-main);
}

.form .link a:hover {
  text-decoration: underline;
}

/* Users List CSS */
.users {
  padding: 25px 30px;
}

.users header,
.users-list a {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  justify-content: space-between;
}

.wrapper img {
  object-fit: cover;
  border-radius: 50%;
}

.users header img {
  height: 50px;
  width: 50px;
}

.users header .content {
  display: flex;
  align-items: center;
}

.users header .content .details {
  color: var(--text-main);
  margin-left: 15px;
}

.users header .content .details span {
  font-size: 18px;
  font-weight: 500;
}

.users header .content .details p {
  font-size: 12px;
}

.users header .theme-toggler {
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-main);
  margin-right: 15px;
  margin-left: auto;
}

.users header .logout {
  display: block;
  background: var(--theme-color);
  color: #fff;
  outline: none;
  border: none;
  padding: 7px 15px;
  text-decoration: none;
  border-radius: 5px;
  font-size: 17px;
}

.users .search {
  margin: 20px 0;
  display: flex;
  position: relative;
  align-items: center;
  justify-content: space-between;
}

.users .search .text {
  font-size: 18px;
  color: var(--text-main);
}

.users .search input {
  position: absolute;
  height: 42px;
  width: calc(100% - 50px);
  font-size: 16px;
  padding: 0 13px;
  border: 1px solid var(--border-color);
  outline: none;
  border-radius: 5px 0 0 5px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  background: var(--input-bg);
  color: var(--text-main);
}

.users .search input.show {
  opacity: 1;
  pointer-events: auto;
}

.users .search button {
  position: relative;
  z-index: 1;
  width: 47px;
  height: 42px;
  font-size: 17px;
  cursor: pointer;
  border: none;
  background: var(--wrapper-bg);
  color: var(--text-main);
  outline: none;
  border-radius: 0 5px 5px 0;
  transition: all 0.2s ease;
}

.users .search button.active {
  background: var(--theme-color);
  color: #fff;
}

.users .search button.active i::before {
  content: "\f00d";
}

.users-list {
  max-height: 350px;
  overflow-y: auto;
}

:is(.users-list, .chat-box)::-webkit-scrollbar {
  width: 0px;
}

.users-list a {
  padding-bottom: 10px;
  margin-bottom: 15px;
  padding-right: 15px;
  border-bottom-color: var(--border-color);
}

.users-list a:last-child {
  margin-bottom: 0px;
  border-bottom: none;
}

.users-list a img {
  height: 40px;
  width: 40px;
}

.users-list a .details {
  color: var(--text-main);
  margin-left: 15px;
}

.users-list a .details span {
  font-size: 18px;
  font-weight: 500;
}

.users-list a .details p {
  color: var(--text-secondary);
}

.users-list a .status-dot {
  font-size: 12px;
  color: #468669;
  padding-left: 10px;
}

.users-list a .status-dot.offline {
  color: #ccc;
}

/* Chat Area CSS */
.chat-area header {
  display: flex;
  align-items: center;
  padding: 18px 30px;
  border-bottom: 1px solid var(--header-border);
}

.chat-area header .back-icon {
  color: var(--text-main);
  font-size: 18px;
}

.chat-area header img {
  height: 45px;
  width: 45px;
  margin: 0 15px;
}

.chat-area header .details span {
  font-size: 17px;
  font-weight: 500;
  color: var(--text-main);
}

.chat-area header .details p {
  font-size: 12px;
  color: var(--text-main);
}

.chat-box {
  position: relative;
  min-height: 500px;
  max-height: 500px;
  overflow-y: auto;
  padding: 10px 30px 20px 30px;
  background: var(--chat-bg);
  box-shadow: inset 0 32px 32px -32px rgb(0 0 0 / 5%),
    inset 0 -32px 32px -32px rgb(0 0 0 / 5%);
  transition: background 0.3s ease;
}

.chat-box .text {
  position: absolute;
  top: 45%;
  left: 50%;
  width: calc(100% - 50px);
  text-align: center;
  transform: translate(-50%, -50%);
  color: var(--text-main);
}

.chat-box .chat {
  margin: 15px 0;
}

.chat-box .chat p {
  word-wrap: break-word;
  padding: 8px 16px;
  box-shadow: 0 0 32px rgb(0 0 0 / 8%),
    0rem 16px 16px -16px rgb(0 0 0 / 10%);
}

.chat-box .outgoing {
  display: flex;
}

.chat-box .outgoing .details {
  margin-left: auto;
  max-width: calc(100% - 130px);
}

.chat-box .outgoing .details p {
  background: var(--outgoing-bg);
  color: var(--outgoing-text);
  border-radius: 18px 18px 0 18px;
}

.chat-box .chat .details p .time {
  font-size: 10px;
  float: right;
  margin-top: 5px;
  margin-left: 10px;
  color: currentColor;
  /* Inherit the text color */
  opacity: 0.7;
  /* Make it slightly lighter than main text */
}

.chat-box .incoming {
  display: flex;
  align-items: flex-end;
}

.chat-box .incoming img {
  height: 35px;
  width: 35px;
}

.chat-box .incoming .details {
  margin-right: auto;
  margin-left: 10px;
  max-width: calc(100% - 130px);
}

.chat-box .incoming .details p {
  background: var(--incoming-bg);
  color: var(--incoming-text);
  border-radius: 18px 18px 18px 0;
}

.typing-area {
  padding: 18px 30px;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--header-border);
  background: var(--wrapper-bg);
  position: relative;
}

.typing-area .attach-btn {
  width: 45px;
  height: 45px;
  border: none;
  outline: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
  margin-right: 10px;
  pointer-events: auto;
}

.typing-area .attach-btn:hover {
  background: var(--input-bg);
}

.typing-area input {
  height: 45px;
  flex: 1;
  /* Automatically take remaining space */
  margin: 0 10px;
  /* Add spacing between buttons */
  font-size: 16px;
  padding: 0 13px;
  border: 1px solid var(--border-color);
  outline: none;
  border-radius: 5px;
  /* Full rounded corners */
  background: var(--input-bg);
  color: var(--text-main);
}

.typing-area button.send-btn {
  color: #fff;
  width: 55px;
  border: none;
  outline: none;
  background: var(--theme-color);
  font-size: 19px;
  cursor: pointer;
  opacity: 1;
  pointer-events: auto;
  border-radius: 5px;
  /* Full rounded */
  transition: all 0.3s ease;
}

/* Attachment Menu */
.attachment-menu {
  position: absolute;
  bottom: 80px;
  left: 30px;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 15px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: all 0.3s ease;
  z-index: 100;
}

.attachment-menu.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.attachment-menu .menu-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  color: white;
  font-size: 0;
  /* Hide text initially */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  position: relative;
  transition: transform 0.2s;
}

.attachment-menu .menu-btn:hover {
  transform: scale(1.1);
}

.attachment-menu .menu-btn i {
  font-size: 20px;
}

/* Tooltip text for menu buttons */
.attachment-menu .menu-btn::after {
  content: attr(data-type);
  /* or use text content */
  position: absolute;
  left: 60px;
  background: white;
  color: #333;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 14px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  text-transform: capitalize;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.attachment-menu .menu-btn:hover::after {
  opacity: 1;
}

/* Preview Modal */
.preview-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.preview-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.preview-content {
  background: white;
  width: 90%;
  max-width: 500px;
  border-radius: 10px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-content .media-container {
  width: 100%;
  max-height: 400px;
  display: flex;
  justify-content: center;
  background: #f0f0f0;
  margin-bottom: 15px;
  border-radius: 5px;
  overflow: hidden;
}

.preview-content .media-container img,
.preview-content .media-container video {
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
}

.preview-content .media-container i {
  font-size: 80px;
  color: #ccc;
  padding: 50px;
}

.preview-content .file-info {
  margin-bottom: 20px;
  text-align: center;
}

.preview-content .file-name {
  display: block;
  font-weight: 500;
  color: #333;
  margin-bottom: 5px;
}

.preview-content .file-size {
  font-size: 12px;
  color: #777;
}

.preview-content .preview-actions {
  display: flex;
  gap: 15px;
  width: 100%;
  justify-content: center;
}

.preview-content button {
  padding: 10px 25px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.3s;
}

.preview-content .cancel-btn {
  background: #f1f1f1;
  color: #333;
}

.preview-content .confirm-send-btn {
  background: var(--theme-color);
  color: white;
}

.typing-area .file-upload-btn {
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-main);
  cursor: pointer;
  border: 1px solid var(--border-color);
  border-right: none;
  border-radius: 5px 0 0 5px;
  background: var(--input-bg);
}

.typing-area input.input-field {
  border-radius: 0;
}

.chat-box .chat .details p img,
.chat-box .chat .details p video {
  max-width: 100%;
  border-radius: 5px;
  margin-top: 5px;
}

.chat-box .chat .details p a {
  color: #fff;
  text-decoration: underline;
}

.chat-box .incoming .details p a {
  color: #333;
}

body.dark-theme .chat-box .incoming .details p a {
  color: var(--text-main);
}

.typing-area button.active {
  opacity: 1;
  pointer-events: auto;
}

/* Responsive Layout Updates */
@media screen and (min-width: 900px) {
  .wrapper {
    max-width: 900px;
    /* Wider layout for laptops/desktops */
  }

  .chat-box {
    max-height: 600px;
    /* Taller chat area on large screens */
  }
}

/* ... rest of the responsiveness ... */
@media screen and (max-width: 450px) {
  body {
    padding: 0;
    align-items: flex-start;
    /* Start from top */
    background: var(--wrapper-bg);
    /* Match wrapper bg to hide edges */
  }

  .wrapper {
    width: 100%;
    height: 100vh;
    /* Full viewport height */
    max-width: none;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
  }

  .chat-area {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  .form,
  .users {
    padding: 20px;
  }

  /* Ensure users list scrolls within the remaining height */
  .users {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .users-list {
    max-height: none;
    flex: 1;
  }

  .form header {
    text-align: center;
  }

  .form form .name-details {
    flex-direction: column;
  }

  .form .name-details .field:first-child {
    margin-right: 0px;
  }

  .form .name-details .field:last-child {
    margin-left: 0px;
  }

  .users header img {
    height: 45px;
    width: 45px;
  }

  .users header .logout {
    padding: 6px 10px;
    font-size: 16px;
  }

  :is(.users, .users-list) .content .details {
    margin-left: 15px;
  }

  .users-list a {
    padding-right: 10px;
  }

  .chat-area header {
    padding: 15px 20px;
  }



  .chat-box .chat p {
    font-size: 15px;
  }

  .chat-box .outogoing .details {
    max-width: 230px;
  }

  .chat-box {
    min-height: auto;
    flex: 1;
    /* Take available space */
    padding: 10px 15px 15px 20px;
    height: auto;
    /* Override fixed height */
    max-height: none;
    /* Override fixed max-height */
  }

  .chat-box .outgoing .details {
    max-width: 75%;
  }

  .chat-box .incoming .details {
    max-width: 75%;
  }

  .incoming .details img {
    height: 30px;
    width: 30px;
  }

  .typing-area {
    padding: 18px 20px;
  }

  .typing-area input {
    height: 40px;
    min-width: 0;
    /* Important for flex */
    flex: 1;
    margin: 0 5px;
  }

  .typing-area button,
  .typing-area .attach-btn {
    width: 45px;
    pointer-events: auto;
  }
}

/* Lightbox & Preview (keeping existing) */
.preview-area {
  display: none;
  padding: 10px 20px;
  background: var(--input-bg);
  border-top: 1px solid var(--border-color);
  position: relative;
}

.preview-area .remove-btn {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  font-size: 18px;
  color: var(--text-secondary);
}

.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.lightbox.active {
  display: flex;
}

.lightbox-content {
  max-width: 90%;
  max-height: 80%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.lightbox-content img,
.lightbox-content video {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 5px;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

.close-lightbox {
  position: absolute;
  top: 20px;
  right: 30px;
  font-size: 40px;
  color: #fff;
  cursor: pointer;
  transition: 0.3s;
}

.close-lightbox:hover {
  color: #ccc;
}

.download-btn {
  margin-top: 20px;
  padding: 10px 20px;
  background: #333;
  color: #fff;
  text-decoration: none;
  border-radius: 5px;
  font-size: 16px;
  display: flex;
  align-items: center;
}

.download-btn i {
  margin-right: 8px;
}

.download-btn:hover {
  background: #555;
}

/* Call Modal */
.call-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  /* Darker dim */
  z-index: 2000;
  /* Highest priority */
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.call-modal.active {
  display: flex;
}

.call-content {
  color: white;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.call-user-img img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 4px solid white;
  object-fit: cover;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
  }

  70% {
    box-shadow: 0 0 0 20px rgba(255, 255, 255, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

.call-content h3 {
  font-size: 24px;
  font-weight: 500;
}

.call-content p {
  font-size: 16px;
  opacity: 0.8;
}

.call-actions {
  margin-top: 50px;
  display: flex;
  gap: 40px;
}

.call-actions button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  font-size: 24px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.call-actions button:hover {
  transform: scale(1.1);
}

.btn-red {
  background: #e74c3c;
}

.btn-green {
  background: #2ecc71;
}

/* Message Ticks */
.chat-box .chat .details p .tick {
  font-size: 10px;
  margin-left: 5px;
  color: #ccc;
  /* Default grey for single/sent */
}

.chat-box .chat .details p .tick.delivered {
  color: #ccc;
}

.chat-box .chat .details p .tick.read {
  color: #34b7f1;
  /* Blue for read */
}

/* Reply Styles */
.reply-preview-area {
  padding: 10px 20px;
  background: #f0f0f0;
  border-left: 5px solid var(--theme-color);
  display: none;
  /* Hidden by default */
  justify-content: space-between;
  align-items: center;
  position: absolute;
  bottom: 80px;
  /* Above input area */
  width: 100%;
  box-sizing: border-box;
  z-index: 99;
}

.reply-preview-area.active {
  display: flex;
}

.reply-preview-content {
  display: flex;
  flex-direction: column;
}

.reply-preview-user {
  font-weight: bold;
  font-size: 12px;
  color: var(--theme-color);
}

.reply-preview-text {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.reply-preview-close {
  cursor: pointer;
  font-size: 20px;
  color: #555;
  padding: 5px;
}

/* Replied Message Styling inside chat */
.reply-content {
  background: rgba(0, 0, 0, 0.05);
  /* Slight darken */
  border-left: 4px solid var(--theme-color);
  padding: 5px 8px;
  margin-bottom: 5px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}

.incoming .reply-content {
  background: rgba(0, 0, 0, 0.05);
}

.outgoing .reply-content {
  background: rgba(0, 0, 0, 0.1);
}

.reply-content .reply-user {
  font-weight: bold;
  font-size: 11px;
  color: var(--theme-color);
  /* Or a specific color */
  margin-bottom: 2px;
}

.reply-content .reply-text {
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat .reply-btn {
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  color: #999;
  cursor: pointer;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s;
}

.chat:hover .reply-btn {
  opacity: 1;
}

@media screen and (max-width: 450px) {
  .chat .reply-btn {
    opacity: 0.7;
    /* Always visible on mobile */
  }
}