/* --- Chat / Messenger Component (Nested) --- */
.messenger-content {
  display: flex;
  flex-direction: column;
  height: 85vh;
  overflow: hidden !important;
  padding: 0 !important;
  max-width: 1000px !important;
  border: 1px solid rgba(255, 255, 255, 0.05) !important;

  .modal-header {
    border-bottom: 1px solid var(--glass-border);
    margin-bottom: 0;
    padding: 0 0 16px 0;
    flex-shrink: 0;
  }

  @media (max-width: 768px) {
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;

    .modal-header {
      display: flex !important;
      flex-shrink: 0 !important;
      padding-top: max(1.5rem, env(safe-area-inset-top)) !important;
    }
  }
}

.messenger-flex {
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
  background: #111b21;

  @media (max-width: 768px) {
    flex-direction: column !important;
    min-height: 0 !important;
  }

  /* Sidebar */
  .messenger-sidebar {
    background: #111b21;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    overflow-y: auto;
    width: 320px;
    display: flex;
    flex-direction: column;

    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-thumb {
      background: rgba(255, 255, 255, 0.1);
      border-radius: 3px;
    }

    @media (max-width: 768px) {
      border-right: none !important;
      width: 100% !important;

      &.inactive-chat {
        display: none !important;
      }
    }

    @media (max-width: 600px) {
      width: 100%;
    }

    .messenger-sidebar-header {
      padding: 10px 15px;
      background: #111b21;
      border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    .messenger-search {
      background: #202c33;
      border: none;
      border-radius: 8px;
      padding: 8px 12px;
      color: #e9edef;
      width: 100%;
      font-size: 0.9rem;
    }
  }

  /* Main Chat Area */
  .messenger-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #0b141a;
    position: relative;
    min-width: 0;
    overflow: hidden;

    @media (max-width: 768px) {
      display: none !important;
      width: 100% !important;
      min-height: 0 !important;
      height: auto !important;

      &.active-chat {
        display: flex !important;
      }
    }

    .messenger-placeholder {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100%;
      color: #8696a0;

      .placeholder-icon {
        font-size: 4rem;
        margin-bottom: 1rem;
        opacity: 0.1;
      }
    }
  }
}

/* Chat Items in Sidebar */
.messenger-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  background: transparent;

  &:hover {
    background: #202c33;
  }

  &.active {
    background: #2a3942;
  }

  .messenger-item-avatar {
    width: 48px;
    height: 48px;
    background: #2d2d3f;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
  }

  .messenger-item-info {
    flex: 1;
    min-width: 0;

    .messenger-item-name-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 2px;

      .messenger-item-name {
        font-weight: 600;
        color: #e9edef;
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .messenger-item-time {
        font-size: 0.75rem;
        color: #8696a0;
      }
    }

    .messenger-item-last {
      font-size: 0.85rem;
      color: #8696a0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;

      &.font-bold {
        font-weight: 700;
        color: var(--text-primary);
      }
    }
  }

  &.has-unread {
    .messenger-item-last {
      color: #e9edef;
      font-weight: 600;
    }
  }

  .unread-badge {
    background: #00a884;
    color: #111b21;
    font-size: 0.75rem;
    font-weight: 700;
    height: 20px;
    min-width: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    margin-left: 0.5rem;
  }
}

/* UI Elements inside Chat */
.chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;

  @media (max-width: 768px) {
    flex: 1 !important;
    height: auto !important;
    min-height: 0 !important;
  }

  .chat-header-bar {
    align-items: center;
    background: #202c33;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: #e9edef;

    .messenger-back-btn {
      display: none !important;

      @media (max-width: 768px) {
        display: flex !important;
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 10px;
        height: 38px;
        width: 38px;
        align-items: center;
        justify-content: center;
        color: #ffffff;
        margin-right: 10px;
        cursor: pointer;
        transition: var(--transition);

        &:active {
          transform: scale(0.9);
          background: rgba(255, 255, 255, 0.1);
        }
      }
    }
  }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-image: url("../img/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.jpg");
    background-repeat: repeat;
    background-attachment: scroll;
    background-blend-mode: overlay;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    background-color: rgba(0, 0, 0, 0.5);

    /* WhatsApp style bubbles */
    .chat-bubble {
      padding: 8px 12px;
      border-radius: 8px;
      font-size: 0.95rem;
      line-height: 1.4;
      max-width: 80%;
      position: relative;
      box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);

      &.bubble-own {
        align-self: flex-end;
        background: #005c4b;
        color: #e9edef;
        border-top-right-radius: 0;

        &::after {
          content: "";
          position: absolute;
          top: 0;
          right: -8px;
          width: 12px;
          height: 12px;
          background: #005c4b;
          clip-path: polygon(0 0, 0% 100%, 100% 0);
        }
      }

      &.bubble-other {
        align-self: flex-start;
        background: #202c33;
        color: #e9edef;
        border-top-left-radius: 0;

        &::after {
          content: "";
          position: absolute;
          top: 0;
          left: -8px;
          width: 12px;
          height: 12px;
          background: #202c33;
          clip-path: polygon(100% 0, 0 0, 100% 100%);
        }
      }

      .bubble-name {
        font-size: 0.75rem;
        font-weight: 700;
        margin-bottom: 2px;
        color: #ffd700;
      }

      .bubble-text {
        word-break: break-word;
      }

      .bubble-time {
        font-size: 0.65rem;
        opacity: 0.6;
        text-align: right;
        margin-top: 4px;
      }
    }
  }

  .chat-input-area {
    background: #202c33;
    padding: 12px 1rem;
    padding-bottom: calc(12px + env(safe-area-inset-top));
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;

    .chat-input {
      flex: 1;
      background: #2a3942;
      border: none;
      border-radius: 12px;
      height: 48px;
      padding: 0 16px;
      color: #d1d7db;
      font-size: 1rem;

      &:focus {
        outline: none;
        background: #374045;
      }
    }

    .btn-emoji {
      align-items: center;
      background: transparent;
      border: none;
      color: #8696a0;
      cursor: pointer;
      display: flex;
      justify-content: center;
    }
  }
}

.messenger-trigger-wrapper {
  position: relative;
}

.messenger-close-mobile {
  margin-left: auto;
  position: static !important;
}

.btn-send {
  align-items: center;
  background: var(--accent);
  border: none;
  color: var(--bg-dark);
  cursor: pointer;
  display: flex;
  justify-content: center;
  width: 60px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: var(--transition);
}

.btn-chat-participant {
  align-items: center;
  background: rgba(225, 254, 19, 0.1);
  border: 1px solid rgba(225, 254, 19, 0.2);
  border-radius: 8px;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  height: 28px;
  justify-content: center;
  margin-right: 0.25rem;
  transition: all 0.2s;
  width: 28px;

  &:hover {
    background: var(--accent);
    color: var(--bg-dark);
  }

  span {
    pointer-events: none;
  }
}

/* Global / Flyout Elements */
/* Global / Flyout Elements handled in header.css */

/* Utilities for Chat */
.show-mobile-flex {
  display: none !important;

  @media (max-width: 768px) {
    display: flex !important;
  }
}

.messenger-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}