/* Chat Widget Styles - Realmify Theme */
/* Voxel Forge Theme */

/* Chat Contacts Widget - Bottom Right */
#chatContactsWidget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;
    max-height: 500px;
    background: var(--realmify-deep-grid-gray);
    border: 1px solid var(--realmify-border-dark);
    border-radius: var(--realmify-radius);
    box-shadow: var(--realmify-shadow-card);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform var(--realmify-duration) var(--realmify-transition), opacity var(--realmify-duration) var(--realmify-transition);
    max-width: calc(100vw - 40px);
}

#chatContactsWidget.minimized {
    transform: translateY(calc(100% - 50px));
    max-height: 50px;
}

#chatContactsWidget .widget-header {
    background: linear-gradient(135deg, var(--realmify-voxel-blue) 0%, var(--realmify-arcane-teal) 100%);
    color: var(--realmify-text-primary);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

#chatContactsWidget .widget-header:hover {
    background: linear-gradient(135deg, var(--realmify-arcane-teal) 0%, var(--realmify-voxel-blue) 100%);
}

#chatContactsWidget .widget-header h6 {
    margin: 0;
    font-weight: 600;
    font-size: 14px;
    color: var(--realmify-text-primary);
}

#chatContactsWidget .widget-header .badge {
    background: rgba(248, 249, 255, 0.3);
    color: var(--realmify-text-primary);
    font-size: 11px;
    padding: 2px 6px;
}

#chatContactsWidget .widget-header .widget-controls {
    display: flex;
    gap: 8px;
}

#chatContactsWidget .widget-header .widget-controls button {
    background: transparent;
    border: none;
    color: var(--realmify-text-primary);
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.8;
    transition: opacity var(--realmify-duration);
}

#chatContactsWidget .widget-header .widget-controls button:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

#chatContactsWidget .widget-tabs {
    display: flex;
    background: var(--realmify-dark-bg);
    border-bottom: 1px solid var(--realmify-border-dark);
}

#chatContactsWidget .widget-tab {
    flex: 1;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--realmify-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all var(--realmify-duration);
}

#chatContactsWidget .widget-tab:hover {
    background: var(--realmify-deep-grid-gray);
    color: var(--realmify-text-primary);
}

#chatContactsWidget .widget-tab.active {
    color: var(--realmify-arcane-teal);
    border-bottom-color: var(--realmify-arcane-teal);
    background: var(--realmify-deep-grid-gray);
    font-weight: 600;
}

#chatContactsWidget .widget-tab i {
    font-size: 14px;
}

#chatContactsWidget .widget-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    position: relative;
    background: var(--realmify-deep-grid-gray);
}

#chatContactsWidget .tab-content {
    display: none;
    height: 100%;
    overflow-y: auto;
}

#chatContactsWidget .tab-content.active {
    display: block;
}

#chatContactsWidget .tab-content .loading {
    padding: 20px;
    text-align: center;
    color: var(--realmify-text-secondary);
    font-size: 14px;
}

#chatContactsWidget #chatContactsList,
#chatContactsWidget #chatContactsListAll {
    padding: 8px;
}

#chatContactsWidget .tab-content::-webkit-scrollbar {
    width: 6px;
}

#chatContactsWidget .tab-content::-webkit-scrollbar-track {
    background: var(--realmify-dark-bg);
}

#chatContactsWidget .tab-content::-webkit-scrollbar-thumb {
    background: var(--realmify-border-dark);
    border-radius: 3px;
}

#chatContactsWidget .tab-content::-webkit-scrollbar-thumb:hover {
    background: var(--realmify-arcane-teal);
}

#chatContactsWidget .contact-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-radius: var(--realmify-radius-sm);
    cursor: pointer;
    transition: background var(--realmify-duration);
    margin-bottom: 4px;
}

#chatContactsWidget .contact-item:hover {
    background: var(--realmify-dark-bg);
}

#chatContactsWidget .contact-item.active {
    background: rgba(28, 156, 246, 0.15);
    border: 1px solid rgba(28, 156, 246, 0.3);
}

#chatContactsWidget .contact-item .contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    border: 2px solid var(--realmify-border-dark);
}

#chatContactsWidget .contact-item .contact-info {
    flex: 1;
    min-width: 0;
}

#chatContactsWidget .contact-item .contact-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--realmify-text-primary);
    margin: 0 0 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chatContactsWidget .contact-item .contact-last-message {
    font-size: 12px;
    color: var(--realmify-text-secondary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chatContactsWidget .contact-item .view-profile-btn {
    color: var(--realmify-voxel-blue);
    font-size: 18px;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity var(--realmify-duration);
}

#chatContactsWidget .contact-item .view-profile-btn:hover {
    opacity: 1;
    color: var(--realmify-arcane-teal);
}

#chatContactsWidget .contact-item .contact-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

#chatContactsWidget .contact-item .contact-time {
    font-size: 11px;
    color: var(--realmify-text-secondary);
}

