/* ══════════════════════════════════════════════════════════════════════
   VELVIXIE DIRECT MESSAGING — MASTER STYLESHEET (PERFECTED & BUG-FREE)
   ══════════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #F4F7FC;
    color: #1E293B;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Container Layout ── */
.dm-app-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 14px 20px 20px;
    height: calc(100vh - 78px);
    height: calc(100dvh - 78px);
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
}

.dm-card-frame {
    flex: 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    background: #FFFFFF;
    border-radius: 20px;
    border: 1.5px solid rgba(107, 159, 255, 0.16);
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.06);
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    overflow: hidden;
    height: 100%;
    box-sizing: border-box;
}

/* ── Sidebar ── */
.dm-sidebar {
    display: flex;
    flex-direction: column;
    background: #FAFBFE;
    border-right: 1px solid #E2E8F0;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    box-sizing: border-box;
}

.dm-sidebar-header {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #FFFFFF;
    border-bottom: 1px solid #F1F5F9;
}

.dm-brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dm-brand-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: #1E293B;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dm-e2e-pill {
    font-size: 0.65rem;
    font-weight: 700;
    color: #10B981;
    background: rgba(16, 185, 129, 0.1);
    padding: 2px 8px;
    border-radius: 99px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Search Wrap */
.dm-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #F1F5F9;
    border-radius: 14px;
    padding: 8px 12px;
    border: 1.5px solid transparent;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.dm-search-wrap:focus-within {
    background: #FFFFFF;
    border-color: #6B9FFF;
}

.dm-search-icon {
    color: #94A3B8;
    flex-shrink: 0;
}

.dm-search-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.84rem;
    color: #1E293B;
    outline: none;
}

.dm-search-clear {
    background: transparent;
    border: none;
    color: #94A3B8;
    cursor: pointer;
    padding: 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    transition: color 0.15s ease, background 0.15s ease;
}

.dm-search-clear:hover {
    color: #475569;
    background: rgba(100, 116, 139, 0.12);
}

/* Side Tabs (Obrolan / Teman) */
.dm-side-tabs {
    display: flex;
    align-items: center;
    background: #F1F5F9;
    padding: 3px;
    border-radius: 99px;
    gap: 2px;
}

.dm-stab-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 700;
    color: #64748B;
    border-radius: 99px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.dm-stab-btn.active {
    background: #FFFFFF;
    color: #2563EB;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Conversation List */
.dm-conv-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
}

.dm-conv-item {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 12px 15px !important;
    border-bottom: 1px solid #F1F5F9 !important;
    cursor: pointer !important;
    transition: background 0.15s ease !important;
    text-decoration: none !important;
    color: inherit !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.dm-conv-item:hover {
    background: #F1F5F9 !important;
}

.dm-conv-item.active {
    background: rgba(107, 159, 255, 0.12) !important;
    box-shadow: inset 3.5px 0 0 #6B9FFF !important;
}

.dm-conv-avatar-wrap {
    position: relative !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    flex-shrink: 0 !important;
    display: block !important;
}

.dm-conv-avatar {
    width: 44px !important;
    height: 44px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 800 !important;
    font-size: 1.05rem !important;
    color: #FFFFFF !important;
    flex-shrink: 0 !important;
}

.dm-online-dot,
.dm-conv-online-dot {
    position: absolute !important;
    bottom: 0 !important;
    right: 0 !important;
    width: 12px !important;
    height: 12px !important;
    border-radius: 50% !important;
    background: #10B981 !important;
    border: 2px solid #FFFFFF !important;
}

.dm-conv-info {
    flex: 1 !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 3px !important;
}

.dm-conv-top {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    width: 100% !important;
    min-width: 0 !important;
}

.dm-conv-name {
    font-size: 0.86rem !important;
    font-weight: 800 !important;
    color: #1E293B !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
}

.dm-name-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.dm-conv-name .vx-verified-badge,
.dm-header-title .vx-verified-badge {
    flex-shrink: 0;
}

.dm-conv-time {
    font-size: 0.68rem !important;
    color: #94A3B8 !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}

.dm-conv-preview-row {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    width: 100% !important;
    min-width: 0 !important;
}

.dm-conv-snippet {
    font-size: 0.78rem !important;
    color: #64748B !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    flex: 1 !important;
    min-width: 0 !important;
}

.dm-unread-badge {
    font-size: 0.65rem !important;
    font-weight: 800 !important;
    color: #FFFFFF !important;
    background: #EF4444 !important;
    padding: 1px 6px !important;
    border-radius: 99px !important;
    flex-shrink: 0 !important;
}

/* ── Main Chat Area ── */
.dm-main-area {
    display: flex;
    flex-direction: column;
    background: #F4F6FB;
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
}

.dm-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 2rem;
    height: 100%;
    color: #64748B;
}

.dm-empty-icon {
    font-size: 3.5rem;
    margin-bottom: 1rem;
}

.dm-empty-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: #1E293B;
    margin-bottom: 6px;
}

