/* ============================================================
   DM Messaging Modal - Mobile-First Design
   Uses unified-modal design system with glassmorphism
   Cyan accent: #00d4ff
   ============================================================ */

/* ============================================================
   Modal Content Specific to DM
   ============================================================ */
.dm-modal-content {
    height: 70dvh;
    max-height: 70dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================================
   Inbox View
   ============================================================ */
.dm-inbox-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.dm-search-container {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 212, 255, 0.2);
    background: rgba(0, 212, 255, 0.05);
}

.dm-search-input {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    transition: all 0.3s ease;
}

.dm-search-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(0, 212, 255, 0.5);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.2);
}

.dm-search-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

/* ============================================================
   Conversations List
   ============================================================ */
.dm-conversations-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.dm-conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.dm-conversation-item:hover {
    background: rgba(0, 212, 255, 0.08);
}

.dm-conversation-item:active {
    background: rgba(0, 212, 255, 0.12);
}

.dm-conv-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(0, 212, 255, 0.3);
    flex-shrink: 0;
}

.dm-conv-info {
    flex: 1;
    min-width: 0; /* Allow text truncation */
}

.dm-conv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.dm-conv-username {
    font-size: 15px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-conv-time {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    margin-left: 8px;
}

.dm-conv-preview {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dm-conv-preview-text {
    flex: 1;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-conv-unread-badge {
    background: linear-gradient(135deg, #ff3366, #ff0044);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(255, 51, 102, 0.4);
}

.dm-conv-online-indicator {
    position: absolute;
    bottom: 12px;
    left: 50px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(10, 25, 47, 0.9);
}

.dm-conv-online-indicator.dm-online {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

.dm-conv-online-indicator.dm-offline {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================================
   Empty State
   ============================================================ */
.dm-empty-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    text-align: center;
}

.dm-empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.dm-empty-message {
    font-size: 16px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 8px;
}

/* ============================================================
   Thread View
   ============================================================ */
.dm-thread-view {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.dm-thread-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 212, 255, 0.2);
    background: rgba(0, 212, 255, 0.05);
    flex-shrink: 0;
}

.dm-thread-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.dm-thread-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(0, 212, 255, 0.3);
    flex-shrink: 0;
}

.dm-thread-user-details {
    flex: 1;
    min-width: 0;
}

.dm-thread-username {
    font-size: 15px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.dm-thread-username:hover {
    color: #00d4ff;
}

.dm-thread-online-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
}

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

.dm-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.dm-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

.dm-action-btn.dm-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ============================================================
   Messages Container
   ============================================================ */
.dm-messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

.dm-load-more {
    display: none;
    padding: 12px 16px;
    text-align: center;
}

.dm-load-more-btn {
    padding: 8px 20px;
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 16px;
    color: #00d4ff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dm-load-more-btn:hover {
    background: rgba(0, 212, 255, 0.2);
    transform: translateY(-1px);
}

.dm-messages-list {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================================
   Message Items
   ============================================================ */
.dm-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: dmMessageSlideIn 0.2s ease-out;
}

@keyframes dmMessageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dm-message-sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.dm-message-received {
    align-self: flex-start;
}

.dm-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(0, 212, 255, 0.2);
    flex-shrink: 0;
    cursor: pointer;
}

.dm-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.dm-message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.dm-message-sent .dm-message-bubble {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.25), rgba(0, 150, 200, 0.25));
    border: 1px solid rgba(0, 212, 255, 0.3);
    color: rgba(255, 255, 255, 0.95);
    border-top-right-radius: 4px;
}

.dm-message-received .dm-message-bubble {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    border-top-left-radius: 4px;
}

.dm-message-text {
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.dm-message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 11px;
}

.dm-message-time {
    color: rgba(255, 255, 255, 0.5);
}

.dm-message-status {
    display: flex;
    align-items: center;
}

.dm-read-receipt {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
}

.dm-read-receipt.dm-read {
    color: #00d4ff;
}

/* ============================================================
   Message Reactions
   ============================================================ */
.dm-message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.dm-reaction-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dm-reaction-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(0, 212, 255, 0.3);
    transform: scale(1.05);
}

.dm-reaction-btn.dm-reaction-add {
    font-size: 16px;
    padding: 2px 6px;
}

.dm-reaction-count {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 600;
}

/* ============================================================
   Reaction Picker
   ============================================================ */