#chatContactsWidget .contact-item .unread-badge {
    background: #ff4757;
    color: var(--realmify-text-primary);
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

#chatContactsWidget .contact-item .status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--realmify-text-muted);
    border: 2px solid var(--realmify-deep-grid-gray);
    /* margin-left: -12px;
    margin-top: 28px; */
}

#chatContactsWidget .contact-item .status-indicator.online {
    background: var(--realmify-arcane-teal);
}

/* Chat Window - Floating Conversation */
.chat-window {
    position: fixed;
    width: 380px;
    height: 500px;
    background: var(--realmify-deep-grid-gray);
    border: 1px solid var(--realmify-border-dark);
    border-radius: var(--realmify-radius);
    box-shadow: var(--realmify-shadow-card);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform var(--realmify-duration) var(--realmify-transition), opacity var(--realmify-duration) var(--realmify-transition);
}

.chat-window.minimized {
    height: 50px;
    overflow: hidden;
}

.chat-window .chat-header {
    background: linear-gradient(135deg, var(--realmify-voxel-blue) 0%, var(--realmify-arcane-teal) 100%);
    color: var(--realmify-text-primary);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
    -webkit-user-select: none;
    user-select: none;
}

.chat-window .chat-header:hover {
    background: linear-gradient(135deg, var(--realmify-arcane-teal) 0%, var(--realmify-voxel-blue) 100%);
}

.chat-window .chat-header .contact-info {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.chat-window .chat-header .contact-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.chat-window .chat-header .contact-details {
    flex: 1;
    min-width: 0;
}

.chat-window .chat-header .contact-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--realmify-text-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-window .chat-header .contact-status {
    font-size: 11px;
    color: var(--realmify-text-primary);
    opacity: 0.9;
    margin: 0;
}

.chat-window .chat-header .chat-controls {
    display: flex;
    gap: 8px;
}

.chat-window .chat-header .chat-controls button {
    background: transparent;
    border: none;
    color: var(--realmify-text-primary);
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.8;
    transition: opacity var(--realmify-duration);
}

.chat-window .chat-header .chat-controls button:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.chat-window .chat-header .chat-controls .view-profile-chat-btn {
    font-size: 18px;
}

.chat-window .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--realmify-dark-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-window .chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-window .chat-messages::-webkit-scrollbar-track {
    background: var(--realmify-dark-bg);
}

.chat-window .chat-messages::-webkit-scrollbar-thumb {
    background: var(--realmify-border-dark);
    border-radius: 3px;
}

.chat-window .chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--realmify-arcane-teal);
}

.chat-window .message {
    display: flex;
    gap: 8px;
    animation: messageSlideIn 0.3s ease;
}

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

.chat-window .message.sent {
    flex-direction: row-reverse;
}

.chat-window .message .message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-window .message .message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-window .message.sent .message-content {
    align-items: flex-end;
}

.chat-window .message .message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.4;
}

.chat-window .message.received .message-bubble {
    background: var(--realmify-deep-grid-gray);
    color: var(--realmify-text-primary);
    border: 1px solid var(--realmify-border-dark);
    border-bottom-left-radius: 4px;
}

.chat-window .message.sent .message-bubble {
    background: linear-gradient(135deg, var(--realmify-voxel-blue) 0%, var(--realmify-arcane-teal) 100%);
    color: var(--realmify-text-primary);
    border-bottom-right-radius: 4px;
}

.chat-window .message .message-time {
    font-size: 10px;
    color: var(--realmify-text-secondary);
    padding: 0 4px;
}

.chat-window .chat-input {
    padding: 12px;
    background: var(--realmify-deep-grid-gray);
    border-top: 1px solid var(--realmify-border-dark);
    display: flex;
    gap: 8px;
}

.chat-window .chat-input input {
    flex: 1;
    border: 1px solid var(--realmify-border-dark);
    background: var(--realmify-dark-bg);
    color: var(--realmify-text-primary);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color var(--realmify-duration);
}

.chat-window .chat-input input::placeholder {
    color: var(--realmify-text-muted);
}

.chat-window .chat-input input:focus {
    border-color: var(--realmify-arcane-teal);
    box-shadow: var(--realmify-shadow-glow);
}

.chat-window .chat-input button {
    background: linear-gradient(135deg, var(--realmify-voxel-blue) 0%, var(--realmify-arcane-teal) 100%);
    color: var(--realmify-text-primary);
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    cursor: pointer;
    transition: opacity var(--realmify-duration);
    font-weight: 600;
}

