/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
  /* Premium Color Palette */
  --primary-color: #3b82f6; /* Modern Blue */
  --primary-gradient: linear-gradient(135deg, #3b82f6, #2563eb);
  --secondary-bg: #f3f4f6;
  --white: #ffffff;
  --text-dark: #1f2937;
  --text-grey: #6b7280;
  --border-color: #e5e7eb;
  
  /* Status Colors */
  --success: #10b981;
  --danger: #ef4444;
  
  /* Shadows & Glass */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: 1px solid rgba(255, 255, 255, 0.3);
}

* {
  box-sizing: border-box;
}

body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--secondary-bg);
  color: var(--text-dark);
  overflow: hidden; /* Prevent body scroll */
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* =========================================
   2. MAIN LAYOUT (SIDEBAR + CHAT)
   ========================================= */

/* Wrapper to hold Sidebar and Chat side-by-side */
.app-wrapper {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* --- Sidebar Area --- */
#overflow-menu-Bar {
  width: 320px; /* Fixed width for desktop */
  min-width: 300px;
  height: 100%;
  background: var(--white);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 20;
}

/* Fixed Header in Sidebar */
.menu-top-bar {
  padding: 20px;
  background: var(--white);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* Scrollable User List */
#overflow-menu {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  margin-top: 0; /* Reset previous margin */
}

/* --- Chat Area --- */
.container {
  flex: 1; /* Takes remaining width */
  position: relative; /* Changed from fixed */
  top: auto; left: auto; /* Reset fixed positions */
  width: auto;
  height: 100%;
  background: #fff;
  display: flex;
  flex-direction: column;
}

/* Background Pattern for Chat */
.container::before {
  content: "";
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0.4;
  background-image: radial-gradient(#e5e7eb 1px, transparent 1px);
  background-size: 20px 20px;
  z-index: 0;
  pointer-events: none;
}

/* =========================================
   3. COMPONENT STYLES
   ========================================= */

/* Search Bar */
.search-container {
  position: relative;
  width: 100%;
}

.search-container input {
  width: 100%;
  padding: 10px 20px 10px 15px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--secondary-bg);
  font-size: 14px;
  transition: all 0.3s ease;
}

.search-container input:focus {
  background: var(--white);
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  outline: none;
}

.search-icon {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-grey);
}

/* Menu Items (Users) */
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: transparent;
  border: 1px solid transparent;
}

.menu-title {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  color: var(--primary-color);
}

.menu-item:hover {
  background: var(--secondary-bg);
}

.menu-item.active {
  background: #eff6ff;
  border-color: #dbeafe;
}

  .profile-pic {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      margin-left: -5px;
      margin-right: 10px;
    }

.profile-pic-small {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--white);
  box-shadow: var(--shadow-sm);
}

.menu-item .memberUserName {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-dark);
  margin-bottom: 2px;
}

/* Chat Header */
#user-info {
  display: flex;
  align-items: center;
  padding: 15px 25px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

#user-info img {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 15px;
  box-shadow: var(--shadow-sm);
}

#selected-user {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
}

#user-status {
  font-size: 13px;
  color: var(--success);
  font-weight: 500;
}

/* Chat Box (Messages Area) */
#chat-box {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1;
}

/* Message Input Area */
.message-input-container {
  padding: 8px;
  background: var(--white);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.message-input-container input[type="text"] {
  flex: 1;
  padding: 12px 20px;
  border-radius: 25px;
  border: 1px solid var(--border-color);
  background: var(--secondary-bg);
  font-size: 15px;
  transition: all 0.3s;
}

.message-input-container input[type="text"]:focus {
  background: var(--white);
  border-color: var(--primary-color);
  outline: none;
}

.message-input-container button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  color: var(--primary-color);
  border-radius: 50%;
  transition: background 0.2s;
}

.message-input-container button:hover {
  background: #eff6ff;
}

/* =========================================
   4. MESSAGE BUBBLES
   ========================================= */

.message-container {
  display: flex;
  width: 100%;
  margin-bottom: 2px;
}

.message {
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  position: relative;
  max-width: 70%;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
}

/* Sent Messages */
.sent {
  justify-content: flex-end;
}

.sent .message {
  background: var(--primary-gradient);
  color: var(--white);
  border-bottom-right-radius: 4px; /* Distinct shape */
  border: none;
}

.sent .time-status {
  color: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  margin-top: 4px;
  text-align: right;
  display: block;
}

