/* 
 * AnySpace Instant Messaging System
 * MySpace 2009-style chat interface
 */

/* ===== Core Messenger Styles ===== */
.ms-chat-tray {
    position: fixed;
    bottom: 0;
    right: 0;
    height: 30px;
    width: 100%;
    z-index: 1000;
    display: flex;
    justify-content: flex-end;
    pointer-events: none; /* Allow clicks to pass through the tray itself */
}

.ms-chat-window {
    position: fixed;
    bottom: 0;
    width: 280px;
    height: 320px;
    background: white;
    border: 1px solid #6699CC;
    border-radius: 5px 5px 0 0;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    pointer-events: auto;
    margin-right: 10px;
}

/* Handle multiple chat windows */
.ms-chat-tray .ms-chat-window:nth-child(1) { right: 10px; }
.ms-chat-tray .ms-chat-window:nth-child(2) { right: 300px; }
.ms-chat-tray .ms-chat-window:nth-child(3) { right: 590px; }
.ms-chat-tray .ms-chat-window:nth-child(4) { right: 880px; }

/* Minimized state */
.ms-chat-window.minimized {
    height: 30px;
}

.ms-chat-window.minimized .ms-chat-messages,
.ms-chat-window.minimized .ms-chat-composer,
.ms-chat-window.minimized .ms-chat-typing-indicator {
    display: none;
}

/* Chat window header */
.ms-chat-header {
    background: #6699CC;
    background-image: linear-gradient(to bottom, #6699CC, #5588BB);
    color: white;
    padding: 5px 10px;
    display: flex;
    justify-content: space-between;
    border-radius: 5px 5px 0 0;
    cursor: pointer;
    user-select: none;
    min-height: 20px;
}

.ms-chat-name {
    font-weight: bold;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ms-chat-controls {
    display: flex;
}

.ms-chat-controls button {
    border: none;
    background: none;
    color: white;
    font-size: 10px;
    cursor: pointer;
    margin-left: 5px;
    padding: 0 3px;
    line-height: 1;
}

.ms-chat-controls button:hover {
    background-color: rgba(255,255,255,0.2);
}

/* Messages container */
.ms-chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    background: #F5F5F5;
    display: flex;
    flex-direction: column;
    font-size: 12px;
}

/* Individual message styling */
.ms-chat-message {
    margin-bottom: 8px;
    max-width: 80%;
    padding: 5px 10px;
    border-radius: 12px;
    font-size: 12px;
    position: relative;
}

.ms-chat-message.outgoing {
    background: #DCE9F7;
    color: black;
    align-self: flex-end;
    border: 1px solid #B0C4DE;
}

.ms-chat-message.incoming {
    background: #FFFFFF;
    color: black;
    align-self: flex-start;
    border: 1px solid #DDDDDD;
}

.ms-chat-message-content {
    word-wrap: break-word;
}

.ms-chat-message-time {
    font-size: 9px;
    color: #999;
    text-align: right;
    margin-top: 2px;
}

/* Typing indicator */
.ms-chat-typing-indicator {
    padding: 3px 10px;
    background: #F5F5F5;
    border-top: 1px solid #E5E5EA;
    color: #999;
    font-size: 11px;
    font-style: italic;
}

/* Composer area */
.ms-chat-composer {
    border-top: 1px solid #DDDDDD;
    padding: 5px;
    background: #F9F9F9;
}

.ms-chat-input {
    width: 100%;
    resize: none;
    border: 1px solid #CCC;
    border-radius: 3px;
    padding: 5px;
    font-size: 12px;
    height: 40px;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

.ms-chat-input:focus {
    outline: none;
    border-color: #6699CC;
}

/* Loading and error states */
.ms-chat-loading, .ms-chat-error, .ms-chat-empty {
    text-align: center;
    padding: 30px 20px;
    color: #666;
}

.ms-chat-empty {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: #777;
    text-align: center;
    padding: 20px;
}

.ms-chat-empty .empty-state-icon {
    font-size: 36px;
    margin-bottom: 15px;
    animation: bounce 1s ease infinite alternate;
}

.ms-chat-empty h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: #555;
}

.ms-chat-empty p {
    margin: 0;
    font-size: 14px;
}

/* Subtle loading indicator */
.ms-chat-loading-subtle {
    position: absolute;
    bottom: 10px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 12px;
    color: #aaa;
    padding: 5px;
    opacity: 0.7;
}

/* Loading animation */
.empty-state-icon {
    font-size: 32px;
    margin-bottom: 10px;
    opacity: 0.8;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
    40% {transform: translateY(-8px);}
    60% {transform: translateY(-4px);}
}

.ms-chat-error {
    color: #CC0000;
}

/* ===== Friend List with Status Indicators ===== */
.friends-list .friend-item {
    display: flex;
    align-items: center;
    padding: 5px;
    border-bottom: 1px solid #EEE;
}

.friend-status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}

.friend-status-indicator.online {
    background: #4CAF50;
    box-shadow: 0 0 3px #4CAF50;
}

.friend-status-indicator.offline {
    background: #9E9E9E;
}

/* Friend list header with online count */
.friends-list-header {
    background: #6699CC;
    color: white;
    padding: 5px 10px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
}

.online-friends-count {
    background: #FFFFFF;
    color: #6699CC;
    border-radius: 10px;
    padding: 0 6px;
    font-size: 11px;
    line-height: 1.5;
}

/* ===== Messaging Button Styles ===== */
.message-me-btn {
    background: #6699CC;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

.message-me-btn:before {
    content: '';
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="white"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z"/></svg>');
    background-size: contain;
    width: 12px;
    height: 12px;
    display: inline-block;
    margin-right: 3px;
}

.message-me-btn:hover {
    background: #5588BB;
}

/* ===== Notifications ===== */
.messages-badge {
    background: #FF4136;
    color: white;
    border-radius: 10px;
    padding: 0 5px;
    font-size: 10px;
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 15px;
    height: 15px;
    line-height: 15px;
    text-align: center;
    display: none; /* Hidden by default */
}

/* Toast notifications */
.ms-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 10px 15px;
    border-radius: 3px;
    font-size: 12px;
    z-index: 2000;
    max-width: 250px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.ms-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ===== Mobile Responsiveness ===== */
@media (max-width: 768px) {
    .ms-chat-window {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        margin: 0;
    }
    
    .ms-chat-header {
        border-radius: 0;
    }
    
    .ms-chat-tray {
        display: none;
    }
    
    .ms-chat-controls .ms-chat-minimize {
        display: none;
    }
}
