/* ===== Instagram-like direct messages ===== */
.messages-page-shell {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 18px;
    min-height: 690px;
}

.messages-sidebar,
.messages-thread-panel,
.chat-dock-panel {
    background: rgba(255,255,255,.94);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.messages-sidebar {
    display: flex;
    flex-direction: column;
}

.messages-sidebar-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 22px;
    border-bottom: 1px solid var(--line);
}

.messages-sidebar-head h1 {
    margin: 0;
    font-size: 2rem;
    letter-spacing: -.04em;
}

.icon-only {
    width: 42px;
    height: 42px;
    justify-content: center;
    padding: 0;
}

.messages-search {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px;
    padding: 0 14px;
    height: 46px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f6f9ff;
    color: var(--muted);
}

.messages-search input {
    border: 0;
    outline: none;
    background: transparent;
    width: 100%;
}

.messages-conversation-list {
    overflow: auto;
    padding: 8px;
    display: grid;
    gap: 4px;
}

.messages-conversation-item {
    width: 100%;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 18px;
    text-align: left;
    color: var(--text);
}

.messages-conversation-item:hover,
.messages-conversation-item.active {
    background: #f0f5ff;
}

.message-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--brand), #93a2ff);
    color: #fff;
    font-weight: 800;
    position: relative;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-avatar.online::after {
    content: '';
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #31c76a;
    border: 3px solid #fff;
}

.message-conversation-copy {
    min-width: 0;
}

.message-conversation-title {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: baseline;
}

.message-conversation-title strong,
.message-conversation-copy p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-conversation-title small,
.message-conversation-copy p {
    color: var(--muted);
}

.message-conversation-copy p {
    margin: 4px 0 0;
}

.message-unread-dot,
.message-fab-badge,
.message-header-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    background: var(--danger);
    color: #fff;
    font-size: .75rem;
    font-weight: 800;
}

.message-unread-dot.hidden,
.message-fab-badge.hidden,
.message-header-badge.hidden {
    display: none;
}

.messages-thread-panel {
    min-width: 0;
}

.messages-thread {
    min-height: 690px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.messages-thread-head {
    min-height: 76px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.messages-thread-user {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    min-width: 0;
}

.messages-thread-user div:last-child {
    display: grid;
    min-width: 0;
}

.messages-thread-user strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.messages-thread-user small {
    color: var(--muted);
}

.messages-list {
    overflow: auto;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: linear-gradient(180deg, rgba(247,250,255,.84), rgba(238,244,251,.65));
}

.message-bubble-row {
    display: flex;
}

.message-bubble-row.mine {
    justify-content: flex-end;
}

.message-bubble-row.theirs {
    justify-content: flex-start;
}

.message-bubble {
    max-width: min(70%, 520px);
    padding: 12px 14px;
    border-radius: 22px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.message-bubble-row.mine .message-bubble {
    background: linear-gradient(135deg, var(--brand), #7c8cff);
    color: #fff;
    border-bottom-right-radius: 8px;
}

.message-bubble-row.theirs .message-bubble {
    background: #fff;
    border: 1px solid var(--line);
    color: var(--text);
    border-bottom-left-radius: 8px;
}

.message-bubble p {
    margin: 0;
}

.message-bubble a {
    text-decoration: underline;
}

.message-bubble small {
    display: block;
    margin-top: 5px;
    opacity: .72;
    font-size: .72rem;
}

.message-compose {
    position: relative;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 46px;
    gap: 10px;
    align-items: end;
    padding: 14px 18px;
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.96);
}

.message-compose textarea {
    resize: none;
    min-height: 44px;
    max-height: 120px;
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 12px 14px;
    outline: none;
    font: inherit;
    background: #f8fbff;
}

.message-compose textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(90,103,216,.12);
}

.message-emoji-button,
.message-send-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    background: #f8fbff;
    color: var(--brand-dark);
}

.message-send-button {
    width: 46px;
    height: 46px;
    color: #fff;
    border: 0;
    background: linear-gradient(135deg, var(--brand), #7c8cff);
}

.message-emoji-popover {
    position: absolute;
    left: 16px;
    bottom: 70px;
    width: 230px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--shadow);
    z-index: 10;
}

.message-emoji-popover.hidden {
    display: none;
}

.message-emoji-popover button {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: #f5f8ff;
}

.messages-thread-empty,
.messages-empty {
    padding: 28px;
    text-align: center;
    color: var(--muted);
}

.messages-thread-empty {
    min-height: 690px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
}

.messages-thread-empty i {
    font-size: 3rem;
    color: var(--brand);
}

/* floating messenger */
.chat-dock {
    position: fixed;
    right: 22px;
    bottom: 18px;
    width: 370px;
    max-width: calc(100vw - 28px);
    z-index: 14000;
}

.chat-dock-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 430px);
    transform: translateY(calc(100% - 62px));
    transition: transform .24s ease;
}

.chat-dock.open .chat-dock-panel {
    transform: translateY(0);
}

.chat-dock-head {
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px 10px 16px;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    background: linear-gradient(180deg, #fff, #f8fbff);
}

.chat-dock-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
}

.chat-dock-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-dock-body {
    min-height: 0;
    overflow: auto;
    padding: 8px;
    background: rgba(247,250,255,.9);
}

