/* ================================================================
   XecureCom Modern Messenger - Full Production CSS (Updated)
   Includes: fixed mobile chat transitions, footer layout, and visibility logic
================================================================ */

/* ==================== GLOBAL RESET ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  height: 100vh;
  overflow: hidden;
  background: #fff;
}

/* ==================== SPLASH SCREEN ==================== */
.splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s, visibility 0.5s;
}

.splash-screen.active {
  opacity: 1;
  visibility: visible;
}

.splash-content {
  text-align: center;
  color: white;
}

.logo-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.app-title {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.app-tagline {
  font-size: 1.1rem;
  opacity: 0.9;
}

.splash-loader {
  height: 4px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  margin: 1.5rem auto 0;
  width: 200px;
}

.loader-bar {
  height: 4px;
  width: 30%;
  background: #fff;
  border-radius: 4px;
  animation: load 1.2s infinite;
}

@keyframes load {
  0% { margin-left: 0; }
  50% { margin-left: 70%; }
  100% { margin-left: 0; }
}

/* ==================== APP CONTAINER ==================== */
#app {
  height: 100vh;
  width: 100vw;
  display: flex;
}

#app.hidden {
  display: none;
}

.screen {
  flex: 1;
  display: none;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* ==================== AUTH SCREEN ==================== */
.auth-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.auth-card {
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 440px;
  padding: 3rem;
}

.auth-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.auth-logo {
  font-size: 3.5rem;
  margin-bottom: 1rem;
}

.auth-header h1 {
  font-size: 2rem;
  color: #202124;
  margin-bottom: 0.5rem;
}

.auth-header p {
  color: #5f6368;
  font-size: 0.95rem;
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
}

.auth-form h2 {
  font-size: 1.75rem;
  color: #202124;
  margin-bottom: 0.5rem;
}

.form-subtitle {
  color: #5f6368;
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.form-field {
  margin-bottom: 1.5rem;
}

.form-field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #202124;
  margin-bottom: 0.5rem;
}

.form-field input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.2s;
}

.form-field input:focus {
  outline: none;
  border-color: #667eea;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: #007aff;
  color: white;
}

.btn-primary:hover {
  background: #0051d5;
}

.btn-block {
  width: 100%;
  padding: 14px;
}

.form-footer {
  margin-top: 1.5rem;
  text-align: center;
  color: #5f6368;
  font-size: 0.9rem;
}

.form-footer a {
  color: #007aff;
  text-decoration: none;
  font-weight: 500;
}

.form-footer a:hover {
  text-decoration: underline;
}

