/* ==============================
   Global Reset
   ============================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: Arial, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #f9f9f9;
}

/* ==============================
   Header
   ============================== */
header {
  background: #fff;
  padding: 0.8rem 1rem;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

header .branding {
  display: flex;
  align-items: center;
  gap: 10px;
}

header img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

header h1 {
  font-size: 1.2rem;
  color: #333;
}

/* ==============================
   Container & Layout
   ============================== */
.container {
  display: flex;
  flex: 1;
  gap: 10px;
  overflow: hidden;
}

/* ==============================
   Chat Section
   ============================== */
.chat-section {
  flex: 2;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #ccc;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  min-height: 0;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  border-bottom: 1px solid #ddd;
  background: #f5f5f5;
  flex-shrink: 0;
}

.chat-header img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 10px;
}

.chat-header span {
  font-weight: bold;
  font-size: 16px;
  color: #333;
}

/* Chat Box */
.chat-box {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  min-height: 0;
}

/* Messages */
.message-wrapper {
  display: flex;
  margin-bottom: 8px;
  max-width: 100%;
}

.message-wrapper.sent {
  justify-content: flex-end;
}

.message-wrapper.received {
  justify-content: flex-start;
  gap: 8px;
}

.message {
  padding: 10px 15px;
  border-radius: 20px;
  line-height: 1.4;
  max-width: 70%;
  display: inline-block;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 0.95rem;
}

.message.sent {
  background-color: #36c36c;
  color: white;
  text-align: right;
  border-bottom-right-radius: 0;
}

.message.received {
  background-color: #f1f1f1;
  color: #333;
  text-align: left;
  border-bottom-left-radius: 0;
}

.message-profile {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* ==============================
   Input Area
   ============================== */
.input-area {
  display: flex;
  padding: 10px;
  border-top: 1px solid #ccc;
  background: #fff;
  flex-shrink: 0;
  gap: 8px;
  align-items: flex-end;
}

.input-area input,
.input-area textarea {
  flex: 1;
  padding: 10px 15px;
  border-radius: 25px;
  border: 1px solid #ccc;
  outline: none;
  font-size: 1rem;
  resize: none;
  overflow-y: hidden;
}

.input-area button {
  padding: 10px 20px;
  border: none;
  border-radius: 25px;
  background-color: #36c36c;
  color: white;
  cursor: pointer;
  font-size: 1rem;
}

.input-area button:hover {
  opacity: 0.9;
}

/* ==============================
   Users Section
   ============================== */
.users-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #ccc;
  background: #fff;
  min-width: 200px;
  overflow: hidden;
}

.users-section h3 {
  padding: 15px;
  border-bottom: 1px solid #ccc;
  font-size: 1rem;
  background: #f5f5f5;
}

.user-search-box {
  width: 95%;
  margin: 8px auto 12px auto;
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid #ccc;
  outline: none;
  font-size: 0.95rem;
  display: block;
}

.user-search-box:focus {
  border-color: #272c29;
  box-shadow: 0 0 5px rgba(5, 5, 5, 0.5);
}

#users-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.user-btn {
  padding: 10px 15px;
  border: none;
  background-color: #f1f1f1;
  cursor: pointer;
  text-align: left;
  border-radius: 8px;
  transition: 0.2s;
}

.user-btn.active {
  background: linear-gradient(135deg, #4a90e2, #357abd);
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  transform: scale(1.02);
  transition: all 0.2s ease-in-out;
}

.user-btn.active:hover {
  background-color: #f0f0f0;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.user-name {
  font-weight: 600;
  font-size: 14px;
  color: #333;
}

.last-message {
  font-size: 15px;
  color: #615f5f;
  margin-top: 10px;
  margin-left: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  font-style: italic;
}

.last-time {
  margin-top: 10px;
}

/* ==============================
   Bottom Navigation
   ============================== */
.bottom-nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 55px;
  background: #fff;
  border-top: 1px solid #ccc;
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.75rem;
  color: #555;
  text-decoration: none;
  position: relative;
}

.bottom-nav i {
  font-size: 1.2rem;
}

/* Unread badge for bottom nav (Message icon) */
.badge {
  position: absolute;
  bottom: 50px;
  left: 25px;
  background:none;
  color: red;
  font-size: 12px;
  font-weight: bold;
  border-radius: 50%;
  padding: 3px 8px;
  display: none;
  line-height: 1;
}

/* Trusted MIDMAN usernames */
.midman-user .user-name {
  color: orange !important;
  font-weight: bold;
}

.midman-user .last-time {
  color: inherit !important;
  font-weight: normal;
}

/* ==============================
   Styles for unread message (users list)
   ============================== */
.user-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.unread-badge {
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 12px;
  padding: 2px 6px;
  display: none;
  line-height: 1;
}

/*username chat display*/
/* 🔹 Shared header style */
.user-section-header {
  font-size: 1.1rem;
  font-weight: bold;
  margin: 10px 0 6px;
  padding: 6px 10px;
  border-radius: 6px;
}

/* Trusted MIDMAN header */
.trusted-header {
  color: orange;
  border-left: 4px solid orange;
  font-size: 17px;
  background: rgba(255, 165, 0, 0.1);
}

/* Members header */
.members-header {
  color: steelblue;
  border-left: 4px solid steelblue;
  font-size: 17px;
  background: rgba(70, 130, 180, 0.1);
}

/* MIDMAN usernames */
.midman-user {
  color: orange;
  font-weight: bold;
}
.midman-user:hover {
  background: rgba(255, 165, 0, 0.15);
}

/* Member usernames */
.member-user {
  color: steelblue;
}
.member-user:hover {
  background: rgba(70, 130, 180, 0.15);
}

/* subtle highlight when new */
.user-btn .highlight {
  animation: none;
}
.user-btn.highlight {
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  transform: translateY(-1px);
}

/* ==============================
   Responsive Design
   ============================== */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
    flex: 1;
    height: calc(100vh - 55px - 60px);
    overflow: hidden;
    padding: 5px;
  }

  .chat-section {
    width: 100%;
    flex: 1;
    min-height: 0;
  }

  /* Give space at bottom for input + bottom nav */
  .chat-box {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow-y: auto;
    padding-bottom: 130px; /* enough space for input & bottom nav */
  }

  /* Fix input area at bottom */
  .input-area {
    position: fixed;
    bottom: 55px; /* above bottom nav */
    left: 0;
    width: 100%;
    padding: 8px 10px;
    background: #fff;
    border-top: 1px solid #ccc;
    z-index: 1001;
    gap: 8px;
    display: flex;
    align-items: flex-end;
  }

  .users-section {
    position: fixed;
    top: 60px;
    right: -100%;
    width: 250px;
    height: calc(100% - 60px);
    flex-direction: column;
    border-left: none;
    background: #fff;
    z-index: 1000;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.2);
    transition: right 0.3s;
    overflow-y: auto;
  }

  .users-section.show {
    right: 0;
  }

  .user-search-box {
    width: 90%;
    margin: 8px auto;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 1rem;
  }

  .input-area input,
  .input-area textarea {
    font-size: 0.9rem;
  }

  .input-area button {
    padding: 8px 16px;
    font-size: 0.9rem;
  }

  .chat-box {
    padding-bottom: 120px; /* adjust for smaller screens */
  }

  .bottom-nav a {
    font-size: 0.65rem;
  }

  .bottom-nav i {
    font-size: 1rem;
  }
}
