/* --- iOS / OS X Modern Chat Layout --- */
:root {
    --ios-blue: #007aff;
    --ios-gray-bg: #f2f2f7;
    --ios-msg-received: #e5e5ea;
    --ios-separator: rgba(60, 60, 67, 0.12);
    --ios-glass-bg: rgba(255, 255, 255, 0.75);
    --ios-glass-sidebar: rgba(248, 248, 250, 0.85);
}

.chat-wrapper {
    display: flex;
    height: calc(100vh - 140px);
    min-height: 600px;
    max-height: 800px;

    /* OS X Glass Window Style */
    background-color: var(--ios-glass-bg);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0,0,0,0.05);
    overflow: hidden;
    position: relative;
}

/* Sidebar (Mac OS Style) */
.chat-sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    z-index: 2;
    background: var(--ios-glass-sidebar);
    border-left: 1px solid var(--ios-separator); /* برای RTL */
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-list {
    padding: 10px 8px; /* پدینگ برای فاصله دادن آیتم‌ها از لبه (شبیه iOS 15+) */
}

.chat-list::-webkit-scrollbar { width: 5px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }

/* Sidebar Item (iOS List Style) */
.chat-item-link {
    border: none !important;
    padding: 10px 12px !important;
    margin-bottom: 4px;
    border-radius: 12px;
    transition: all 0.2s ease;
    background: transparent;
}
.chat-item-link:hover {
    background-color: rgba(0, 0, 0, 0.04) !important;
}
.chat-item-link.active {
    background-color: rgba(0, 122, 255, 0.1) !important; /* iOS Soft Blue */
}

/* کارت سایدبار اختصاصی */
.chat-card {
    gap: 12px !important;
}
.chat-card .chat-avatar {
    width: 48px !important;
    height: 48px !important;
    border: 1px solid rgba(0,0,0,0.05) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.chat-card .chat-ad-title {
    font-size: 0.75rem !important;
    padding: 3px 8px !important;
    background-color: rgba(0, 122, 255, 0.08) !important;
    color: var(--ios-blue) !important;
    border-radius: 8px !important;
    margin-bottom: 4px !important;
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: rgba(255, 255, 255, 0.5); /* بسیار شفاف تا افکت شیشه اصلی دیده شود */
    position: relative;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Chat Messages Area */
.chat-messages-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px;
}

.chat-messages-area::-webkit-scrollbar { width: 5px; }
.chat-messages-area::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }

/* Message Bubbles - iMessage Style */
.msg-row {
    display: flex;
    margin-bottom: 6px;
    max-width: 75%;
}

/* RTL Alignments */
[dir="rtl"] .msg-row.me { align-self: flex-end; margin-left: auto; margin-right: 0; }
[dir="rtl"] .msg-row.you { align-self: flex-start; margin-right: auto; margin-left: 0; }

/* LTR Alignments */
[dir="ltr"] .msg-row.me { align-self: flex-end; margin-left: auto; margin-right: 0; }
[dir="ltr"] .msg-row.you { align-self: flex-start; margin-right: auto; margin-left: 0; }

/* iMessage Bubble Styling */
.msg-bubble {
    padding: 8px 16px;
    position: relative;
    border-radius: 20px; /* انحنای زیاد مخصوص اپل */
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    min-width: 100px;
}

/* My Messages (Sent) - iOS Blue */
.msg-row.me .msg-bubble {
    background: linear-gradient(180deg, #2b95ff 0%, var(--ios-blue) 100%);
    color: #fff;
    border-bottom-left-radius: 4px; /* گوشه تیزتر برای دم پیام در RTL */
}
[dir="ltr"] .msg-row.me .msg-bubble {
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 20px;
}

/* Received Messages - iOS Gray */
.msg-row.you .msg-bubble {
    background: var(--ios-msg-received);
    color: #000;
    border-bottom-right-radius: 4px; /* گوشه تیزتر برای دم پیام در RTL */
}
[dir="ltr"] .msg-row.you .msg-bubble {
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 20px;
}

.msg-content { word-break: break-word; }
.msg-content img {
    border-radius: 14px;
    max-width: 100%;
    display: block;
    margin-bottom: 6px;
    border: 1px solid rgba(0,0,0,0.05);
}

/* Message Meta Data */
.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 0.65rem;
    opacity: 0.9;
}
.msg-row.me .msg-meta { color: rgba(255,255,255,0.8); }
.msg-row.you .msg-meta { color: #8e8e93; }

/* Delete Message Icon */
.msg-action-icon {
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    margin-right: 6px;
    color: inherit;
    font-size: 0.8rem;
}
.msg-bubble:hover .msg-action-icon { opacity: 1; }

/* Chat Input Area (iOS Bottom Bar Style) */
.chat-input-area {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--ios-separator) !important;
    padding: 12px 16px;
    z-index: 2;
}

/* iOS Input Textfield */
.chat-input-wrapper {
    background: #fff !important;
    border-radius: 24px;
    border: 1px solid #c7c7cc !important; /* حاشیه مخصوص فیلدهای اپل */
    transition: all 0.2s ease;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}
.chat-input-wrapper:focus-within {
    border-color: var(--ios-blue) !important;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15) !important;
}

.chat-input {
    color: #1c1c1e;
}
.chat-input::placeholder {
    color: #8e8e93;
}

/* Hide Default scrollbar on textarea */
.chat-input::-webkit-scrollbar { width: 0; }

/* Recording Button Animation */
.btn-mic-record.recording i {
    color: #ff3b30 !important; /* iOS Red */
    animation: mic-pulse 1.5s infinite;
}
@keyframes mic-pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.4); background-color: rgba(255, 59, 48, 0.1); border-radius: 50%;}
    70% { box-shadow: 0 0 0 10px rgba(255, 59, 48, 0); background-color: rgba(255, 59, 48, 0); border-radius: 50%;}
    100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0); background-color: transparent; border-radius: 50%;}
}

/* --- Mobile Responsive Rules --- */
@media (max-width: 768px) {
    .chat-wrapper {
        height: calc(100vh - 120px);
        border: none;
        border-radius: 0;
        box-shadow: none;
        background: var(--ios-gray-bg);
    }

    .chat-sidebar {
        width: 100%;
        position: absolute;
        height: 100%;
        border-left: none;
    }

    .chat-main {
        width: 100%;
        position: absolute;
        height: 100%;
        transform: translateX(-100%);
    }
    [dir="rtl"] .chat-main { transform: translateX(-100%); }

    /* State: Chat Open */
    .chat-wrapper.chat-open .chat-sidebar {
        transform: translateX(100%);
    }
    [dir="rtl"] .chat-wrapper.chat-open .chat-sidebar { transform: translateX(100%); }

    .chat-wrapper.chat-open .chat-main {
        transform: translateX(0);
        z-index: 10;
    }

    .chat_sidbar_right { display: none; width: 0; }
    .chat-section-left { display: flex; width: 100%; }
}