/* ==================== MAIN LAYOUT ==================== */
.container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==================== CONTACTS SIDEBAR ==================== */
.contacts-sidebar {
  width: 360px;
  min-width: 360px;
  max-width: 360px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  padding: 20px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.header h1 {
  font-size: 24px;
  font-weight: 500;
  color: #202124;
}

.btn-add-contact {
  width: 36px;
  height: 36px;
  border: none;
  background: #007aff;
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-add-contact:hover {
  background: #0051d5;
}

.search-bar {
  padding: 12px 20px;
  background: #f1f3f4;
  border-radius: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-bar input {
  background: transparent;
  border: none;
  outline: none;
  flex: 1;
  font-size: 14px;
  color: #202124;
}

.search-bar input::placeholder {
  color: #5f6368;
}

.contacts-list {
  flex: 1;
  overflow-y: auto;
}

.contact-item {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
}

.contact-item:hover {
  background: #f8f9fa;
}

.contact-item.active {
  background: #e8f0fe;
}

.contact-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 500;
  font-size: 18px;
  flex-shrink: 0;
}

.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.contact-name {
  font-weight: 500;
  color: #202124;
  font-size: 16px;
}

.contact-time {
  font-size: 12px;
  color: #5f6368;
}

.contact-last-msg,
.contact-last-message {
  color: #5f6368;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==================== SIDEBAR FOOTER ==================== */
.sidebar-footer {
  border-top: 1px solid #e0e0e0;
  background: #fff;
}

/* Emergency + Profile Section */
.emergency-section {
  padding: 12px;
  border-top: 1px solid #e0e0e0;
}

.emergency-controls {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.emergency-btn {
  flex: 1;
  padding: 10px 8px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}

.emergency-btn:hover {
  background: #f8f9fa;
  transform: translateY(-1px);
}

.emergency-btn .icon {
  font-size: 20px;
}

.emergency-btn .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
  color: #5f6368;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  transition: background 0.2s;
}

.user-profile:hover {
  background: #f8f9fa;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 500;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-weight: 500;
  color: #202124;
  font-size: 14px;
}

.user-status {
  font-size: 12px;
  color: #5f6368;
}

/* ==================== CHAT AREA ==================== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  min-width: 0;
  overflow: hidden;
  transition: transform 0.3s ease;
}

/* 🔧 EMPTY STATE - VISIBLE BY DEFAULT */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #5f6368;
  text-align: center;
  padding: 40px;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.5rem;
  color: #202124;
  margin-bottom: 0.5rem;
}

.empty-state p {
  font-size: 1rem;
}

/* 🔧 CHAT CONTAINER - HIDDEN BY DEFAULT */
#chatContainer {
  display: none;
  flex-direction: column;
  flex: 1;
  height: 100%;
  overflow: hidden;
  background: #fff;
}

/* ==================== CHAT HEADER ==================== */
.chat-header {
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 500;
  cursor: pointer;
}

.chat-header-info {
  flex: 1;
}

.chat-header-info h2 {
  font-size: 18px;
  font-weight: 500;
  color: #202124;
  margin-bottom: 2px;
}

.chat-status {
  font-size: 13px;
  color: #5f6368;
}

/* 🔧 CHAT RECIPIENT HEADER */
.chat-recipient {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 500;
  font-size: 16px;
  flex-shrink: 0;
}

.chat-recipient-name {
  font-size: 18px;
  font-weight: 500;
  color: #202124;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* ==================== MESSAGES CONTAINER ==================== */
#messagesContainer,
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
}
.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ef4444;
  color: white;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
}
.message {
  display: flex;
  margin-bottom: 16px;
  gap: 8px;
  width: 100%;
  animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.sent { 
  justify-content: flex-end; 
}

.message.received { 
  justify-content: flex-start; 
}

.message-content {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  min-width: 0;
  gap: 4px;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.4;
}

.message.sent .message-bubble {
  background: #007aff;
  color: white;
  border-bottom-right-radius: 4px;
}

.message.received .message-bubble {
  background: #e5e5ea;
  color: #000;
  border-bottom-left-radius: 4px;
}

.message-text {
  word-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-time {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.7;
  color: #5f6368;
  align-self: flex-end;
}

.message.received .message-time {
  align-self: flex-start;
}

/* ==================== INPUT AREA ==================== */
.input-area {
  padding: 16px 24px;
  background: #fff !important; /* 🔧 Force white background */
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-shrink: 0;
}

.input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  background: #f1f3f4 !important; /* 🔧 Force light gray background */
  border-radius: 24px;
  padding: 10px 20px;
}

.input-wrapper input,
#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 15px;
  color: #202124 !important; /* 🔧 Force dark text */
  font-family: inherit;
  -webkit-text-fill-color: #202124 !important; /* 🔧 Safari fix */
}

/* 🔧 Additional specificity for input */
#chatContainer #messageInput,
.input-area #messageInput {
  color: #202124 !important;
  -webkit-text-fill-color: #202124 !important;
}

.input-wrapper input::placeholder,
#messageInput::placeholder {
  color: #5f6368;
}

.send-button,
#sendBtn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #007aff;
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 20px;
  flex-shrink: 0;
}

.send-button:hover,
#sendBtn:hover {
  background: #0051d5;
  transform: scale(1.05);
}

.send-button:disabled,
#sendBtn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: scale(1);
}

/* ==================== ICON BUTTONS ==================== */
.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: #5f6368;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  transform: scale(1.1);
}

/* ==================== UNREAD BADGE ==================== */
.unread-badge {
  min-width: 20px;
  height: 20px;
  background: #007aff;
  color: white;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

/* ==================== MODAL OVERLAYS ==================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: white;
  border-radius: 16px;
  padding: 0;
  max-width: 90%;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 20px;
  font-weight: 500;
  color: #202124;
  margin: 0;
}

.close-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #5f6368;
  font-size: 24px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.close-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(90vh - 140px);
}

/* ==================== MENU DROPDOWN ==================== */
#menuDropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  min-width: 220px;
  overflow: hidden;
  display: none;
  z-index: 1000;
}