.dm-reaction-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: rgba(15, 25, 45, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 24px;
    padding: 8px;
    display: none;
    flex-direction: row;
    gap: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 10000;
}

.dm-reaction-picker.show {
    display: flex;
}

.dm-reaction-picker-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dm-reaction-picker-btn:hover {
    background: rgba(0, 212, 255, 0.2);
    transform: scale(1.15);
}

/* ============================================================
   Compose Area
   ============================================================ */
.dm-compose-container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 212, 255, 0.2);
    background: rgba(0, 212, 255, 0.03);
    flex-shrink: 0;
}

.dm-compose-input {
    flex: 1;
    min-height: 38px;
    max-height: 120px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.95);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    transition: all 0.3s ease;
}

.dm-compose-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(0, 212, 255, 0.5);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.2);
}

.dm-compose-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.dm-send-btn {
    width: 38px;
    height: 38px;
    border: none;
    background: linear-gradient(135deg, #00d4ff, #0096c8);
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 212, 255, 0.3);
}

.dm-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 212, 255, 0.5);
}

.dm-send-btn:active {
    transform: scale(0.95);
}

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

.dm-send-icon {
    display: block;
}

.dm-char-counter {
    position: absolute;
    bottom: 16px;
    right: 70px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    pointer-events: none;
}

.dm-char-counter.dm-near-limit {
    color: #fbbf24;
}

.dm-char-counter.dm-at-limit {
    color: #ef4444;
}

/* ============================================================
   Unread Badge (Toolbar)
   ============================================================ */
.dm-unread-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    background: linear-gradient(135deg, #ff3366, #ff0044);
    color: white;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(255, 51, 102, 0.6);
    animation: dmBadgePulse 2s ease-in-out infinite;
    min-width: 18px;
    text-align: center;
}

@keyframes dmBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.dm-unread-count {
    display: block;
}

/* ============================================================
   Responsive: Portrait Mode
   ============================================================ */
@media (orientation: portrait) {
    .dm-message {
        max-width: 80%;
    }

    .dm-compose-container {
        padding: 10px 12px;
        padding-bottom: calc(env(safe-area-inset-bottom) + 75px) !important;
    }

    .dm-char-counter {
        display: none; /* Hide on small screens */
    }
}

/* ============================================================
   Responsive: Landscape Mode
   ============================================================ */
@media (orientation: landscape) {
    .dm-message {
        max-width: 70%;
    }

    .dm-thread-header {
        padding: 10px 16px;
    }

    .dm-messages-list {
        padding: 12px 20px;
    }
}

/* ============================================================
   Responsive: Mobile (iPhone 15 Pro and similar)
   ============================================================ */
@media (max-width: 768px) {
    .dm-modal-content {
        margin: 0;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border: none;
        border-radius: 0;
    }

    .dm-search-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .dm-compose-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .dm-message-text {
        font-size: 15px; /* Slightly larger for readability */
    }
}

/* ============================================================
   Landscape Mode on Mobile
   ============================================================ */
@media (max-width: 1024px) and (orientation: landscape) {
    .dm-modal-content {
        margin: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border: none !important;
        border-radius: 0 !important;
    }

    .dm-thread-header {
        padding: 8px 12px;
    }

    .dm-messages-list {
        padding: 8px 12px;
    }

    .dm-compose-container {
        padding: 8px 12px;
    }
}

/* ============================================================
   Loading States
   ============================================================ */
.dm-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.dm-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(0, 212, 255, 0.2);
    border-top-color: #00d4ff;
    border-radius: 50%;
    animation: dmSpin 0.8s linear infinite;
}

@keyframes dmSpin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   Optimistic UI (Sending State)
   ============================================================ */
.dm-message.dm-sending {
    opacity: 0.6;
}

.dm-message.dm-sending .dm-message-bubble {
    background: rgba(0, 212, 255, 0.15);
    border-style: dashed;
}

.dm-message.dm-error {
    opacity: 0.5;
}

.dm-message.dm-error .dm-message-bubble {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
}

/* ============================================================
   Accessibility
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .dm-message,
    .dm-conversation-item,
    .dm-unread-badge,
    .dm-action-btn,
    .dm-reaction-btn,
    .dm-send-btn {
        animation: none;
        transition: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .dm-message-bubble {
        border-width: 2px;
    }

    .dm-search-input,
    .dm-compose-input {
        border-width: 2px;
    }
}