.dm-empty-subtitle {
    font-size: 0.84rem;
    color: #94A3B8;
    max-width: 400px;
    line-height: 1.5;
}

/* Active Chat Header */
.dm-chat-header {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #FFFFFF;
    border-bottom: 1px solid #F1F5F9;
    flex-shrink: 0;
    box-sizing: border-box;
}

.dm-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.dm-back-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #1E293B;
    cursor: pointer;
    padding: 4px;
    flex-shrink: 0;
}

.dm-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.05rem;
    color: #FFFFFF;
    cursor: pointer;
    flex-shrink: 0;
}

.dm-header-meta-click {
    display: flex;
    flex-direction: column;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.dm-header-title {
    font-size: 0.92rem;
    font-weight: 800;
    color: #1E293B;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.dm-header-status {
    font-size: 0.72rem;
    font-weight: 600;
    color: #64748B;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-header-status > span:last-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94A3B8;
    display: inline-block;
    flex-shrink: 0;
}

.dm-header-status.online .dm-status-dot {
    background: #10B981;
}

.dm-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.dm-hbtn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 99px;
    font-family: inherit;
    font-size: 0.74rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.dm-hbtn-primary {
    background: linear-gradient(135deg, #6B9FFF 0%, #8B5CF6 100%) !important;
    color: #FFFFFF !important;
}

.dm-hbtn-friend {
    background: rgba(16, 185, 129, 0.15) !important;
    color: #10B981 !important;
    border: 1px solid rgba(16, 185, 129, 0.3) !important;
}

.dm-icon-btn {
    background: #F1F5F9;
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748B;
    cursor: pointer;
}

/* Messages Scroll Window */
.dm-messages-window {
    flex: 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 18px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    background: #F4F6FB;
    scrollbar-width: thin;
    box-sizing: border-box;
}

.dm-security-banner {
    background: rgba(107, 159, 255, 0.08);
    border: 1px dashed rgba(107, 159, 255, 0.3);
    border-radius: 12px;
    padding: 8px 14px;
    text-align: center;
    font-size: 0.73rem;
    color: #64748B;
    margin: 0 auto 14px;
    width: 100%;
    max-width: 560px;
    box-sizing: border-box;
    overflow-wrap: break-word;
}

.dm-date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0 6px;
}

.dm-date-pill {
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748B;
    background: rgba(15, 23, 42, 0.06);
    padding: 3px 12px;
    border-radius: 99px;
}

/* Message Rows & Bubbles (Neat Modern Telegram / WhatsApp Style) */
.dm-msg-row {
    display: flex !important;
    margin-bottom: 2px !important;
    width: 100% !important;
    box-sizing: border-box !important;
}
.dm-msg-row.me {
    justify-content: flex-end !important;
}
.dm-msg-row.them {
    justify-content: flex-start !important;
}

.dm-bubble {
    position: relative !important;
    max-width: 72% !important;
    min-width: 68px !important;
    padding: 9px 14px 7px !important;
    border-radius: 18px !important;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06) !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    display: inline-flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
}