#menuDropdown.show {
  display: block;
  animation: menuSlideDown 0.2s ease-out;
}

@keyframes menuSlideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.menu-item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: #202124;
  transition: background 0.2s;
}

.menu-item:hover {
  background: #f8f9fa;
}

.menu-item span {
  font-size: 18px;
}

.menu-divider {
  height: 1px;
  background: #e0e0e0;
  margin: 4px 0;
}

/* ==================== TRUST REQUEST BANNER ==================== */
@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.trust-request-item {
  transition: all 0.3s ease;
}

.trust-request-item:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

/* ==================== MOBILE STYLES ==================== */
@media screen and (max-width: 768px) {

  body, html {
    height: -webkit-fill-available;
  }

  .container {
    position: relative;
    height: 100vh;
    height: -webkit-fill-available;
    overflow: hidden;
  }

  .contacts-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    min-width: 100%;
    height: 100%;
    z-index: 10;
    transform: translateX(0);
    transition: transform 0.3s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }

  .contacts-sidebar.hidden {
    transform: translateX(-100%) !important;
  }

  .chat-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 5;
  }

  .chat-area.active {
    transform: translateX(0) !important;
    z-index: 15 !important;
  }

  /* Footer always visible */
  .sidebar-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    z-index: 20;
  }

  .user-profile {
    padding: 12px 16px;
    justify-content: space-between;
    align-items: center;
  }

  .emergency-section {
    display: flex;
    flex-direction: column;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  #messagesContainer,
  .messages-container {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
  }

  .container { overflow: hidden; }

  /* Larger tap targets */
  .contact-item { 
    padding: 18px 16px; 
  }
  
  .contact-avatar { 
    width: 54px; 
    height: 54px; 
    font-size: 22px; 
  }
  
  .contact-name { 
    font-size: 18px; 
  }
  
  .contact-last-message,
  .contact-last-msg { 
    font-size: 16px; 
  }

  /* Input area fix */
  .input-area {
    position: relative;
    padding: 14px 16px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .send-button,
  #sendBtn {
    width: 50px;
    height: 50px;
    font-size: 24px;
  }

  .empty-state h3 { 
    font-size: 2rem; 
  }
  
  .empty-state p { 
    font-size: 1.2rem; 
  }

  /* Chat header mobile */
  .chat-header {
    padding: 12px 16px;
  }

  .chat-recipient-name {
    font-size: 16px;
  }

  /* Message bubbles mobile */
  .message-content {
    max-width: 85%;
  }

  .message-bubble {
    font-size: 15px;
  }
}

/* ==================== SMALL MOBILE ==================== */
@media screen and (max-width: 400px) {
  .header h1 { 
    font-size: 22px; 
  }
  
  .contact-name { 
    font-size: 17px; 
  }
  
  .contact-last-message,
  .contact-last-msg { 
    font-size: 15px; 
  }
  
  .message-bubble { 
    font-size: 14px; 
  }

  .chat-recipient-name {
    font-size: 15px;
  }
}

/* ==================== SCROLLBAR STYLING ==================== */
.messages-container::-webkit-scrollbar,
#messagesContainer::-webkit-scrollbar,
.contacts-list::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track,
#messagesContainer::-webkit-scrollbar-track,
.contacts-list::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb,
#messagesContainer::-webkit-scrollbar-thumb,
.contacts-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover,
#messagesContainer::-webkit-scrollbar-thumb:hover,
.contacts-list::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* ==================== ANIMATIONS ==================== */
@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* ==================== ACCESSIBILITY ==================== */
*:focus-visible {
  outline: 2px solid #007aff;
  outline-offset: 2px;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid #007aff;
  outline-offset: 2px;
}

/* ==================== PRINT STYLES ==================== */
@media print {
  .emergency-section,
  .sidebar-footer,
  .input-area,
  .chat-actions {
    display: none !important;
  }
}