:root {
    --wm-primary: #3390ec;
    --wm-bg: #ffffff;
    --wm-sidebar: #f0f2f5;
    --wm-border: #e0e0e0;
    --wm-bubble-sent: #dcf8c6;
    --wm-bubble-received: #ffffff;
    --wm-text: #212121;
    --wm-text-muted: #707579;
}

[data-theme="dark"] {
    --wm-bg: #17212b;
    --wm-sidebar: #0e1621;
    --wm-border: #242f3d;
    --wm-bubble-sent: #2b5278;
    --wm-bubble-received: #182533;
    --wm-text: #ffffff;
    --wm-text-muted: #8b9bab;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--wm-bg);
    color: var(--wm-text);
    margin: 0;
}

html[dir="rtl"] body {
    font-family: 'IRANSans', Tahoma, Arial, sans-serif !important;
}

/* v2: group/channel badges */
.chat-type-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
    background: var(--wm-sidebar);
    color: var(--wm-text-muted);
    vertical-align: middle;
}

.message-sender-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--wm-primary);
    margin: 0 0.25rem 0.15rem;
    padding-inline-start: 0.35rem;
}

.message-sender-tag {
    display: block;
    max-width: 100%;
    margin: 0 0 4px;
    padding: 0;
    border-radius: 0;
    overflow: hidden;
    color: var(--wm-primary);
    background: transparent;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.35;
    text-align: left;
    float: none;
    clear: both;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-bubble.group-sender-bubble > .message-text,
.message-bubble.group-sender-bubble > .message-attachment,
.message-bubble.group-sender-bubble > .message-reply-preview,
.message-bubble.group-sender-bubble > .message-location,
.message-bubble.group-sender-bubble > .message-call-block {
    clear: both;
}

.message-sender-avatar {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    overflow: hidden;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, var(--wm-primary), #7c3aed);
    font-size: 0.78rem;
    font-weight: 700;
    box-shadow: 0 2px 7px rgba(15, 23, 42, 0.14);
}

.message-sender-avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.message-sender-avatar.is-placeholder {
    visibility: hidden;
}

.message-row.received.group-message-row,
[dir="rtl"] .message-row.received.group-message-row {
    /* Physical order: avatar left, bubble, menu right */
    flex-direction: row;
    direction: ltr;
    align-items: flex-start;
}

/* Bubble/menu text direction follows app language (not the row's forced LTR layout) */
[dir="rtl"] .message-row.received.group-message-row > .message-bubble-stack > .message-bubble,
[dir="rtl"] .message-row.received.group-message-row > .message-bubble,
[dir="rtl"] .message-row.received.group-message-row > .msg-menu-wrap {
    direction: rtl;
}

[dir="ltr"] .message-row.received.group-message-row > .message-bubble-stack > .message-bubble,
[dir="ltr"] .message-row.received.group-message-row > .message-bubble,
[dir="ltr"] .message-row.received.group-message-row > .msg-menu-wrap {
    direction: ltr;
}

.message-row.received.group-message-row > .message-sender-avatar {
    margin-top: 2px;
}

.message-row.received.group-message-row > .msg-menu-wrap {
    align-self: center;
    margin-top: 0;
}

.group-sender-bubble .attachment-top {
    display: none;
}


/* Login */
.login-page { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-card { border-radius: 16px; }
.btn-primary { background: var(--wm-primary); border-color: var(--wm-primary); }
.btn-primary:hover { filter: brightness(1.1); }

/* Messenger Layout */
.messenger-app {
    position: relative;
    height: var(--wm-app-height, 100vh);
    max-height: var(--wm-app-height, 100vh);
    overflow: hidden;
    /* Clears Android system nav / iOS home indicator in installed PWA */
    padding-bottom: var(--wm-safe-bottom, env(safe-area-inset-bottom, 0px));
}

.chat-sidebar {
    width: 340px;
    min-width: 280px;
    background: var(--wm-sidebar);
    border-left: 1px solid var(--wm-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.25s ease, min-width 0.25s ease, opacity 0.2s ease;
}

.sidebar-expand-fab {
    position: fixed;
    top: max(14px, env(safe-area-inset-top, 0px));
    z-index: 120;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 0;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

[dir="rtl"] .sidebar-expand-fab {
    right: 14px;
    left: auto;
}

[dir="ltr"] .sidebar-expand-fab {
    left: 14px;
    right: auto;
}

@media (min-width: 769px) {
    .chat-sidebar.collapsed {
        width: 0;
        min-width: 0;
        overflow: hidden;
        border: none;
        opacity: 0;
        pointer-events: none;
    }

    .messenger-app.sidebar-collapsed #btnExpandSidebar {
        display: inline-flex !important;
    }

    .messenger-app.sidebar-collapsed .sidebar-expand-fab {
        display: inline-flex !important;
    }
}

[dir="ltr"] .messenger-app.sidebar-collapsed #btnExpandSidebar i {
    transform: rotate(180deg);
}

[dir="rtl"] #btnCollapseSidebar i {
    transform: rotate(180deg);
}

[dir="ltr"] .chat-sidebar {
    border-left: none;
    border-right: 1px solid var(--wm-border);
}

.chat-main {
    background: var(--wm-bg);
    min-width: 0;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.chat-list .chat-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--wm-border);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.chat-list .chat-item:hover,
.chat-list .chat-item.active {
    background: rgba(51, 144, 236, 0.08);
}
.chat-list-context-menu {
    position: fixed;
    z-index: 1080;
    min-width: 200px;
    padding: 8px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--wm-border-soft, var(--wm-border));
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
}
.chat-list-context-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    background: transparent;
    padding: 9px 10px;
    border-radius: 9px;
    text-align: start;
    font-size: 0.78rem;
    line-height: 1.35;
    color: inherit;
    font-family: inherit;
}
.chat-list-context-item .bi {
    width: 18px;
    font-size: 0.95em;
    color: var(--wm-text-muted);
    text-align: center;
    flex-shrink: 0;
}
.chat-list-context-item.text-danger .bi {
    color: inherit;
}
.chat-list-context-item:hover {
    background: rgba(51, 144, 236, 0.08);
}
.chat-list-context-item.text-danger:hover {
    background: rgba(220, 53, 69, 0.08);
}

.avatar-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--wm-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
    overflow: hidden;
}
.avatar-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.avatar-circle.sm { width: 36px; height: 36px; font-size: 14px; }