.dm-msg-row.me .dm-bubble {
    background: linear-gradient(135deg, #5B8DEF 0%, #7C5CF6 100%) !important;
    color: #FFFFFF !important;
    border-bottom-right-radius: 5px !important;
}

.dm-msg-row.them .dm-bubble {
    background: #FFFFFF !important;
    color: #1E293B !important;
    border: 1px solid rgba(15, 23, 42, 0.07) !important;
    border-bottom-left-radius: 5px !important;
}

html.dark-mode .dm-msg-row.them .dm-bubble,
body.dark-mode .dm-msg-row.them .dm-bubble {
    background: #1E293B !important;
    color: #F1F5F9 !important;
    border-color: rgba(255, 255, 255, 0.08) !important;
}

.dm-bubble-text {
    font-size: 0.91rem !important;
    line-height: 1.5 !important;
    color: inherit !important;
    white-space: pre-wrap !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    max-width: 100% !important;
}

.dm-bubble-info {
    align-self: flex-end !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 3px !important;
    font-size: 0.64rem !important;
    margin-top: 2px !important;
    margin-left: 10px !important;
    line-height: 1 !important;
    user-select: none !important;
    opacity: 0.85 !important;
}

.dm-msg-row.me .dm-bubble-info {
    color: rgba(255, 255, 255, 0.9) !important;
}
.dm-msg-row.them .dm-bubble-info {
    color: #64748B !important;
}
html.dark-mode .dm-msg-row.them .dm-bubble-info,
body.dark-mode .dm-msg-row.them .dm-bubble-info {
    color: #94A3B8 !important;
}

.dm-tick {
    color: #E0E7FF !important;
    font-weight: 800 !important;
    font-size: 0.72rem !important;
}
.dm-msg-row.them .dm-tick {
    color: #60A5FA !important;
}

/* Floating Sticker Bubble (No rectangular box, clean anime sticker) */
.dm-sticker-bubble {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: flex-end !important;
}
.dm-msg-row.them .dm-sticker-bubble {
    align-items: flex-start !important;
}

.dm-sticker-img {
    width: 120px !important;
    max-width: 120px !important;
    height: 120px !important;
    max-height: 120px !important;
    object-fit: contain !important;
    display: block !important;
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.15)) !important;
    transition: transform 0.15s ease !important;
}
.dm-sticker-img:hover {
    transform: scale(1.05) !important;
}

.dm-sticker-info {
    font-size: 0.62rem !important;
    background: rgba(15, 23, 42, 0.5) !important;
    backdrop-filter: blur(4px) !important;
    color: #FFFFFF !important;
    padding: 2px 7px !important;
    border-radius: 99px !important;
    margin-top: 4px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 3px !important;
}
.dm-sticker-info .dm-tick {
    color: #60A5FA !important;
}

/* Media Elements */
.dm-media-img {
    max-width: min(250px, 100%) !important;
    max-height: 250px !important;
    height: auto !important;
    border-radius: 12px !important;
    object-fit: cover !important;
    cursor: pointer !important;
    display: block !important;
}
.dm-media-video {
    max-width: min(260px, 100%) !important;
    max-height: 260px !important;
    border-radius: 12px !important;
    display: block !important;
}
.dm-media-caption {
    margin-top: 6px !important;
    font-size: 0.88rem !important;
    line-height: 1.4 !important;
}

/* Media Preview Bar (Hidden by default!) */
.dm-preview-bar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: #F1F5F9;
    border-top: 1px solid #E2E8F0;
    flex-shrink: 0;
}
.dm-preview-bar.show {
    display: flex !important;
}

.dm-preview-thumb {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
}

.dm-preview-cancel {
    margin-left: auto;
    background: none;
    border: none;
    color: #EF4444;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
}

/* Sticker & Emoji Drawer (Hidden by default!) */
.dm-drawer-panel {
    display: none;
    flex-direction: column;
    background: #FFFFFF;
    border-top: 1px solid #E2E8F0;
    max-height: 200px;
    overflow-y: auto;
    padding: 10px 14px;
    flex-shrink: 0;
}
.dm-drawer-panel.show {
    display: flex !important;
}

.dm-drawer-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.dm-dtab {
    background: #F1F5F9;
    border: none;
    border-radius: 99px;
    padding: 5px 12px;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 700;
    color: #64748B;
    cursor: pointer;
    transition: all 0.15s ease;
}
.dm-dtab.active {
    background: #6B9FFF;
    color: #FFFFFF;
}

