/* =======================================================
   PM BOX BASE
======================================================= */
#pmBox {
    position: fixed;
    bottom: 12px;
    right: 12px;

    width: 340px;
    max-width: calc(100vw - 20px);

    height: 420px;
    max-height: calc(100vh - 20px);

    z-index: 9999;
    display: none;

    /* required for dragging */
    touch-action: none;
}

#pmBox.visible {
    display: block;
}

.pmBoxInner {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;

    background: #0b0d17;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
    box-shadow: 0 0 18px rgba(0, 0, 0, 0.45);
    transition: height 0.2s ease;
}

/* =======================================================
   COLLAPSED MODE
======================================================= */
#pmBox.collapsed .pmMessages,
#pmBox.collapsed .pmInputBar {
    display: none;
}

#pmBox.collapsed .pmBoxInner {
    height: 50px !important;
}

/* rotate collapse button */
#pmBox.collapsed .pmCollapseBtn {
    transform: rotate(-90deg);
}

/* =======================================================
   HEADER (Draggable + Collapse + Close)
======================================================= */
.pmHeader {
    height: 48px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 14px;
    background: #0f111c;
    color: #fff;
    font-weight: 600;

    cursor: grab;
}

.pmHeader:active {
    cursor: grabbing;
}

/* buttons beside each other */
.pmHeaderButtons {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pmCollapseBtn,
.pmCloseBtn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    transition: 0.15s;
}

.pmCollapseBtn:hover,
.pmCloseBtn:hover {
    color: #fff;
}

/* =======================================================
   MESSAGES AREA
======================================================= */
.pmMessages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;

    padding: 12px;

    display: flex;
    flex-direction: column;
    gap: 10px;

    -webkit-overflow-scrolling: touch;
}

/* message rows */
.pm-row {
    display: flex;
    gap: 8px;
    max-width: 90%;
}

.pm-row.self {
    margin-left: auto;
    flex-direction: row-reverse;
}

.pm-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.pm-text {
    padding: 8px 12px;
    background: #1b1e2b;
    color: #fff;
    border-radius: 8px;
    max-width: 240px;
    word-break: break-word;
}

.pm-row.self .pm-text {
    background: #2962ff;
}

/* =======================================================
   INPUT BAR
======================================================= */
.pmInputBar {
    height: 52px;
    flex-shrink: 0;

    display: flex;
    align-items: center;
    padding: 6px 10px;
    background: #0f111c;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

#pmInput {
    flex: 1;
    height: 38px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: #151824;
    color: #fff;
    padding: 6px 10px;
}

#pmSendBtn {
    margin-left: 6px;
    height: 38px;
    padding: 0 14px;
    background: #2962ff;
    border-radius: 6px;
    border: none;
    color: #fff;
    cursor: pointer;
}

/* =======================================================
   MOBILE MODE — SMALLER PM BOX
======================================================= */
@media (max-width: 600px) {

    #pmBox {
        left: 50%;
        right: auto;
        bottom: 10px;
        transform: translateX(-50%);

        width: 85vw;
        height: 55vh;
        max-height: 55vh;
        border-radius: 10px;
    }

    .pm-text {
        max-width: 70vw;
    }
}
/* =======================================================
   FIX: Avatar class used in PM thread items
======================================================= */
.pm-avatar {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
}

/* =======================================================
   FIX: Ensure message bubbles never exceed PM box
======================================================= */
.pm-text {
    max-width: calc(100% - 50px);
    /* prevents overflow */
}

/* =======================================================
   FIX: Inbox items (pm_list.php)
======================================================= */
.pm-thread {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
}

.pm-thread:hover {
    background: rgba(255, 255, 255, 0.05);
}

.pm-thread .list-avatar {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
}

.pm-thread .list-name {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
}

.pm-thread .list-rank {
    font-size: 12px;
    color: #999;
}

.pm-thread .pm-preview {
    width: 100%;
    opacity: 0.8;
    font-size: 12px;
    margin-top: 2px;
}