/* MZChat - Main Application Styles */
/* WhatsApp-like dark theme with premium feel */

/* ========== Base & Reset ========== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Yekan Bakh FaNum', 'Roboto', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

.ltr {
    direction: ltr;
    text-align: left;
}

/* ========== Custom Scrollbar ========== */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(134, 150, 160, 0.3);
    border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(134, 150, 160, 0.5);
}

/* ========== Animations ========== */
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes pulse-ring {
    0% { transform: scale(0.8); opacity: 1; }
    100% { transform: scale(1.4); opacity: 0; }
}

.animate-modal-in {
    animation: modalIn 0.25s ease-out;
}

.animate-message-in {
    animation: messageIn 0.2s ease-out;
}

.animate-slide-in-right {
    animation: slideInRight 0.2s ease-out;
}

/* ========== Message Bubbles ========== */
.message-bubble {
    max-width: 65%;
    padding: 6px 10px;
    border-radius: 12px;
    position: relative;
    word-wrap: break-word;
    animation: messageIn 0.2s ease-out;
    line-height: 1.6;
}

.message-sent {
    background-color: #005c4b;
    border-top-right-radius: 4px;
}

.message-received {
    background-color: #202c33;
    border-top-left-radius: 4px;
}

.message-bubble .message-text {
    font-size: 0.875rem;
    color: #e9edef;
    white-space: pre-wrap;
}

.message-bubble .message-time {
    font-size: 0.65rem;
    color: rgba(233, 237, 239, 0.6);
    display: inline-flex;
    align-items: center;
    gap: 3px;
    float: left;
    margin-top: 4px;
    margin-right: 8px;
    direction: ltr;
}

.message-bubble .message-time .read-tick {
    font-size: 0.7rem;
}

.message-bubble .message-time .read-tick.read {
    color: #53bdeb;
}

/* Reply preview inside message */
.message-reply-preview {
    background: rgba(0,0,0,0.15);
    border-right: 3px solid #00a884;
    padding: 4px 8px;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 0.75rem;
}

.message-reply-preview .reply-sender {
    color: #00a884;
    font-weight: bold;
    font-size: 0.7rem;
}

.message-reply-preview .reply-content {
    color: rgba(233,237,239,0.7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* ========== Media in Messages ========== */
.message-image {
    border-radius: 8px;
    max-width: 300px;
    max-height: 300px;
    object-fit: cover;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-image:hover {
    opacity: 0.9;
}

.message-video {
    border-radius: 8px;
    max-width: 300px;
    max-height: 300px;
}

.message-voice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    min-width: 200px;
}

.message-voice .voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.message-voice .voice-play-btn:hover {
    background: rgba(255,255,255,0.25);
}

.message-voice .voice-waveform {
    flex: 1;
    height: 30px;
    display: flex;
    align-items: center;
    gap: 2px;
}

.message-voice .voice-waveform .bar {
    width: 3px;
    background: rgba(255,255,255,0.4);
    border-radius: 2px;
    transition: background 0.2s;
}

.message-voice .voice-waveform .bar.active {
    background: rgba(255,255,255,0.8);
}

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(0,0,0,0.15);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    min-width: 200px;
}

.message-file:hover {
    background: rgba(0,0,0,0.25);
}

.message-file .file-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8696a0;
    flex-shrink: 0;
}

.message-file .file-info {
    flex: 1;
    min-width: 0;
}

.message-file .file-name {
    color: #e9edef;
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-file .file-size {
    color: rgba(233,237,239,0.5);
    font-size: 0.7rem;
    margin-top: 2px;
}

/* ========== Conversation Item ========== */
.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(42, 57, 66, 0.5);
}

.conversation-item:hover {
    background: #2a3942;
}

.conversation-item.active {
    background: #2a3942;
}

.conversation-item .conv-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #128c7e 0%, #25d366 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    flex-shrink: 0;
    overflow: hidden;
}

.conversation-item .conv-info {
    flex: 1;
    min-width: 0;
}