.chat-item-info { flex: 1; min-width: 0; margin: 0 12px; }
.chat-item-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-preview { font-size: 13px; color: var(--wm-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview-forwarded {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    min-width: 0;
    color: #8e8e8e;
}
.chat-preview-forwarded span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-preview-forward-icon {
    flex-shrink: 0;
    color: #8e8e8e;
}
.chat-item-meta { text-align: end; flex-shrink: 0; }
.chat-item-time { font-size: 12px; color: var(--wm-text-muted); }
.unread-badge {
    background: var(--wm-primary);
    color: #fff;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
}

/* Messages */
.messages-area { padding: 16px 16px 28px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; overflow-x: hidden; }
.messages-wrap {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    position: relative;
}
.messages-jump-latest {
    position: absolute;
    bottom: 1rem;
    inset-inline-end: 1rem;
    z-index: 7;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--wm-primary, #3390ec);
    color: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}
.messages-jump-latest:hover { transform: scale(1.05); }
.messages-jump-latest.d-none { display: none !important; }
.messages-jump-latest .bi { font-size: 1.25rem; line-height: 1; }
.messages-jump-badge {
    position: absolute;
    top: -4px;
    inset-inline-end: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #e53935;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}
.messages-jump-badge.d-none { display: none !important; }
.observer-messages-wrap {
    position: relative;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.messages-date-sticky {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 12px;
    padding: 4px 14px;
    border-radius: 14px;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.message-date-divider {
    text-align: center;
    margin: 14px 0 10px;
    flex-shrink: 0;
}
.message-date-divider span {
    display: inline-block;
    background: rgba(0, 0, 0, 0.07);
    color: var(--wm-text-muted);
    font-size: 12px;
    padding: 4px 14px;
    border-radius: 14px;
}
.chat-search-bar { flex-shrink: 0; position: relative; background: var(--wm-bg); }
.chat-actions .btn.active {
    background: var(--wm-primary);
    color: #fff;
}
.chat-search-results {
    position: relative;
    left: auto;
    right: auto;
    top: auto;
    z-index: 20;
    max-height: 240px;
    overflow-y: auto;
    margin-top: 8px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--wm-border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}
.chat-search-result {
    display: block;
    width: 100%;
    text-align: start;
    border: none;
    background: none;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--wm-border);
}
.chat-search-result:last-child { border-bottom: none; }
.chat-search-result:hover { background: #f5f6fa; }
.search-section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--wm-text-muted);
    padding: 10px 16px 4px;
    text-transform: uppercase;
}
.message-highlight {
    animation: msgHighlight 2s ease;
    border-radius: 12px;
}
@keyframes msgHighlight {
    0%, 100% { background: transparent; }
    35% { background: rgba(51, 144, 236, 0.12); }
}

.message-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 72%;
    min-width: 0;
    position: relative;
}

.group-message-info-btn {
    position: absolute;
    top: 5px;
    left: 5px;
    z-index: 4;
    width: 23px;
    height: 23px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    color: var(--wm-text-muted);
    background: rgba(255, 255, 255, 0.72);
    opacity: 0.78;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.group-message-info-btn:hover,
.group-message-info-btn:focus-visible {
    opacity: 1;
    color: var(--wm-primary);
    transform: scale(1.06);
}

.group-message-info-btn .bi {
    font-size: 0.85rem;
    line-height: 1;
}

.message-bubble:has(> .group-message-info-btn) {
    padding-left: 34px;
}

.receipt-section-title {
    display: flex;
    align-items: center;
    gap: 7px;
}

.receipt-member-list {
    max-height: 230px;
    overflow-y: auto;
}

.receipt-member-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* LTR: DOM order is menu+bubble (sent) / bubble+menu (received) — keep as row so
   options sit left of sent bubbles and right of received bubbles (same as Persian). */
.message-row.sent {
    align-self: flex-end;
    flex-direction: row;
}

.message-row.received {
    align-self: flex-start;
    flex-direction: row;
}

[dir="rtl"] .message-row.sent {
    align-self: flex-start;
    flex-direction: row-reverse;
}

[dir="rtl"] .message-row.received {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-bubble {
    position: relative;
    max-width: 100%;
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow: hidden;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.message-text,
.message-caption,
.message-text *,
.message-caption * {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}
.message-link {
    color: #0b6bcb;
    text-decoration: underline;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.message-bubble.sent .message-link {
    color: #0563a6;
}
.message-link:hover {
    text-decoration-thickness: 2px;
}

@media (min-width: 769px) {
    /* Full-width hover strip: menu appears when pointer is anywhere on this message line */
    .message-row {
        width: 100%;
        max-width: 100%;
        align-self: stretch;
    }

    .message-row > .message-bubble-stack {
        flex: 0 1 auto;
        max-width: min(72%, 560px);
    }

    .message-row > .message-bubble {
        flex: 0 1 auto;
        max-width: min(72%, 560px);
    }

    .message-row.sent {
        justify-content: flex-end;
    }

    .message-row.received {
        justify-content: flex-start;
    }

    /* RTL: sent stays on the right, received on the left (same as previous align-self) */
    [dir="rtl"] .message-row.sent {
        justify-content: flex-end;
    }

    [dir="rtl"] .message-row.received {
        justify-content: flex-start;
    }

    [dir="rtl"] .message-row.received.group-message-row {
        justify-content: flex-start;
    }
}

.message-bubble.sent {
    align-self: flex-end;
    background: var(--wm-bubble-sent);
}

.message-row.sent > .message-bubble-stack > .message-bubble,
.message-row.sent > .message-bubble {
    background: var(--wm-bubble-sent);
}

.message-row.received > .message-bubble-stack > .message-bubble,
.message-row.received > .message-bubble {
    background: var(--wm-bubble-received);
    border: 1px solid var(--wm-border);
}

.message-bubble.received {
    align-self: flex-start;
    background: var(--wm-bubble-received);
    border: 1px solid var(--wm-border);
}

/* Cluster tail only on first bubble in a consecutive series (WhatsApp-like) */
.message-bubble.sent.bubble-cluster-start {
    border-top-right-radius: 4px;
}
.message-bubble.received.bubble-cluster-start {
    border-top-left-radius: 4px;
}

/* LTR/RTL: keep physical corners — sent on right, received on left */
[dir="ltr"] .message-bubble.sent.bubble-cluster-start,
[dir="rtl"] .message-bubble.sent.bubble-cluster-start {
    border-top-right-radius: 4px;
}
[dir="ltr"] .message-bubble.received.bubble-cluster-start,
[dir="rtl"] .message-bubble.received.bubble-cluster-start {
    border-top-left-radius: 4px;
}

[dir="rtl"] .message-bubble.sent {
    align-self: flex-start;
}
[dir="rtl"] .message-bubble.received {
    align-self: flex-end;
}

.message-meta {
    font-size: 11px;
    color: var(--wm-text-muted);
    margin-top: 5px;
    margin-inline-start: 10px;
    text-align: end;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
    justify-content: flex-end;
    float: right;
    clear: right;
    line-height: 1.2;
    direction: ltr;
}

.message-bubble::after {
    content: "";
    display: table;
    clear: both;
}

.message-edited { font-style: italic; font-size: 11px; }

/* Connection status */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-inline-end: 4px;
}
.status-dot.online { background: #4caf50; }
.status-dot.offline { background: #9e9e9e; }
.status-dot.connecting { background: #ff9800; animation: pulse 1s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Typing indicator */
.typing-indicator { font-size: 13px; color: var(--wm-text-muted); padding: 4px 16px; font-style: italic; }

/* Chat input */
.chat-input textarea { resize: none; max-height: 120px; border-radius: 20px; }
.chat-input textarea:focus { box-shadow: none; border-color: var(--wm-primary); }

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
    height: 60px;
    margin: 8px 16px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Admin */
.admin-sidebar {
    width: 260px;
    background: #1e2a3a;
    color: #fff;
    min-height: 100vh;
}
.admin-sidebar a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    display: block;
    padding: 10px 20px;
}
.admin-sidebar a:hover, .admin-sidebar a.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
}
.admin-content { flex: 1; padding: 24px; background: #f5f6fa; min-height: 100vh; }
.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--wm-primary); }

/* Mobile */
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        inset: 0;
        z-index: 100;
        transform: translateX(0);
        transition: transform 0.3s;
    }
    [dir="ltr"] .chat-sidebar { transform: translateX(0); }
    .chat-sidebar.hidden {
        transform: translateX(100%);
        pointer-events: none;
        visibility: hidden;
    }
    [dir="ltr"] .chat-sidebar.hidden { transform: translateX(-100%); }
    .chat-main.full { width: 100%; }

    /* Reopen chats list when sidebar was closed without an open conversation header */
    .messenger-app.sidebar-mobile-hidden .sidebar-expand-fab {
        display: inline-flex !important;
    }

    .message-row { max-width: 85%; }
    :root {
        --wm-media-max-w: min(240px, 85vw);
        --wm-media-max-h: min(280px, 45vh);
    }
    .msg-image { max-height: none; }
    .msg-video { max-height: none; }
}

/* Message attachments */
.message-attachment { margin-top: 6px; max-width: 100%; }
.message-attachment-media {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    max-width: 100%;
    width: 100%;
}
.message-attachment-media:has(.msg-image-wrap),
.message-attachment-media:has(.msg-video-wrap),
.message-attachment-media:has(.media-load-placeholder) {
    margin-top: 0;
    gap: 0;
    width: auto;
    max-width: 100%;
    align-items: flex-start;
}
.message-attachment-media:has(.msg-image-wrap) .attachment-top,
.message-attachment-media:has(.msg-video-wrap) .attachment-top,
.message-attachment-media:has(.media-load-placeholder) .attachment-top {
    display: none;
}
.message-attachment-media:has(.msg-image-wrap) .attachment-media,
.message-attachment-media:has(.msg-video-wrap) .attachment-media {
    width: auto;
    max-width: 100%;
}

/* Photo/video bubbles — thin L/R/bottom inset + border like text bubbles */
.message-bubble.is-media-bubble,
.message-bubble:has(.msg-image-wrap),
.message-bubble:has(.msg-video-wrap),
.message-bubble:has(.media-load-placeholder) {
    padding: 1px 1px 1px !important;
    overflow: hidden;
    width: fit-content;
    max-width: min(100%, var(--wm-media-max-w, 560px));
    flex: 0 1 auto !important;
    box-sizing: border-box;
    border: 1px solid var(--wm-border);
}
.message-bubble.is-media-bubble:has(.message-caption),
.message-bubble:has(.msg-image-wrap):has(.message-caption),
.message-bubble:has(.msg-video-wrap):has(.message-caption),
.message-bubble:has(.media-load-placeholder):has(.message-caption) {
    padding: 1px 1px 8px !important;
}
.message-row.is-media-row {
    max-width: 85%;
}

@media (min-width: 769px) {
    /* Keep full-width row so hover still reveals the options button */
    .message-row.is-media-row {
        width: 100%;
        max-width: 100%;
    }

    .message-row.is-media-row > .message-bubble-stack,
    .message-row.is-media-row > .message-bubble {
        max-width: min(72%, var(--wm-media-max-w, 280px));
    }
}
.message-bubble.is-media-bubble .message-attachment,
.message-bubble.is-media-bubble .message-attachment-media,
.message-bubble.is-media-bubble .attachment-media,
.message-bubble:has(.msg-image-wrap) .message-attachment-media,
.message-bubble:has(.msg-video-wrap) .message-attachment-media,
.message-bubble:has(.media-load-placeholder) .message-attachment-media,
.message-bubble:has(.msg-image-wrap) .attachment-media,
.message-bubble:has(.msg-video-wrap) .attachment-media {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
}
/* Fill bubble width; soft inner radius so media sits inside the 1px frame */
.message-bubble.is-media-bubble .msg-image-wrap,
.message-bubble.is-media-bubble .msg-video-wrap,
.message-bubble.is-media-bubble .media-load-placeholder,
.message-bubble:has(.msg-image-wrap) .msg-image-wrap,
.message-bubble:has(.msg-video-wrap) .msg-video-wrap,
.message-bubble:has(.media-load-placeholder) .media-load-placeholder {
    width: var(--wm-media-w, 100%) !important;
    max-width: 100% !important;
    border-radius: 10px !important;
    overflow: hidden;
}
.message-bubble.is-media-bubble:has(.message-reply-preview) .msg-image-wrap,
.message-bubble.is-media-bubble:has(.message-reply-preview) .msg-video-wrap,
.message-bubble.is-media-bubble:has(.message-reply-preview) .media-load-placeholder,
.message-bubble.is-media-bubble:has(.message-caption) .msg-image-wrap,
.message-bubble.is-media-bubble:has(.message-caption) .msg-video-wrap,
.message-bubble.is-media-bubble:has(.message-caption) .media-load-placeholder {
    width: 100% !important;
    border-radius: 10px 10px 4px 4px !important;
}
.message-bubble.group-sender-bubble.is-media-bubble,
.message-bubble.group-sender-bubble:has(.msg-image-wrap),
.message-bubble.group-sender-bubble:has(.msg-video-wrap),
.message-bubble.group-sender-bubble:has(.media-load-placeholder) {
    padding: 6px 1px 1px !important;
}
.message-bubble.group-sender-bubble:has(.msg-image-wrap) .message-sender-tag,
.message-bubble.group-sender-bubble:has(.msg-video-wrap) .message-sender-tag,
.message-bubble.group-sender-bubble:has(.media-load-placeholder) .message-sender-tag {
    padding-inline: 8px;
    margin-bottom: 4px;
}
.message-bubble:has(.msg-image-wrap) .message-caption,
.message-bubble:has(.msg-video-wrap) .message-caption {
    padding: 4px 8px 0;
}

/* Message clock overlaid on media (bottom-right) */
.message-bubble:has(.msg-image-wrap):not(:has(.message-caption)) .message-meta,
.message-bubble:has(.msg-video-wrap):not(:has(.message-caption)) .message-meta,
.message-bubble:has(.media-load-placeholder):not(:has(.message-caption)) .message-meta {
    position: absolute;
    right: 8px;
    bottom: 8px;
    left: auto;
    float: none;
    clear: none;
    margin: 0;
    z-index: 5;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
    font-size: 11px;
    line-height: 1.2;
}
.message-bubble:has(.msg-image-wrap):not(:has(.message-caption)) .message-meta .message-edited,
.message-bubble:has(.msg-video-wrap):not(:has(.message-caption)) .message-meta .message-edited,
.message-bubble:has(.media-load-placeholder):not(:has(.message-caption)) .message-meta .message-edited {
    color: rgba(255, 255, 255, 0.9);
}
.message-bubble:has(.msg-image-wrap):not(:has(.message-caption)) .msg-receipt-sent,
.message-bubble:has(.msg-image-wrap):not(:has(.message-caption)) .msg-receipt-delivered,
.message-bubble:has(.msg-video-wrap):not(:has(.message-caption)) .msg-receipt-sent,
.message-bubble:has(.msg-video-wrap):not(:has(.message-caption)) .msg-receipt-delivered,
.message-bubble:has(.media-load-placeholder):not(:has(.message-caption)) .msg-receipt-sent,
.message-bubble:has(.media-load-placeholder):not(:has(.message-caption)) .msg-receipt-delivered {
    color: rgba(255, 255, 255, 0.9);
}
.message-bubble:has(.msg-image-wrap):not(:has(.message-caption)) .msg-receipt-read,
.message-bubble:has(.msg-video-wrap):not(:has(.message-caption)) .msg-receipt-read,
.message-bubble:has(.media-load-placeholder):not(:has(.message-caption)) .msg-receipt-read {
    color: #7dd3fc;
}

.message-attachment-media .attachment-top { width: 100%; }
.message-attachment-media .attachment-top .file-type-badge { margin-bottom: 0; }
.message-attachment-media .attachment-media { width: 100%; max-width: 100%; }
.message-attachment-media .attachment-footer { width: 100%; max-width: 100%; }

:root {
    --wm-media-max-w: 280px;
    --wm-media-max-h: 360px;
}

.msg-image-wrap,
.msg-video-wrap {
    position: relative;
    display: block;
    width: var(--wm-media-w, auto);
    max-width: min(100%, var(--wm-media-max-w));
    max-height: var(--wm-media-max-h);
    aspect-ratio: var(--wm-media-ar, auto);
    overflow: hidden;
    border-radius: 10px;
}

.msg-image-wrap {
    background: transparent;
}

.msg-video-wrap {
    background: #000;
    cursor: pointer;
    isolation: isolate;
}

.msg-image,
.msg-video {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    object-fit: cover;
    border-radius: inherit;
}

.msg-image {
    cursor: pointer;
}

.media-load-placeholder.is-media-sized,
.media-load-placeholder[style*="--wm-media-w"] {
    width: var(--wm-media-w, 100%);
    max-width: min(100%, var(--wm-media-max-w));
    max-height: var(--wm-media-max-h);
    aspect-ratio: var(--wm-media-ar, auto);
    min-height: 0;
}
.file-attachment {
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    padding: 8px 12px;
}
.file-download-link {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
.file-download-link:hover,
.file-download-link:focus {
    text-decoration: none;
}
.chat-actions .btn { border-radius: 50%; width: 36px; height: 36px; padding: 0; }

/* File type badges */
.file-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(51, 144, 236, 0.15);
    color: var(--wm-primary);
    margin-bottom: 6px;
}
.message-bubble.sent .file-type-badge {
    background: rgba(21, 128, 61, 0.13);
    color: #166534;
}

[data-theme="dark"] .message-bubble.sent .file-type-badge {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}
.file-meta { font-size: 12px; opacity: 0.8; margin-top: 4px; }

/* Video in chat — poster-style preview, native controls only in fullscreen */
.msg-video {
    background: #000;
    pointer-events: none;
}

.msg-video-wrap.is-fs-playing {
    position: fixed;
    inset: 0;
    z-index: 2200;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    aspect-ratio: auto !important;
    border-radius: 0;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.msg-video-wrap.is-fs-playing .msg-video {
    pointer-events: auto;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 0;
    z-index: 1;
    position: relative;
}

/* Keep chat meta/time from covering the native seek bar while video is open */
.message-bubble:has(.msg-video-wrap.is-fs-playing) .message-meta {
    display: none !important;
}

.msg-video-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: rgba(15, 23, 42, 0.55);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
    pointer-events: auto;
}

.msg-video-play i {
    font-size: 1.75rem;
    margin-inline-start: 2px;
    line-height: 1;
}

.msg-video-close {
    display: none;
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 0px));
    inset-inline-end: max(12px, env(safe-area-inset-right, 0px));
    z-index: 12;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: rgba(15, 23, 42, 0.62);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
    cursor: pointer;
}

.msg-video-close i {
    font-size: 1.15rem;
    line-height: 1;
}

.msg-video-wrap.is-fs-playing .msg-video-close {
    display: inline-flex;
    z-index: 5;
    pointer-events: auto;
}

.msg-video-wrap.is-fs-playing .msg-video-play,
.msg-video-wrap.is-fs-playing .msg-video-badge {
    display: none;
}

.msg-video-wrap:not(.is-fs-playing) .msg-video::-webkit-media-controls {
    display: none !important;
}

.msg-video-wrap:hover .msg-video-play {
    background: rgba(15, 23, 42, 0.72);
}

.msg-video-badge {
    position: absolute;
    bottom: 6px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 6px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.95);
    background: rgba(15, 23, 42, 0.45);
    font-size: 11px;
    line-height: 1.2;
    pointer-events: none;
    direction: ltr;
    unicode-bidi: isolate;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.msg-video-badge i {
    font-size: 0.85rem;
    line-height: 1;
}

.msg-video-badge-left {
    left: 6px;
    padding: 2px 6px;
}

.msg-video-duration {
    font-weight: 600;
    direction: ltr;
    unicode-bidi: isolate;
    min-width: 2.4em;
}

.msg-audio {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-top: 2px;
}

.message-caption {
    margin-top: 6px;
    font-size: 14px;
}

.media-load-placeholder {
    position: relative;
    width: 100%;
    min-height: 160px;
    max-height: 280px;
    border: 0;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.08);
    color: #fff;
    display: block;
    overflow: hidden;
    cursor: pointer;
    padding: 0;
    isolation: isolate;
}
.media-load-placeholder.has-preview {
    min-height: 160px;
}
.media-load-placeholder .media-load-preview {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(14px);
    transform: scale(1.12);
    opacity: 0.92;
}
.media-load-placeholder .media-load-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4rem;
    opacity: 0.45;
    color: inherit;
}
.media-load-placeholder .media-load-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 12px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.18), rgba(15, 23, 42, 0.42));
    z-index: 1;
}
.media-load-placeholder:hover .media-load-overlay {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.28), rgba(15, 23, 42, 0.52));
}
.media-load-placeholder .media-load-chip {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 10px 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #0f172a;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.18);
}
.media-load-placeholder .media-load-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    height: auto;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    box-shadow: none;
    flex-shrink: 0;
}
.media-load-placeholder .media-load-action .bi { font-size: 1.1rem; }
.media-load-placeholder .media-load-size {
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    text-shadow: none;
    direction: ltr;
    unicode-bidi: isolate;
}
.message-bubble.sent .media-load-placeholder .media-load-chip {
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
}
.message-bubble.sent .media-load-placeholder .media-load-action {
    background: transparent;
    color: inherit;
}
.message-attachment-media:has(.media-load-placeholder) .attachment-footer,
.message-attachment-media .attachment-footer:empty {
    display: none;
}