.chat-window .chat-input button:hover {
    opacity: 0.9;
    box-shadow: var(--realmify-shadow-glow);
}

.chat-window .chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Empty state */
.chat-window .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--realmify-text-secondary);
    text-align: center;
    padding: 20px;
}

.chat-window .empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.chat-window .empty-state .empty-text {
    font-size: 14px;
}

/* Loading indicator */
.chat-window .loading {
    text-align: center;
    padding: 20px;
    color: var(--realmify-text-secondary);
    font-size: 14px;
}

/* Notification badge on widget */
#chatContactsWidget .unread-total-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ff4757;
    color: var(--realmify-text-primary);
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    border: 2px solid var(--realmify-deep-grid-gray);
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

@media (max-width: 768px) {
    /* Chat Contacts Widget - Full width on mobile */
    #chatContactsWidget {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        z-index: 9999;
    }

    #chatContactsWidget.minimized {
        transform: translateY(calc(100vh - 60px));
        max-height: 60px;
        height: 60px;
    }

    #chatContactsWidget .widget-header {
        padding: 16px;
        min-height: 60px;
    }

    #chatContactsWidget .widget-header h6 {
        font-size: 16px;
    }

    #chatContactsWidget .widget-header .widget-controls button {
        padding: 8px 12px;
        font-size: 18px;
    }

    #chatContactsWidget .widget-tab {
        padding: 14px 12px;
        font-size: 14px;
    }

    #chatContactsWidget .contact-item {
        padding: 14px 12px;
    }

    #chatContactsWidget .contact-item .contact-avatar {
        width: 48px;
        height: 48px;
    }

    #chatContactsWidget .contact-item .contact-name {
        font-size: 16px;
    }

    #chatContactsWidget .contact-item .contact-last-message {
        font-size: 13px;
    }

    /* Chat Window - Full screen on mobile */
    .chat-window {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        z-index: 10000;
    }

    .chat-window.minimized {
        height: 60px;
        max-height: 60px;
    }

    .chat-window .chat-header {
        padding: 16px;
        min-height: 60px;
        cursor: default; /* Disable drag on mobile */
    }

    .chat-window .chat-header .contact-avatar {
        width: 40px;
        height: 40px;
    }

    .chat-window .chat-header .contact-name {
        font-size: 16px;
    }

    .chat-window .chat-header .contact-status {
        font-size: 12px;
    }

    .chat-window .chat-header .chat-controls {
        gap: 12px;
    }

    .chat-window .chat-header .chat-controls button {
        padding: 8px 12px;
        font-size: 20px;
        min-width: 44px; /* Touch target size */
        min-height: 44px;
    }

    .chat-window .chat-header .chat-controls .back-to-contacts {
        font-size: 22px;
    }

    .chat-window .chat-messages {
        padding: 12px;
        gap: 10px;
        /* Account for header and input height */
        max-height: calc(100vh - 120px);
    }

    .chat-window .message {
        gap: 10px;
    }

    .chat-window .message .message-avatar {
        width: 36px;
        height: 36px;
    }

    .chat-window .message .message-content {
        max-width: 80%; /* More width on mobile */
    }

    .chat-window .message .message-bubble {
        padding: 12px 16px;
        font-size: 15px;
        line-height: 1.5;
    }

    .chat-window .message .message-time {
        font-size: 11px;
    }

    /* Chat Input - Larger and more touch-friendly */
    .chat-window .chat-input {
        padding: 12px 16px;
        gap: 12px;
        min-height: 70px;
        border-top: 2px solid var(--realmify-border-dark);
    }

    .chat-window .chat-input input {
        padding: 12px 18px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 24px;
        min-height: 48px; /* Touch target size */
    }

    .chat-window .chat-input button {
        padding: 12px 20px;
        border-radius: 24px;
        min-width: 60px;
        min-height: 48px; /* Touch target size */
        font-size: 16px;
    }

    /* Hide drag cursor on mobile */
    .chat-window .chat-header {
        cursor: default;
    }

    /* Better scrollbar on mobile */
    .chat-window .chat-messages::-webkit-scrollbar {
        width: 4px;
    }

    #chatContactsWidget .tab-content::-webkit-scrollbar {
        width: 4px;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    #chatContactsWidget {
        width: 280px;
        max-height: 450px;
    }

    .chat-window {
        width: 360px;
        height: 480px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    #chatContactsWidget .widget-header h6 {
        font-size: 14px;
    }

    .chat-window .chat-header .contact-name {
        font-size: 15px;
    }

    .chat-window .message .message-bubble {
        padding: 10px 14px;
        font-size: 14px;
    }

    .chat-window .chat-input input {
        font-size: 16px; /* Keep 16px to prevent zoom */
    }
}