.dm-drawer-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}
#drawerStickerGrid {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)) !important;
    gap: 8px !important;
}

.dm-emoji-btn {
    background: transparent;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: transform 0.1s ease;
}
.dm-emoji-btn:hover {
    transform: scale(1.2);
    background: #F1F5F9;
}

.dm-sticker-select {
    background: rgba(107, 159, 255, 0.07) !important;
    border: 1px solid rgba(107, 159, 255, 0.15) !important;
    cursor: pointer !important;
    padding: 6px !important;
    border-radius: 12px !important;
    width: 100% !important;
    height: 68px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.15s ease !important;
    box-sizing: border-box !important;
}
.dm-sticker-select:hover {
    background: rgba(107, 159, 255, 0.2) !important;
    border-color: #6B9FFF !important;
    transform: scale(1.05) !important;
}
.dm-sticker-select img {
    width: 52px !important;
    height: 52px !important;
    max-width: 52px !important;
    max-height: 52px !important;
    object-fit: contain !important;
}

/* Chat Input Bar */
.dm-input-bar {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 12px 16px;
    background: #FFFFFF;
    border-top: 1px solid #E2E8F0;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
    box-sizing: border-box;
}

.dm-sticker-btn,
.dm-attach-btn {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: #64748B;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.dm-sticker-btn:hover,
.dm-attach-btn:hover {
    background: rgba(107, 159, 255, 0.12);
    color: #4F46E5;
}

.dm-input-field {
    flex: 1;
    min-width: 0;
    background: #F1F5F9;
    border: 1.5px solid #E2E8F0;
    border-radius: 22px;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #1E293B;
    outline: none;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    overflow-y: auto;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.dm-input-field:focus {
    background: #FFFFFF;
    border-color: #6B9FFF;
    box-shadow: 0 0 0 3px rgba(107, 159, 255, 0.16);
}

.dm-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #5B8DEF 0%, #7C5CF6 100%);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(107, 159, 255, 0.28);
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.dm-send-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════
   VELVIXIE MESSAGES — BULLETPROOF MASTER DARK MODE
   ═══════════════════════════════════════════════════════════════ */
html.dark-mode,
html.dark-mode body,
body.dark-mode {
    background: #0B0F19 !important;
    background-color: #0B0F19 !important;
    background-image: none !important;
    color: #E2E8F0 !important;
}

html.dark-mode .dm-card-frame,
body.dark-mode .dm-card-frame {
    background: #1E293B !important;
    border: 1.5px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5) !important;
}

html.dark-mode .dm-sidebar,
body.dark-mode .dm-sidebar {
    background: #162033 !important;
    border-right-color: rgba(255, 255, 255, 0.06) !important;
}

html.dark-mode .dm-sidebar-header,
body.dark-mode .dm-sidebar-header {
    background: #162033 !important;
    border-bottom-color: rgba(255, 255, 255, 0.06) !important;
}

html.dark-mode .dm-brand-title,
body.dark-mode .dm-brand-title {
    color: #F8FAFC !important;
}

html.dark-mode .dm-search-wrap,
body.dark-mode .dm-search-wrap {
    background: #0F172A !important;
    border-color: rgba(255, 255, 255, 0.08) !important;
}
html.dark-mode .dm-search-wrap:focus-within,
body.dark-mode .dm-search-wrap:focus-within {
    border-color: #60A5FA !important;
}

html.dark-mode .dm-search-input,
body.dark-mode .dm-search-input {
    color: #F8FAFC !important;
}
html.dark-mode .dm-search-input::placeholder,
body.dark-mode .dm-search-input::placeholder {
    color: #64748B !important;
}

html.dark-mode .dm-side-tabs,
body.dark-mode .dm-side-tabs {
    background: #0F172A !important;
}
html.dark-mode .dm-stab-btn,
body.dark-mode .dm-stab-btn {
    color: #94A3B8 !important;
}
html.dark-mode .dm-stab-btn.active,
body.dark-mode .dm-stab-btn.active {
    background: #1E293B !important;
    color: #60A5FA !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3) !important;
}

html.dark-mode .dm-conv-item,
body.dark-mode .dm-conv-item {
    border-bottom-color: rgba(255, 255, 255, 0.04) !important;
}
html.dark-mode .dm-conv-item:hover,
body.dark-mode .dm-conv-item:hover {
    background: #0F172A !important;
}
html.dark-mode .dm-conv-item.active,
body.dark-mode .dm-conv-item.active {
    background: rgba(96, 165, 250, 0.14) !important;
    box-shadow: inset 3.5px 0 0 #60A5FA !important;
}

html.dark-mode .dm-conv-name,
body.dark-mode .dm-conv-name {
    color: #F8FAFC !important;
}

html.dark-mode .dm-conv-snippet,
body.dark-mode .dm-conv-snippet {
    color: #94A3B8 !important;
}

html.dark-mode .dm-online-dot,
body.dark-mode .dm-online-dot {
    border-color: #1E293B !important;
}

/* Chat Pane in Dark Mode */
html.dark-mode .dm-main-area,
body.dark-mode .dm-main-area {
    background: #0F172A !important;
}

html.dark-mode .dm-empty-title,
body.dark-mode .dm-empty-title {
    color: #F8FAFC !important;
}
html.dark-mode .dm-empty-subtitle,
body.dark-mode .dm-empty-subtitle {
    color: #94A3B8 !important;
}

html.dark-mode .dm-chat-header,
body.dark-mode .dm-chat-header {
    background: #1E293B !important;
    border-bottom-color: rgba(255, 255, 255, 0.06) !important;
}
html.dark-mode .dm-header-title,
body.dark-mode .dm-header-title {
    color: #F8FAFC !important;
}
html.dark-mode .dm-back-btn,
body.dark-mode .dm-back-btn {
    color: #F8FAFC !important;
}
html.dark-mode .dm-icon-btn,
body.dark-mode .dm-icon-btn {
    background: #0F172A !important;
    color: #94A3B8 !important;
}

html.dark-mode .dm-messages-window,
body.dark-mode .dm-messages-window {
    background: #0A101D !important;
}

html.dark-mode .dm-date-pill,
body.dark-mode .dm-date-pill {
    background: rgba(255, 255, 255, 0.08) !important;
    color: #94A3B8 !important;
}

html.dark-mode .dm-header-status,
body.dark-mode .dm-header-status {
    color: #94A3B8 !important;
}

html.dark-mode .dm-header-status.online,
body.dark-mode .dm-header-status.online {
    color: #34D399 !important;
}

html.dark-mode .dm-security-banner,
body.dark-mode .dm-security-banner {
    background: rgba(107, 159, 255, 0.05) !important;
    border-color: rgba(107, 159, 255, 0.15) !important;
    color: #94A3B8 !important;
}

html.dark-mode .dm-msg-row.them .dm-bubble,
body.dark-mode .dm-msg-row.them .dm-bubble {
    background: #1E293B !important;
    color: #F1F5F9 !important;
    border-color: rgba(255, 255, 255, 0.06) !important;
}

html.dark-mode .dm-drawer-panel,
body.dark-mode .dm-drawer-panel {
    background: #1E293B !important;
    border-top-color: rgba(255, 255, 255, 0.06) !important;
}
html.dark-mode .dm-dtab,
body.dark-mode .dm-dtab {
    background: #0F172A !important;
    color: #94A3B8 !important;
}
html.dark-mode .dm-dtab.active,
body.dark-mode .dm-dtab.active {
    background: #60A5FA !important;
    color: #FFFFFF !important;
}

html.dark-mode .dm-preview-bar,
body.dark-mode .dm-preview-bar {
    background: #1E293B !important;
    border-top-color: rgba(255, 255, 255, 0.06) !important;
}
html.dark-mode #dmPreviewName,
body.dark-mode #dmPreviewName {
    color: #F8FAFC !important;
}