.chat-dock .messages-conversation-item {
    grid-template-columns: 46px minmax(0, 1fr) auto;
    padding: 10px;
}

.chat-dock .message-avatar {
    width: 46px;
    height: 46px;
}

.chat-dock .messages-thread {
    min-height: 430px;
    height: 430px;
}

.chat-dock .messages-thread-head {
    min-height: 58px;
    padding: 8px;
}

.chat-dock .messages-list {
    padding: 12px;
}

.chat-dock .message-bubble {
    max-width: 82%;
}

.chat-dock .message-compose {
    padding: 10px;
}

.message-header-button {
    position: relative;
}

.message-header-badge {
    position: absolute;
    right: -4px;
    top: -5px;
}

@media (max-width: 980px) {
    .messages-page-shell {
        grid-template-columns: 1fr;
    }

    .messages-thread,
    .messages-thread-empty {
        min-height: 560px;
    }
}

@media (max-width: 640px) {
    .chat-dock {
        right: 10px;
        left: 10px;
        width: auto;
    }

    .message-bubble {
        max-width: 88%;
    }
}

/* dropdown placement for messages */
.dropdown-message-badge {
    margin-left: auto;
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    padding: 0 7px;
    font-size: .76rem;
    font-weight: 800;
    color: #fff;
    background: var(--brand, #5a67d8);
}
.dropdown-message-badge.hidden {
    display: none;
}

/* media / block / report extensions */
.messages-thread-head {
    justify-content: space-between;
}

.messages-thread-user {
    flex: 1;
}

.messages-thread-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.messages-thread-actions .danger {
    color: var(--danger);
}

.message-compose {
    grid-template-columns: 42px 42px minmax(0, 1fr) 46px;
}

.message-attach-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    background: #f8fbff;
    color: var(--brand-dark);
}

.message-compose.is-disabled {
    opacity: .6;
}

.message-compose.sending {
    pointer-events: none;
    opacity: .75;
}

.message-media-preview {
    grid-column: 1 / -1;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #f8fbff;
    padding: 10px;
}

.message-media-preview.hidden {
    display: none;
}

.message-media-preview-inner {
    display: grid;
    grid-template-columns: 62px minmax(0, 1fr) 34px;
    gap: 10px;
    align-items: center;
}

.message-media-preview-inner img,
.message-media-preview-inner video {
    width: 62px;
    height: 62px;
    border-radius: 14px;
    object-fit: cover;
    background: #e9eef8;
}

.message-media-preview-inner strong,
.message-media-preview-inner small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-media-preview-inner small {
    color: var(--muted);
}

.message-media-preview-inner button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--danger);
}

.message-bubble.has-media {
    padding: 8px;
}

.message-media {
    display: block;
    overflow: hidden;
    border-radius: 18px;
    margin-bottom: 8px;
    background: rgba(0,0,0,.08);
}

.message-media img,
.message-media video {
    display: block;
    width: min(320px, 100%);
    max-height: 360px;
    object-fit: cover;
}

.message-video video {
    object-fit: contain;
    background: #000;
}

.message-bubble-footer {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

.message-report-mini {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 0;
    background: rgba(214,73,73,.08);
    color: var(--danger);
    opacity: .65;
}

.message-report-mini:hover {
    opacity: 1;
}

.message-bubble-row.mine .message-report-mini {
    display: none;
}

.message-block-notice {
    margin: 10px 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff8e8;
    color: #8a5f00;
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

.message-block-notice.danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.message-block-notice button {
    padding: 8px 12px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--brand-dark);
    font-weight: 800;
}

.chat-dock .message-compose {
    grid-template-columns: 36px 36px minmax(0, 1fr) 40px;
    gap: 7px;
}

.chat-dock .message-emoji-button,
.chat-dock .message-attach-button {
    width: 36px;
    height: 36px;
}

.chat-dock .message-send-button {
    width: 40px;
    height: 40px;
}

.chat-dock .message-media img,
.chat-dock .message-media video {
    width: min(220px, 100%);
    max-height: 260px;
}

@media (max-width: 640px) {
    .message-compose {
        grid-template-columns: 38px 38px minmax(0, 1fr) 42px;
        padding: 10px;
    }
    .messages-thread-actions {
        gap: 4px;
    }
}

/* message image lightbox */
.message-photo {
    border: 0;
    padding: 0;
    cursor: zoom-in;
    text-align: left;
}

.message-media-lightbox {
    position: fixed;
    inset: 0;
    z-index: 18000;
    background: rgba(9, 13, 24, .88);
    backdrop-filter: blur(10px);
    display: grid;
    place-items: center;
    padding: 34px;
}

.message-media-lightbox.hidden {
    display: none;
}

.message-media-lightbox img {
    max-width: min(94vw, 1180px);
    max-height: 88vh;
    object-fit: contain;
    border-radius: 22px;
    box-shadow: 0 30px 80px rgba(0,0,0,.38);
    background: #111827;
}

.message-media-lightbox-close {
    position: absolute;
    top: 22px;
    right: 22px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.12);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.message-media-lightbox-close:hover {
    background: rgba(255,255,255,.2);
}