.conversation-item .conv-name {
    color: #e9edef;
    font-size: 0.9rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-item .conv-last-message {
    color: #8696a0;
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

.conversation-item .conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    flex-shrink: 0;
}

.conversation-item .conv-time {
    color: #8696a0;
    font-size: 0.7rem;
    direction: ltr;
}

.conversation-item.has-unread .conv-time {
    color: #25d366;
}

.conversation-item .unread-badge {
    background: #25d366;
    color: #111b21;
    font-size: 0.65rem;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* ========== Contact Item ========== */
.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 12px;
}

.contact-item:hover {
    background: #2a3942;
}

/* ========== Emoji Picker ========== */
.emoji-picker {
    background: #202c33;
    border: 1px solid #2a3942;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

.emoji-categories {
    display: flex;
    border-bottom: 1px solid #2a3942;
    padding: 0 4px;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.emoji-categories::-webkit-scrollbar {
    display: none;
}

.emoji-category-btn {
    padding: 10px 12px;
    background: none;
    border: none;
    color: #8696a0;
    cursor: pointer;
    font-size: 1.1rem;
    transition: color 0.2s;
    border-bottom: 2px solid transparent;
    flex-shrink: 0;
}

.emoji-category-btn:hover,
.emoji-category-btn.active {
    color: #25d366;
    border-bottom-color: #25d366;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 8px;
    max-height: 250px;
    overflow-y: auto;
}

.emoji-grid::-webkit-scrollbar {
    width: 4px;
}

.emoji-grid::-webkit-scrollbar-thumb {
    background: rgba(134, 150, 160, 0.3);
    border-radius: 4px;
}

.emoji-item {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s, transform 0.1s;
}

.emoji-item:hover {
    background: rgba(255,255,255,0.1);
    transform: scale(1.2);
}

/* ========== Image Lightbox ========== */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
}

.lightbox img {
    max-width: 90%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

.lightbox .close-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.2s;
}

.lightbox .close-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* ========== Date Separator ========== */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 12px 0;
}

.date-separator span {
    background: rgba(17, 27, 33, 0.9);
    color: rgba(233, 237, 239, 0.6);
    padding: 4px 14px;
    border-radius: 8px;
    font-size: 0.7rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .message-bubble {
        max-width: 85%;
    }
    
    #sidebar {
        width: 100% !important;
    }
    
    #chat-area.active-mobile {
        display: flex !important;
        position: fixed;
        inset: 0;
        z-index: 40;
    }
}

@media (min-width: 769px) {
    #sidebar {
        display: flex !important;
        position: relative !important;
    }
    
    #chat-area {
        display: flex !important;
        min-width: 0;
        position: relative !important;
    }
    
    #chat-area.active-mobile {
        position: relative !important;
        inset: auto !important;
    }
}

/* ========== Toast Notifications ========== */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #2a3942;
    color: #e9edef;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 0.85rem;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.1);
    transition: transform 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    border-color: #25d366;
}

.toast.error {
    border-color: #ef4444;
}

/* ========== Group Member Chip ========== */
.member-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #128c7e33;
    color: #128c7e;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
}

.member-chip .remove-chip {
    cursor: pointer;
    margin-right: 2px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.member-chip .remove-chip:hover {
    opacity: 1;
}

/* ========== System Message ========== */
.system-message {
    text-align: center;
    padding: 4px 0;
}

.system-message span {
    background: rgba(17, 27, 33, 0.8);
    color: rgba(233, 237, 239, 0.5);
    padding: 4px 14px;
    border-radius: 8px;
    font-size: 0.75rem;
}

/* ========== RTL Adjustments ========== */
[dir="rtl"] .message-sent {
    border-top-right-radius: 4px;
    border-top-left-radius: 12px;
}

[dir="rtl"] .message-received {
    border-top-left-radius: 4px;
    border-top-right-radius: 12px;
}

/* ========== Typing Indicator ========== */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 8px 12px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #8696a0;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ========== Selection & Focus ========== */
::selection {
    background: rgba(18, 140, 126, 0.4);
}

input:focus, textarea:focus {
    outline: none;
}

/* ========== Audio Player ========== */
audio {
    height: 36px;
    border-radius: 18px;
}

audio::-webkit-media-controls-panel {
    background: transparent;
}