html.dark-mode .dm-input-bar,
body.dark-mode .dm-input-bar {
    background: #1E293B !important;
    border-top-color: rgba(255, 255, 255, 0.06) !important;
}

html.dark-mode .dm-input-field,
body.dark-mode .dm-input-field {
    background: #0F172A !important;
    color: #F8FAFC !important;
}
html.dark-mode .dm-input-field:focus,
body.dark-mode .dm-input-field:focus {
    border-color: #60A5FA !important;
}

html.dark-mode .dm-sticker-btn,
body.dark-mode .dm-sticker-btn,
html.dark-mode .dm-attach-btn,
body.dark-mode .dm-attach-btn {
    color: #94A3B8 !important;
}

/* ═══════════════════════════════════════════════════════════════
   TABLET & COMPACT DESKTOP CONTAINMENT (769PX - 1080PX)
   ═══════════════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1080px) {
    body.dm-page .dm-page-container {
        padding: 0 12px !important;
        max-width: 100% !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .dm-app-container {
        padding: 10px 4px 14px;
    }
    .dm-card-frame {
        grid-template-columns: 290px minmax(0, 1fr);
    }
}

@media (min-width: 769px) and (max-width: 900px) {
    .dm-card-frame {
        grid-template-columns: 264px minmax(0, 1fr);
    }
    .dm-chat-header {
        padding: 10px 12px;
        gap: 8px;
    }
    .dm-messages-window {
        padding: 14px;
    }
    .dm-input-bar {
        padding: 10px 12px;
        gap: 8px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE DEDICATED FULL SCREEN & COMFORTABLE CHAT (MAX-WIDTH: 768PX)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    html, body {
        height: 100% !important;
        height: 100dvh !important;
        overflow: hidden !important;
        overscroll-behavior: none !important;
    }
    body {
        padding-bottom: 0 !important;
    }
    body.dm-page .dm-page-container,
    .container:has(> .dm-app-container) {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    .dm-app-container {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        height: calc(100dvh - 54px - 64px) !important;
        height: calc(100vh - 54px - 64px) !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    .dm-card-frame {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        grid-template-columns: minmax(0, 1fr) !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    .dm-sidebar {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: 100% !important;
        border-right: none !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    .dm-sidebar-header {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    .dm-conv-list {
        flex: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        box-sizing: border-box !important;
    }

    /* Active Chat View (Full Screen on Mobile) */
    .dm-main-area {
        display: none !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: 100dvh;
        z-index: 9999999 !important;
        background: #F4F6FB !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    html.dark-mode .dm-main-area,
    body.dark-mode .dm-main-area {
        background: #090D16 !important;
    }
    .dm-main-area.mobile-open {
        display: flex !important;
        flex-direction: column !important;
    }
    #dmActiveChatWrap {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    /* Hide Mobile Bottom Nav when actively chatting */
    body.in-mobile-chat .vx-bottom-nav,
    body.in-mobile-chat #vxBottomNav {
        display: none !important;
    }

    /* Mobile Chat Header */
    .dm-chat-header {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        gap: 8px !important;
        padding: max(8px, env(safe-area-inset-top, 8px)) 12px 8px !important;
        min-height: 52px !important;
        flex-shrink: 0 !important;
        background: #FFFFFF !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.08) !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03) !important;
    }
    html.dark-mode .dm-chat-header,
    body.dark-mode .dm-chat-header {
        background: #0F172A !important;
        border-bottom-color: rgba(255, 255, 255, 0.06) !important;
    }

    .dm-back-btn {
        display: flex !important;
        width: 36px !important;
        height: 36px !important;
        border-radius: 50% !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
        background: rgba(0, 0, 0, 0.04) !important;
    }
    html.dark-mode .dm-back-btn,
    body.dark-mode .dm-back-btn {
        background: rgba(255, 255, 255, 0.08) !important;
    }
    .dm-header-left {
        gap: 8px !important;
        flex: 1 1 0 !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }
    .dm-header-meta-click {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }
    .dm-header-avatar {
        width: 36px !important;
        height: 36px !important;
    }
    .dm-header-actions {
        gap: 6px !important;
        flex-shrink: 0 !important;
    }
    .dm-hbtn {
        padding: 6px 10px !important;
        font-size: 0.72rem !important;
        white-space: nowrap !important;
    }

    /* Messages Window with smooth touch scrolling */
    .dm-messages-window {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        padding: 12px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        flex: 1 1 auto !important;
    }
    #dmMessagesList {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    /* Mobile Input Bar */
    .dm-input-bar {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        padding: 8px 10px max(8px, env(safe-area-inset-bottom, 8px)) !important;
        gap: 6px !important;
        background: #FFFFFF !important;
        border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.04) !important;
        flex-shrink: 0 !important;
        position: relative !important;
        z-index: 10 !important;
    }
    html.dark-mode .dm-input-bar,
    body.dark-mode .dm-input-bar {
        background: #1E293B !important;
        border-top-color: rgba(255, 255, 255, 0.08) !important;
    }

    /* 16px font prevents iOS Safari from auto-zooming viewport */
    .dm-input-field {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 16px !important;
        padding: 9px 14px !important;
        border-radius: 20px !important;
        line-height: 22px !important;
        min-height: 40px !important;
        max-height: 110px !important;
    }

    .dm-send-btn {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
        border-radius: 50% !important;
        flex-shrink: 0 !important;
    }

    .dm-sticker-btn,
    .dm-attach-btn {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        font-size: 1.35rem !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }

    /* Comfortable Message Bubbles */
    .dm-bubble {
        max-width: 82% !important;
        font-size: 0.88rem !important;
        padding: 9px 13px !important;
        line-height: 1.45 !important;
    }

    .dm-drawer-panel {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        max-height: 220px !important;
        padding: 8px 10px !important;
    }
    .dm-preview-bar {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}

