/* WhatsApp Inbox Styles */
#wa-inbox-modal.modal {
  padding-right: 0 !important; /* Remove Bootstrap padding */
  Z-INDEX: 1062;
}

#wa-inbox-modal .modal-dialog.modal-fullscreen {
  margin: 0;
  max-width: none;
  width: 100%;
  height: 100%;
}

#wa-inbox-modal .modal-content {
  border-radius: 0;
  display: flex;
  flex-direction: column;
  height: 100vh; /* Full viewport height */
  width: 100vw; /* Full viewport width */
  border: none; /* Remove border */
}

#wa-inbox-modal .modal-header {
  flex-shrink: 0; /* Prevent shrinking */
  background-color: #fff;
  border-bottom: 1px solid #dee2e6;
}

#wa-inbox-modal .modal-body {
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0; /* Allow shrinking */
  overflow: hidden; /* Prevent any overflow */
}

#contacts-container {
  background-color: #fff;
  border-right: 1px solid #dee2e6;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0; /* Allow shrinking */
}

#contact-list {
  overflow-y: auto; /* Scroll only when needed */
  flex: 1; /* Take available space */
  min-height: 0; /* Allow shrinking */
}

.contact-item {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background-color 0.2s;
  position: relative;
  flex-shrink: 0; /* Prevent contacts from shrinking */
}

.contact-item:hover {
  background-color: #f8f9fa;
}

.contact-item.active {
  background-color: #e8f5e9;
  border-left: 3px solid #25d366;
}

.contact-name {
  font-weight: 500;
  color: #333;
  margin-bottom: 4px;
}

.contact-last-message {
  font-size: 13px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.contact-time {
  font-size: 11px;
  color: #999;
  position: absolute;
  right: 16px;
  top: 12px;
}

.contact-unread-badge {
  background-color: #25d366;
  color: white;
  font-size: 11px;
  font-weight: bold;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 16px;
  bottom: 12px;
}

/* Chat Panel Layout */
#chat-panel {
  background-color: #f0f2f5;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0; /* Allow shrinking */
}

/* Fixed Header Area */
#mobile-chat-header,
#chat-header {
  background-color: #f0f2f5;
  border-bottom: 1px solid #dee2e6;
  flex-shrink: 0; /* Prevent shrinking */
  z-index: 1062;
}

/* Scrollable Messages Container */
#chat-messages {
  background-color: #f2ffea !important; /* WhatsApp background color */
  background-image: none !important; /* Remove the pattern */
  flex: 1; /* Take available space */
  overflow-y: auto; /* Scroll only messages */
  min-height: 0; /* Allow shrinking */
  padding: 0 20px !important; /* Add 20px padding to container */
  display: flex;
  flex-direction: column;
}

/* Fixed Footer (Input Area) */
#send-form {
  background-color: #f0f2f5;
  border-top: 1px solid #dee2e6;
  flex-shrink: 0; /* Prevent shrinking */
  z-index: 1062;
}

/* Message Bubbles */
.message {
  max-width: 100%;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  position: relative;
  animation: fadeIn 0.3s ease;
  flex-shrink: 0; /* Prevent messages from shrinking */
}

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

.message.incoming {
  background-color: white;
  border-radius: 0 8px 8px 8px;
  align-self: flex-start;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.1);
  margin-left: 5px !important; /* Fixed 5px left margin */
  margin-right: auto;
}

.message.outgoing {
  background-color: #dcf8c6;
  border-radius: 8px 0 8px 8px;
  align-self: flex-end;
  margin-left: auto;
  margin-right: 5px !important; /* Fixed 5px right margin */
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.1);
}

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

.message-status {
  font-size: 12px;
  margin-left: 4px;
}

.message-status.delivered {
  color: #999;
}

.message-status.read {
  color: #34b7f1;
}

/* Scrollbar Styles */
#contact-list::-webkit-scrollbar,
#chat-messages::-webkit-scrollbar {
  width: 6px;
}

#contact-list::-webkit-scrollbar-track,
#chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

#contact-list::-webkit-scrollbar-thumb,
#chat-messages::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

#contact-list::-webkit-scrollbar-thumb:hover,
#chat-messages::-webkit-scrollbar-thumb:hover {
  background: #f2ffea;
}

/* ===== RESPONSIVE STYLES ===== */
@media (max-width: 768px) {
  #wa-inbox-modal.modal {
    padding-right: 0 !important;
  }
  
  #contacts-container {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1062;
    transition: transform 0.3s ease;
  }
  
  /* FIX: Hide chat panel completely when inactive on mobile */
  #chat-panel {
    width: 100%;
    position: absolute;
    left: 100%;
    top: 0;
    bottom: 0;
    z-index: 1062;
    display: none !important; /* Completely hidden when inactive */
    transition: left 0.3s ease;
  }
  
  /* FIX: Only show when active class is added */
  #chat-panel.active {
    left: 0;
    display: flex !important; /* Show when active */
  }
  
  .contact-item {
    padding: 14px 16px;
  }
  
  .message {
    max-width: 85%;
  }
  
  /* Keep 5px margins on mobile */
  .message.incoming {
    margin-left: 5px !important;
  }
  
  .message.outgoing {
    margin-right: 5px !important;
  }
  
  #chat-messages {
    padding: 0 5px !important;
  }
  
  /* Mobile header/footer padding */
  #mobile-chat-header {
    padding: 10px 15px;
  }
  
  #send-form {
    padding: 10px 15px;
  }
}

@media (min-width: 769px) {
  /* Make modal truly fullscreen on desktop */
  #wa-inbox-modal.modal {
    padding-right: 0 !important;
  }
  
  #wa-inbox-modal .modal-dialog.modal-fullscreen {
    margin: 0;
    max-width: none;
    width: 100%;
    height: 100%;
  }
  
  #wa-inbox-modal .modal-content {
    height: 100vh;
    width: 100vw;
    border: none;
    border-radius: 0;
  }
  
  /* Contacts panel - fixed width */
  #contacts-container {
    width: 350px !important; /* Fixed width */
    flex: 0 0 350px !important; /* Don't grow or shrink */
    position: static !important;
  }
  
  /* Chat panel - takes remaining space */
  #chat-panel {
    position: static !important;
    left: 0 !important;
    display: flex !important;
    flex: 1; /* Take remaining space */
  }
  
  #mobile-chat-header {
    display: none !important;
  }
  
  /* Header visibility control */
  #chat-header {
    display: block !important;
    padding: 15px 20px;
  }
  
  #chat-messages {
    padding: 0 20px !important;
  }
  
  #send-form {
    padding: 15px 20px;
  }
  
  /* Ensure messages stay at 100% width on desktop */
  .message {
    max-width: 100% !important;
  }
}

/* Additional utility classes */
.container-fluid.p-0.flex-grow-1.d-flex.flex-column {
  min-height: 0; /* Allow shrinking */
}

.row.g-0.flex-grow-1.d-flex.position-relative {
  min-height: 0; /* Allow shrinking */
}

/* Remove any default Bootstrap padding/margin */
.modal-open {
  padding-right: 0 !important;
  overflow: hidden;
}