/* Received Messages */
.received {
  justify-content: flex-start;
}

.received .message {
  background: var(--white);
  color: var(--text-dark);
  border-bottom-left-radius: 4px; /* Distinct shape */
  border: 1px solid var(--border-color);
}

.received .time-status {
  color: var(--text-grey);
  font-size: 11px;
  margin-top: 4px;
  text-align: right;
  display: block;
}

/* =========================================
   5. MODALS & DIALOGS
   ========================================= */

/* Backdrop Filter for Modals */
.modal, #profile-dialog, #recording-dialog, #profile-update-dialog {
  backdrop-filter: blur(5px);
}

/* Generic Dialog Styling */
.dialog-box {
  background: var(--white);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.5);
  padding: 25px;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: translate(-50%, -50%) scale(0.9); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Fix specific modals based on your ID names */
#profile-dialog, #recording-dialog, #profile-update-dialog {
  /* Inherit generic styles by ensuring these IDs use the properties above */
  background: var(--white);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  border: none;
}

/* Close Button (Fixed Typo: clotse -> close-modal) */
.close-modal {
  position: absolute;
  top: 20px;
  right: 25px;
  color: var(--white);
  font-size: 30px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s;
}
.close-modal:hover { transform: scale(1.1); }

/* Buttons inside Dialogs */
.dialog-button, .profile-button, #send-audio-button, #confirm-edit {
  padding: 10px 20px;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

#edit-button, #send-audio-button, #confirm-edit {
  background: var(--primary-color);
  color: white;
}

#edit-button:hover, #send-audio-button:hover, #confirm-edit:hover {
  background: #2563eb;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

#close-button, #cancel-audio-button, .button-cancel {
  background: #fee2e2;
  color: var(--danger);
}

#close-button:hover, #cancel-audio-button:hover, .button-cancel:hover {
  background: #fecaca;
}

/* --- Floating Profile Button --- */
#my-profile-button {
  position: fixed;
  top: 12px;
  right: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  border: none;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 100; /* Ensure it floats above everything */
}

#my-profile-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(37, 99, 235, 0.4);
}

/* --- Mobile Transitions & Overrides --- */
@media screen and (max-width: 768px) {
  /* Hide the back button by default, JS toggles it */
  #back-button {
    display: none; 
  }

  /* The User List (Sidebar) */
  #overflow-menu-Bar {
    width: 100% !important; /* Force full width */
    transform: translateX(0);
    transition: transform 0.3s ease-in-out;
    position: absolute;
    z-index: 20;
  }

  /* The Chat Container */
  .container {
    width: 100% !important; /* Force full width */
    position: fixed; /* Fixed to cover screen */
    top: 0;
    left: 0;
    z-index: 30;
    transform: translateX(100%); /* Hidden to the right by default */
    transition: transform 0.3s ease-in-out;
    background: #fff;
  }

  /* Class added by JS to slide chat in */
  .container.show-chat {
    transform: translateX(0);
  }

  /* Class added by JS to push sidebar away (optional visual effect) */
  #overflow-menu-Bar.hide-sidebar {
    transform: translateX(-30%); /* Slight parallax effect */
  }
  
  /* Adjust Title Padding on Mobile */
  .menu-top-bar h3 {
    font-size: 24px !important;
  }
}

/* =========================================
   6. RESPONSIVENESS
   ========================================= */

/* Tablet and Mobile */
@media screen and (max-width: 768px) {
  .app-wrapper {
    position: relative;
  }

  /* Make sidebar full width initially */
  #overflow-menu-Bar {
    width: 100%;
    position: absolute;
    top: 0; left: 0;
    display: flex; /* Toggle this via JS usually, or assume side-by-side logic */
    transform: translateX(0);
    transition: transform 0.3s ease;
  }
  
  /* Chat container covers sidebar when active */
  .container {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    z-index: 30;
    transform: translateX(100%); /* Hidden by default on mobile */
    transition: transform 0.3s ease;
  }

  /* Utility class to show chat on mobile (You need to toggle this with JS) */
  .container.show-chat {
    transform: translateX(0);
  }

  /* Utility class to hide sidebar when chat is open */
  #overflow-menu-Bar.hide-sidebar {
    transform: translateX(-20%);
  }

  /* Message Widths on Mobile */
  .message {
    max-width: 85%;
  }
  
  /* Buttons */
  .menu-actions {
    flex-wrap: wrap;

  }
}