/* Upload progress */
.upload-progress-wrap, .download-progress {
    height: 6px;
    background: rgba(0,0,0,0.1);
    border-radius: 3px;
    overflow: hidden;
    margin: 8px 0 4px;
}
.upload-progress-bar, .download-progress-bar {
    height: 100%;
    background: var(--wm-primary);
    border-radius: 3px;
    transition: width 0.2s;
    width: 0;
}
.message-bubble.sent .upload-progress-bar { background: #fff; }
.upload-progress-text { font-size: 11px; opacity: 0.85; }
.upload-file-name { font-size: 13px; margin-bottom: 4px; word-break: break-all; }
.uploading-bubble { opacity: 0.9; }

.message-call-block {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
    width: 100%;
    margin-bottom: 0.15rem;
}

.message-call-log {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.92rem;
    line-height: 1.35;
    width: 100%;
}

.message-call-log .bi {
    font-size: 1.05rem;
    flex-shrink: 0;
}

.call-log-text {
    min-width: 0;
}

.message-bubble:has(.message-call-block) .message-meta,
.message-bubble.call-log-bubble .message-meta {
    display: flex;
    width: 100%;
    margin-top: 0.85rem;
    padding-top: 0.4rem;
    border-top: 1px solid rgba(127, 127, 127, 0.22);
    justify-content: flex-end;
    clear: both;
    float: none;
    margin-inline-start: 0;
}

.call-tone-answered .bi { color: #16a34a; }
.call-tone-missed .bi { color: #dc2626; }
.call-tone-incoming .bi { color: #2563eb; }

.call-recording-player {
    display: block;
    width: min(100%, 320px);
    max-height: 240px;
    margin-top: 0.15rem;
}


/* v3 voice/video calls */
.call-stage {
    min-height: min(70vh, 620px);
    background: radial-gradient(circle at center, #334155 0, #111827 65%);
}

.call-peer-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 3;
}

.call-stage.video-active .call-peer-placeholder {
    justify-content: flex-end;
    padding-bottom: 1rem;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}

.call-stage.video-active .call-peer-avatar,
.call-stage.video-active #callPeerName {
    display: none;
}

.call-peer-avatar {
    width: 96px;
    height: 96px;
    font-size: 2rem;
}

.call-remote-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

.call-local-video {
    position: absolute;
    width: min(28vw, 210px);
    aspect-ratio: 3 / 4;
    object-fit: cover;
    inset-inline-end: 18px;
    bottom: 18px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    z-index: 2;
    background: #111;
}

.call-local-video.mirrored {
    transform: scaleX(-1);
}

.call-action-btn {
    width: 54px;
    height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.call-action-btn.active,
.call-action-btn.call-control-off {
    background: #dc2626 !important;
    border-color: #dc2626 !important;
    color: #fff !important;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.35);
}

.call-action-btn.call-control-on {
    background: #2563eb !important;
    border-color: #2563eb !important;
    color: #fff !important;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
}

@media (max-width: 576px) {
    .call-modal .modal-dialog {
        margin: 0;
        min-height: 100%;
    }

    .call-modal .modal-content {
        min-height: 100vh;
        border-radius: 0;
    }

    .call-stage {
        min-height: calc(100vh - 90px);
    }
}
.attach-preview {
    text-align: center;
    background: #f5f6fa;
    border-radius: 12px;
    padding: 12px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.attach-preview-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
}
.attach-preview-edit-btn {
    position: absolute;
    top: 8px;
    inset-inline-end: 8px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.attach-preview-edit-btn:hover {
    background: rgba(0, 0, 0, 0.72);
    color: #fff;
}
.attach-preview-img { max-width: 100%; max-height: 200px; border-radius: 8px; display: block; }
.attach-preview-video { max-width: 100%; max-height: 200px; border-radius: 8px; }
.attach-preview-audio { width: 100%; max-width: 100%; }
.attach-preview-icon { color: var(--wm-primary); opacity: 0.7; }

.image-view-content { background: rgba(0, 0, 0, 0.92) !important; }
.image-view-body {
    position: relative;
    overflow: hidden;
    min-height: min(50vh, 420px);
    max-height: min(78vh, 720px);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    cursor: grab;
    user-select: none;
}
.image-view-body.grabbing { cursor: grabbing; }
.image-view-img {
    max-width: 100%;
    max-height: min(72vh, 680px);
    border-radius: 8px;
    object-fit: contain;
    transform-origin: center center;
    will-change: transform;
}
.image-view-toolbar {
    position: absolute;
    bottom: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.35rem;
    z-index: 5;
    opacity: 0.9;
}
.image-view-zoom-btn {
    min-width: 2.25rem;
    font-weight: 600;
    line-height: 1;
}
.media-view-header {
    justify-content: flex-end;
}
.media-view-header .btn-close {
    margin: 0;
    opacity: 0.85;
}
.media-view-download {
    width: 1em;
    height: 1em;
    padding: 0.25em;
    box-sizing: content-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 0.25rem;
    background: transparent !important;
    color: #fff;
    opacity: 0.85;
    text-decoration: none;
    box-shadow: none !important;
    line-height: 1;
    font-size: 1.25rem;
}
.media-view-download i {
    font-size: 1em;
    line-height: 1;
}
.media-view-download:hover,
.media-view-download:focus {
    background: transparent !important;
    color: #fff;
    opacity: 1;
}
.media-view-download.disabled {
    opacity: 0.45;
    pointer-events: none;
}
.video-view-body {
    cursor: default;
}
.video-view-player {
    width: 100%;
    max-width: 100%;
    max-height: min(72vh, 680px);
    border-radius: 8px;
    background: #000;
    object-fit: contain;
}

/* Profile page */
.profile-page { min-height: 100vh; background: #f5f6fa; }
.profile-header { position: sticky; top: 0; z-index: 10; }
.profile-avatar-wrap { position: relative; width: 96px; height: 96px; }
.profile-avatar { width: 96px !important; height: 96px !important; font-size: 36px !important; overflow: hidden; }
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-avatar-edit {
    position: absolute;
    bottom: 0;
    inset-inline-end: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--wm-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 2px solid #fff;
    font-size: 14px;
}
.profile-avatar-edit:hover { opacity: 0.9; }

.otp-input-group {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 0 auto 4px;
    max-width: 320px;
}
.otp-digit {
    width: 44px;
    height: 52px;
    border: 1.5px solid #d0d5dd;
    border-radius: 12px;
    background: #fff;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1;
    color: #1f2937;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
    caret-color: var(--wm-primary, #3390ec);
}
.otp-digit:focus {
    border-color: var(--wm-primary, #3390ec);
    box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.22);
}
@media (max-width: 420px) {
    .otp-digit { width: 40px; height: 48px; font-size: 1.2rem; }
    .otp-input-group { gap: 6px; }
}

/* Message context menu */
.msg-menu-wrap {
    flex-shrink: 0;
    align-self: center;
    opacity: 0.55;
    transition: opacity 0.15s, visibility 0.15s;
}

.message-row:hover .msg-menu-wrap,
.msg-menu-wrap:focus-within,
.msg-menu-wrap:has(.msg-dropdown.show) {
    opacity: 1;
}

@media (min-width: 769px) {
    .msg-menu-wrap {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

    .message-row:hover .msg-menu-wrap,
    .msg-menu-wrap:focus-within,
    .msg-menu-wrap:has(.msg-dropdown.show) {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}

.msg-menu-btn {
    position: relative;
    border: none;
    background: var(--wm-sidebar);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    line-height: 1;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    color: var(--wm-text-muted);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.msg-menu-btn .bi {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1em;
    height: 1em;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transform: translate(-50%, -50%);
}

.msg-menu-btn .bi::before {
    display: block;
    margin: 0;
    line-height: 1;
}

.msg-menu-btn:hover {
    background: #e4e6eb;
    color: var(--wm-primary);
}

.msg-dropdown {
    position: fixed;
    z-index: 2000;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
    min-width: 200px;
    padding: 6px 0;
    display: none;
}

.msg-dropdown.show { display: block; }
.msg-dropdown button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: start;
    border: none;
    background: none;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
}
.msg-dropdown button .bi,
.msg-dropdown button .wm-icon-forward {
    font-size: 15px;
    opacity: 0.85;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}
.msg-dropdown button:hover { background: #f5f6fa; }

/* English / LTR: menu items left-aligned (icon then label) */
[dir="ltr"] .msg-dropdown,
[dir="ltr"] .msg-menu-wrap {
    direction: ltr;
}
[dir="ltr"] .msg-dropdown button {
    flex-direction: row;
    justify-content: flex-start;
    text-align: left;
}

[dir="rtl"] .msg-dropdown {
    direction: rtl;
}
[dir="rtl"] .msg-dropdown button {
    flex-direction: row;
    text-align: right;
}
.message-reply-preview {
    display: block;
    width: 100%;
    border: none;
    border-inline-start: 3px solid var(--wm-primary);
    padding: 4px 8px;
    margin-bottom: 6px;
    background: rgba(0,0,0,0.04);
    border-radius: 4px;
    font-size: 12px;
    text-align: inherit;
    cursor: pointer;
    transition: background 0.15s ease;
}
.message-reply-preview:hover { background: rgba(0,0,0,0.08); }
.message-reply-preview:focus-visible {
    outline: 2px solid var(--wm-primary);
    outline-offset: 1px;
}
.message-bubble.sent .message-reply-preview { background: rgba(0,0,0,0.08); }
.message-bubble.sent .message-reply-preview:hover { background: rgba(0,0,0,0.14); }
.message-reply-preview strong { display: block; color: var(--wm-primary); }
.message-reply-preview span { display: block; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.message-forwarded-label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #8e8e8e;
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 4px;
    line-height: 1.2;
}
.message-forwarded-label .wm-icon-forward,
.msg-dropdown .wm-icon-forward {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    color: inherit;
    opacity: 0.9;
}
.message-forwarded-label .wm-icon-forward {
    width: 14px;
    height: 14px;
    color: #8e8e8e;
}
[dir="rtl"] .wm-icon-forward {
    transform: scaleX(-1);
}
[data-theme="dark"] .message-forwarded-label,
[data-theme="dark"] .message-forwarded-label .wm-icon-forward {
    color: #a0a8b0;
}
.forward-chat-list {
    max-height: min(52vh, 420px);
    overflow-y: auto;
}
.forward-chat-item {
    display: flex !important;
    align-items: center;
    gap: 12px;
    padding: 10px 4px !important;
    border: 0 !important;
    background: transparent !important;
}
.forward-chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--wm-primary-soft, #e8f0fe);
    color: var(--wm-primary, #1a73e8);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    font-weight: 600;
}
.forward-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.forward-chat-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.forward-chat-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.forward-chat-preview {
    font-size: 12px;
    color: #8e8e8e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.message-bubble-stack {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
}
.message-bubble-stack.has-reactions {
    margin-bottom: 12px;
}
.message-reactions {
    position: absolute;
    left: 4px;
    bottom: -11px;
    z-index: 3;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    pointer-events: auto;
}
.reaction-chip {
    width: 26px;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    font-size: 14px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.reaction-chip:hover {
    background: #f5f5f5;
}
.reaction-picker {
    position: fixed; z-index: 2001; background: #fff;
    border-radius: 20px; box-shadow: 0 2px 12px rgba(0,0,0,0.15); padding: 4px 8px; display: flex; gap: 4px;
    align-items: center;
}
.reaction-picker button { border: none; background: none; font-size: 18px; cursor: pointer; line-height: 1; padding: 4px; border-radius: 50%; }
.reaction-picker button:hover { background: #f3f4f6; }
.reaction-picker-more {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px !important;
    font-weight: 600;
    color: #667085;
    background: #f2f4f7 !important;
    border-radius: 50% !important;
}
.reaction-picker-more:hover {
    background: #e4e7ec !important;
    color: #344054;
}

.chat-composer {
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--wm-border);
}

.chat-input.has-reply .chat-composer {
    border-color: var(--wm-primary);
}

.chat-input.has-edit .chat-composer {
    border-color: #f59e0b;
}

.reply-bar {
    display: flex;
    align-items: stretch;
    gap: 10px;
    background: rgba(51, 144, 236, 0.08);
    border-bottom: 1px solid var(--wm-border);
    padding: 8px 12px;
    border-radius: 12px 12px 0 0;
}

.reply-bar.edit-bar {
    background: rgba(245, 158, 11, 0.12);
}

.reply-bar:not(.d-none) {
    display: flex !important;
}

.reply-bar-line {
    width: 3px;
    border-radius: 2px;
    background: var(--wm-primary);
    flex-shrink: 0;
}

.reply-bar.edit-bar .reply-bar-line {
    background: #f59e0b;
}

.reply-bar-body {
    min-width: 0;
    flex: 1;
}

.reply-bar-author {
    font-size: 13px;
    font-weight: 600;
    color: var(--wm-primary);
    line-height: 1.3;
}

.reply-bar.edit-bar .reply-bar-author {
    color: #b45309;
}

.reply-bar-text {
    font-size: 13px;
    color: var(--wm-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.reply-bar-close {
    align-self: center;
    flex-shrink: 0;
}

.chat-input.has-reply #messageForm .form-control,
.chat-input.has-edit #messageForm .form-control {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border: none;
    box-shadow: none;
}

.chat-input.has-reply #messageForm,
.chat-input.has-edit #messageForm {
    padding-top: 8px;
}

.chat-input.has-reply .chat-composer,
.chat-input.has-edit .chat-composer {
    overflow: hidden;
}

.location-map-wrap { min-height: 360px; }
.location-map { height: 360px; width: 100%; z-index: 1; }
.location-gps-btn {
    position: absolute;
    top: 12px;
    inset-inline-end: 12px;
    z-index: 1000;
}

.select-toolbar { flex-shrink: 0; }
.messages-area.is-selecting {
    overflow-anchor: none;
}
/* Full chat-line hit/highlight; keep bubble side identical to desktop layout. */
.messages-area.is-selecting .message-row {
    cursor: pointer;
    position: relative;
    width: 100%;
    max-width: 100%;
    align-self: stretch;
    border-radius: 0;
    transition: background-color 0.12s ease;
}
.messages-area.is-selecting .message-row.sent {
    justify-content: flex-end;
}
.messages-area.is-selecting .message-row.received {
    justify-content: flex-start;
}
[dir="rtl"] .messages-area.is-selecting .message-row.sent {
    justify-content: flex-end;
}
[dir="rtl"] .messages-area.is-selecting .message-row.received {
    justify-content: flex-start;
}
[dir="rtl"] .messages-area.is-selecting .message-row.received.group-message-row {
    justify-content: flex-start;
}
.messages-area.is-selecting .message-row > .message-bubble-stack,
.messages-area.is-selecting .message-row > .message-bubble {
    flex: 0 1 auto;
    max-width: min(72%, 560px);
}
@media (max-width: 768px) {
    .messages-area.is-selecting .message-row > .message-bubble-stack,
    .messages-area.is-selecting .message-row > .message-bubble {
        max-width: min(88%, 560px);
    }
    .messages-area.is-selecting .message-row.is-media-row > .message-bubble-stack,
    .messages-area.is-selecting .message-row.is-media-row > .message-bubble {
        max-width: min(100%, var(--wm-media-max-w, 240px));
    }
}
.messages-area.is-selecting .message-row:active {
    background: rgba(51, 144, 236, 0.08);
}
.message-row.is-selected {
    background: rgba(51, 144, 236, 0.16) !important;
    border-radius: 0;
}
.message-row.is-selected::before {
    content: none;
}
body.msg-select-mode .msg-menu-wrap {
    opacity: 0.35;
    pointer-events: none;
}
.message-location { margin-top: 4px; }

.location-card {
    display: block;
    max-width: 100%;
    width: 100%;
    border-radius: 10px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.08);
    transition: opacity 0.15s;
    padding: 0;
    text-align: inherit;
    cursor: pointer;
    font: inherit;
}

.location-card:hover {
    opacity: 0.92;
    color: inherit;
}

.location-thumb {
    display: block;
    position: relative;
    width: 100%;
    height: 160px;
    background: #e8ecef;
    overflow: hidden;
}

.location-thumb-inner {
    position: relative;
    margin: 0 auto;
    overflow: hidden;
    background: #dfe6ec;
}

.location-tile-img {
    position: absolute;
    width: 256px;
    height: 256px;
    display: block;
    max-width: none;
}

.location-marker-pin {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    background: #e53935;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    z-index: 2;
    pointer-events: none;
}

.location-thumb-mosaic:not(.is-ready) .location-thumb-inner::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #e8ecef 25%, #f5f7f9 50%, #e8ecef 75%);
    background-size: 200% 100%;
    animation: location-shimmer 1.2s infinite;
}

@keyframes location-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.location-caption {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.3;
}

.location-caption-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.location-live-badge {
    flex-shrink: 0;
    font-size: 10px;
}

.message-bubble.sent .location-card {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
}

.message-bubble.sent .location-caption {
    color: #fff;
}
.file-meta.text-truncate { max-width: 100%; }
.file-locked { padding: 24px; background: rgba(0,0,0,0.05); border-radius: 8px; text-align: center; }

/* Toast */
.wm-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #323232;
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 9999;
    animation: fadeInUp 0.3s;
}
.toastify.wm-toastify {
    max-width: min(92vw, 420px);
    padding: 12px 16px;
    font-size: 0.95rem;
    line-height: 1.45;
    z-index: 10050 !important;
}
.toastify.wm-toastify .toast-close {
    opacity: 0.85;
    padding-inline-start: 10px;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Contact list in modal */
.list-group-item-action { cursor: pointer; }

/* Active devices / sessions */
.device-row { border-bottom: 1px solid var(--wm-border); }
.device-row.is-current { background: rgba(51, 144, 236, 0.06); }
.device-row-main {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
}
.device-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(51, 144, 236, 0.12);
    color: var(--wm-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}
.device-info { flex: 1; min-width: 0; }
.device-label { font-weight: 600; font-size: 14px; }
.device-meta { margin-top: 2px; }
.device-details-body {
    background: #f8f9fb;
    border-top: 1px solid var(--wm-border);
    padding: 10px 14px 12px 62px;
}
.session-detail-row {
    padding: 8px 0;
    border-bottom: 1px dashed rgba(0,0,0,0.08);
}
.session-detail-row:last-child { border-bottom: none; }
.session-detail-row.is-current { background: rgba(40, 167, 69, 0.06); border-radius: 6px; padding: 8px; }
.session-ua { word-break: break-word; margin-top: 4px; font-size: 11px; }
.admin-device-row .device-row-main { padding: 12px; }

/* Message receipts */
.message-time { white-space: nowrap; }
.msg-receipt {
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    line-height: 1;
    margin-inline-start: 2px;
}
.msg-receipt-sent { color: #667781; }
.message-bubble.received .msg-receipt-sent { color: var(--wm-text-muted); }
.msg-receipt-delivered { color: #667781; }
.message-bubble.received .msg-receipt-delivered { color: var(--wm-text-muted); }
.msg-receipt-read { color: #0b93f6; }
.message-bubble.received .msg-receipt-read { color: var(--wm-primary); }

/* Observer panel — reuses messenger chat chrome */
.observer-app {
    height: var(--wm-app-height, 100dvh);
    max-height: var(--wm-app-height, 100dvh);
    overflow: hidden;
    background: var(--wm-surface);
    padding-bottom: var(--wm-safe-bottom, env(safe-area-inset-bottom, 0px));
}
.observer-subjects-pane {
    width: clamp(240px, 22vw, 300px);
    min-width: 220px;
}
.observer-sidebar-search.sidebar-search::before {
    display: none;
}
.observer-search-field {
    position: relative;
}
.observer-search-field::before {
    content: "\F52A";
    position: absolute;
    inset-inline-start: 14px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    font-family: "bootstrap-icons";
    font-size: 1rem;
    line-height: 1;
    color: var(--wm-text-muted);
    pointer-events: none;
}
#observerSubjectSearch {
    height: 44px;
    padding-inline-start: 42px;
    border: 0;
    border-radius: 14px;
    background:
        linear-gradient(var(--wm-surface-soft), var(--wm-surface-soft)) padding-box,
        linear-gradient(135deg, rgba(var(--wm-primary-rgb), 0.18), transparent) border-box;
    box-shadow: inset 0 0 0 1px var(--wm-border-soft);
}
.observer-conversations-pane {
    width: clamp(280px, 26vw, 360px);
    min-width: 260px;
    border-inline-start: 1px solid var(--wm-border);
}
.observer-messages-wrap {
    position: relative;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.observer-readonly-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--wm-surface-elevated, #fff);
    color: var(--wm-text-muted);
    font-size: 13px;
}
.observer-readonly-bar .bi {
    opacity: 0.75;
}
@media (max-width: 991.98px) {
    .observer-app {
        position: relative;
    }
    .observer-subjects-pane,
    .observer-conversations-pane {
        width: 100%;
        min-width: 0;
        max-width: none;
        border-inline-start: none;
    }
    .observer-view-subjects .observer-conversations-pane,
    .observer-view-subjects #observerMain,
    .observer-view-conversations .observer-subjects-pane,
    .observer-view-conversations #observerMain,
    .observer-view-chat .observer-subjects-pane,
    .observer-view-chat .observer-conversations-pane {
        display: none !important;
    }
    .observer-view-chat #observerMain {
        display: flex !important;
        width: 100%;
    }
}
@media (min-width: 992px) {
    .observer-mobile-back {
        display: none !important;
    }
}

.wm-notify-banner {
    position: fixed;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    z-index: 1090;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--wm-bg);
    border: 1px solid var(--wm-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.wm-notify-banner-text {
    flex: 1;
    font-size: 13px;
    line-height: 1.35;
}
@media (min-width: 769px) {
    .wm-notify-banner {
        left: auto;
        right: 16px;
        max-width: 360px;
    }
}

.wm-image-editor-stage {
    overflow: hidden;
    touch-action: none;
}
.wm-image-editor-canvas {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
.wm-image-editor-canvas.wm-cursor-crosshair { cursor: crosshair; }
.wm-image-editor-canvas.wm-cursor-crop { cursor: crosshair; }
.wm-color-btn {
    width: 31px;
    min-width: 31px;
    height: 31px;
    padding: 2px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}
.wm-color-input {
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    display: block;
}
.wm-emoji-popover {
    position: absolute;
    z-index: 1080;
    width: min(320px, calc(100vw - 16px));
    background: var(--wm-bg);
    border: 1px solid var(--wm-border);
    border-radius: 12px;
    padding: 8px;
}
.wm-emoji-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    padding: 0 4px;
}
.wm-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    max-height: 220px;
    overflow-y: auto;
}
.wm-emoji-btn {
    border: none;
    background: transparent;
    font-size: 1.35rem;
    line-height: 1;
    padding: 6px 2px;
    border-radius: 8px;
    cursor: pointer;
}
.wm-emoji-btn:hover {
    background: rgba(51, 144, 236, 0.12);
}
