:root {
  --paused-yellow: #f0c941;
}


/* ---------------------------------------------------------
 * Page layout
 * --------------------------------------------------------- */

html,
body {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
}

body {
  background-color: #f3f2f1;

  /*
   * Keep 100vh as a compatibility fallback.
   * 100dvh follows the currently visible mobile viewport.
   */
  height: 100vh;
  height: 100dvh;

  min-height: 0;
  overflow: hidden;

  display: flex;
  flex-direction: column;
}


/* ---------------------------------------------------------
 * Chat layout
 * --------------------------------------------------------- */

.chat-container {
  width: 100%;

  display: flex;

  /*
   * Let the body flex layout assign the remaining vertical
   * space instead of calculating it from a hardcoded 100vh.
   */
  flex: 1 1 auto;
  min-height: 0;
  height: auto;

  margin-top: 120px;
}


/* ---------------------------------------------------------
 * Sidebar
 * --------------------------------------------------------- */

.chat-sidebar {
  width: 280px;

  flex: 0 0 280px;
  min-height: 0;

  background: #ffffff;
  border-right: 1px solid #ddd;

  overflow-y: auto;
}

.chat-sidebar .chat-item {
  padding: 0.75rem 1rem;

  border-bottom: 1px solid #eee;

  cursor: pointer;

  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-sidebar .chat-item:hover {
  background-color: #f6f6f6;
}

.chat-sidebar .chat-item.active {
  background-color: #e6f0ff;
  border-left: 4px solid #0d6efd;
}

.chat-sidebar img {
  width: 40px;
  height: 40px;

  border-radius: 50%;
}


/* ---------------------------------------------------------
 * Main chat area
 * --------------------------------------------------------- */

.chat-main {
  flex: 1 1 auto;

  width: 100%;
  min-width: 0;
  min-height: 0;

  display: flex;
  flex-direction: column;

  background-color: #fafafa;

  /*
   * Prevent this flex child from extending beyond the space
   * assigned by the outer page layout.
   */
  overflow: hidden;
}

.chat-header {
  flex: 0 0 auto;

  background-color: #ffffff;
  border-bottom: 1px solid #ddd;

  padding: 0.75rem 1rem;

  display: flex;
  align-items: center;
  justify-content: space-between;
}


/* ---------------------------------------------------------
 * Messages
 * --------------------------------------------------------- */

.chat-messages {
  flex: 1 1 auto;

  min-width: 0;
  min-height: 0;

  overflow-y: auto;
  overflow-x: hidden;

  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;

  padding: 1rem 1.5rem;

  display: flex;
  flex-direction: column;
}

.message {
  max-width: 70%;

  padding: 0.6rem 0.9rem;
  margin-bottom: 0.75rem;

  position: relative;

  border-radius: 1rem;

  overflow-wrap: anywhere;
  word-wrap: break-word;
}

.message.me {
  align-self: flex-end;
  background-color: #dcf8c6;
}

.message.other {
  align-self: flex-start;
  background-color: #e8e8e8;
}

.message small {
  display: block;

  margin-top: 0.3rem;

  color: #666;

  font-size: 0.7rem;
  text-align: right;
}


/* ---------------------------------------------------------
 * Input area
 * --------------------------------------------------------- */

.chat-input {
  flex: 0 0 auto;

  width: 100%;
  min-width: 0;

  background-color: #ffffff;
  border-top: 1px solid #ddd;

  /*
   * Preserve the current spacing while accounting for mobile
   * safe-area insets where the browser exposes one.
   */
  padding:
    0.5rem
    1rem
    max(
      0.5rem,
      env(safe-area-inset-bottom, 0px)
    );
}

.chat-input > .position-relative {
  min-width: 0;
}

#messageInput {
  width: 100%;

  border-radius: 2rem;

  padding-left: 1rem;
}

#micButton {
  width: 40px;
  height: 40px;

  border-radius: 50%;
}

#sendBtn {
  flex: 0 0 auto;

  border-radius: 2rem;
}

.chat-input input.form-control {
  border-radius: 2rem;
}

.chat-input #micButton:hover i {
  color: #b02a37;
}

.chat-input #sendBtn i {
  font-size: 1rem;
}


/* ---------------------------------------------------------
 * Responsive layout
 * --------------------------------------------------------- */

@media (max-width: 991px) {
  .chat-container {
    flex: 1 1 auto;

    min-height: 0;
    height: auto;

    margin-top: 0;
    padding-top: 0;
  }

  .chat-main {
    min-height: 0;
  }

  .chat-messages {
    min-height: 0;
  }
}

@media (max-width: 768px) {
  .chat-sidebar {
    display: none;
  }
}

@media (max-width: 576px) {
  .chat-input {
    padding-right: 0.5rem;
    padding-left: 0.5rem;
  }

  #sendBtn {
    width: 36px;
    height: 36px;
  }

  #micButton i {
    font-size: 1.1rem;
  }

  #messageInput {
    font-size: 0.95rem;
  }
}


/* ---------------------------------------------------------
 * Chat list
 * --------------------------------------------------------- */

.chat-item {
  display: flex;
  align-items: center;

  padding: 0.5rem;

  position: relative;
  z-index: 2;

  border-radius: 0.5rem;

  cursor: pointer;

  user-select: none;
  -webkit-user-select: none;

  -webkit-tap-highlight-color: transparent;

  touch-action: manipulation;

  transition:
    background 0.2s ease;
}

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

.chat-avatar {
  width: 48px;
  height: 48px;

  object-fit: cover;
}

.avatar-wrapper {
  position: relative;
  display: inline-block;
}


/* ---------------------------------------------------------
 * Presence indicators
 * --------------------------------------------------------- */

.status-dot {
  position: absolute;

  right: 2px;
  bottom: 2px;

  width: 12px;
  height: 12px;

  border: 2px solid #fff;
  border-radius: 50%;
}

.status-dot.online {
  background-color: #28a745;
}

.status-dot.offline {
  background-color: #dc3545;
}

.status-dot.away {
  background-color: #c0c0c0;
}

.status-dot.paused {
  background-color: var(--paused-yellow);
}


/* ---------------------------------------------------------
 * Typing bubble
 * --------------------------------------------------------- */

.message.typing-bubble {
  max-width: 200px;

  margin: 5px 0;
  padding: 8px 14px;

  border-radius: 18px;

  background-color: #f1f0f0;

  display: inline-flex;
  align-items: center;
}

.typing-dots {
  display: flex;
  align-items: center;
}

.typing-dots .dot {
  width: 8px;
  height: 8px;

  margin: 0 3px;

  background-color: #a8a8a8;
  border-radius: 50%;

  animation:
    typingBounce
    1.4s
    infinite
    ease-in-out
    both;
}

.typing-dots .dot:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dots .dot:nth-child(2) {
  animation-delay: -0.16s;
}

.typing-dots .dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes typingBounce {
  0%,
  80%,
  100% {
    opacity: 0.5;
    transform: scale(0);
  }

  40% {
    opacity: 1;
    transform: scale(1);
  }
}