/* Extra-Narrow Phones (<= 390px) */
@media (max-width: 390px) {
    .dm-sidebar-header {
        padding: 12px !important;
    }
    .dm-conv-item {
        padding: 11px 12px !important;
        gap: 10px !important;
    }
    .dm-chat-header {
        padding: max(8px, env(safe-area-inset-top, 8px)) 10px 8px !important;
        gap: 6px !important;
    }
    .dm-back-btn {
        width: 32px !important;
        height: 32px !important;
    }
    .dm-header-avatar {
        width: 34px !important;
        height: 34px !important;
    }
    .dm-header-title {
        font-size: 0.86rem !important;
    }
    .dm-header-status {
        font-size: 0.68rem !important;
    }
    .dm-hbtn {
        padding: 5px 9px !important;
        font-size: 0.7rem !important;
    }
    .dm-icon-btn {
        width: 32px !important;
        height: 32px !important;
    }
    .dm-messages-window {
        padding: 10px !important;
    }
    .dm-input-bar {
        padding: 7px 8px max(7px, env(safe-area-inset-bottom, 7px)) !important;
        gap: 5px !important;
    }
    .dm-sticker-btn,
    .dm-attach-btn {
        width: 34px !important;
        height: 34px !important;
        min-width: 34px !important;
        min-height: 34px !important;
    }
    .dm-input-field {
        padding: 8px 12px !important;
    }
    .dm-send-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   MODAL OVERLAYS (PROFILE & CONFIRMATION) — HIDDEN BY DEFAULT
   ═══════════════════════════════════════════════════════════════ */
.dm-modal-overlay {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.75) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    z-index: 99999999 !important;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

.dm-modal-overlay.show,
.dm-modal-overlay.active {
    display: flex !important;
}

.dm-profile-card {
    background: #FFFFFF;
    border-radius: 24px;
    width: 100%;
    max-width: 360px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    position: relative;
    animation: modalPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-sizing: border-box;
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.dm-pmodal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.dm-pmodal-header-bg {
    height: 85px;
    background: linear-gradient(135deg, #6B9FFF 0%, #8B5CF6 50%, #EC4899 100%);
}

.dm-pmodal-body {
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
}

.dm-pmodal-avatar-wrap {
    margin-top: -40px;
    margin-bottom: 10px;
}

.dm-pmodal-avatar {
    width: 75px;
    height: 75px;
    border-radius: 50%;
    border: 4px solid #FFFFFF;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 800;
    color: #FFFFFF;
    background: linear-gradient(135deg, #6B9FFF, #8B5CF6);
    overflow: hidden;
}

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

.dm-pmodal-names {
    margin-bottom: 8px;
}

.dm-pmodal-title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.dm-pmodal-name {
    font-size: 1.1rem;
    font-weight: 800;
    color: #1E293B;
    margin: 0;
}

.dm-pmodal-username {
    font-size: 0.78rem;
    color: #94A3B8;
}

.dm-pmodal-tag {
    font-size: 0.72rem;
    font-weight: 700;
    color: #6B9FFF;
    background: rgba(107, 159, 255, 0.12);
    padding: 3px 10px;
    border-radius: 99px;
    margin-bottom: 10px;
}

.dm-pmodal-bio-box {
    font-size: 0.8rem;
    color: #64748B;
    font-style: italic;
    background: #F8FAFC;
    border-radius: 12px;
    padding: 8px 12px;
    width: 100%;
    margin-bottom: 12px;
    box-sizing: border-box;
}

.dm-pmodal-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    margin-bottom: 14px;
}

.dm-pmodal-info-item {
    background: #F8FAFC;
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
}

.pmodal-info-val {
    font-size: 0.85rem;
    font-weight: 800;
    color: #1E293B;
}

.pmodal-info-lbl {
    font-size: 0.65rem;
    color: #94A3B8;
}

.dm-pmodal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.dm-pmodal-btn {
    width: 100%;
    padding: 9px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.dm-pmodal-btn-primary {
    background: linear-gradient(135deg, #6B9FFF, #8B5CF6);
    color: #FFFFFF;
}

.dm-pmodal-btn-outline {
    background: rgba(107, 159, 255, 0.1);
    color: #6B9FFF;
    border: 1px solid rgba(107, 159, 255, 0.3);
}

/* ── Custom Confirmation Dialog ── */
.vx-confirm-overlay {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.75) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    z-index: 999999999 !important;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

.vx-confirm-overlay.show,
.vx-confirm-overlay.active {
    display: flex !important;
}

.vx-confirm-card {
    background: #FFFFFF;
    border-radius: 20px;
    width: 100%;
    max-width: 320px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    animation: modalPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-sizing: border-box;
}

.vx-confirm-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.vx-confirm-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: #1E293B;
    margin-bottom: 6px;
}

.vx-confirm-msg {
    font-size: 0.8rem;
    color: #64748B;
    line-height: 1.5;
    margin-bottom: 16px;
}

.vx-confirm-actions {
    display: flex;
    gap: 8px;
}

.vx-confirm-btn {
    flex: 1;
    padding: 9px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
}

.vx-confirm-btn-cancel {
    background: #F1F5F9;
    color: #64748B;
}

.vx-confirm-btn-danger {
    background: #EF4444;
    color: #FFFFFF;
}

/* ── Dark Mode Overrides for Modals ── */
html.dark-mode .dm-profile-card,
body.dark-mode .dm-profile-card,
html.dark-mode .vx-confirm-card,
body.dark-mode .vx-confirm-card {
    background: #1E293B !important;
    border: 1.5px solid rgba(255, 255, 255, 0.08) !important;
}

html.dark-mode .dm-pmodal-avatar,
body.dark-mode .dm-pmodal-avatar {
    border-color: #1E293B !important;
}

html.dark-mode .dm-pmodal-name,
body.dark-mode .dm-pmodal-name,
html.dark-mode .vx-confirm-title,
body.dark-mode .vx-confirm-title {
    color: #F8FAFC !important;
}

html.dark-mode .dm-pmodal-username,
body.dark-mode .dm-pmodal-username,
html.dark-mode .pmodal-info-lbl,
body.dark-mode .pmodal-info-lbl {
    color: #94A3B8 !important;
}

html.dark-mode .dm-pmodal-bio-box,
body.dark-mode .dm-pmodal-bio-box,
html.dark-mode .dm-pmodal-info-item,
body.dark-mode .dm-pmodal-info-item {
    background: #0F172A !important;
    color: #CBD5E1 !important;
}

html.dark-mode .pmodal-info-val,
body.dark-mode .pmodal-info-val {
    color: #F8FAFC !important;
}

html.dark-mode .vx-confirm-msg,
body.dark-mode .vx-confirm-msg {
    color: #94A3B8 !important;
}

html.dark-mode .vx-confirm-btn-cancel,
body.dark-mode .vx-confirm-btn-cancel {
    background: #0F172A !important;
    color: #94A3B8 !important;
}
