/* --- Modern Chat Layout --- */
.chat-wrapper {
    display: flex;
    height: calc(100vh - 140px); /* تنظیم ارتفاع نسبت به هدر/فوتر */
    min-height: 600px;
    max-height: 800px;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.05);
    overflow: hidden;
    position: relative;
    border: 1px solid #edf2f7;
}

/* Sidebar (List) */
.chat-sidebar {
    width: 350px;
    background-color: #fff;
    border-left: 1px solid #edf2f7;
    display: flex;
    flex-direction: column;
    z-index: 2;
}

.chat-sidebar-header {
    padding: 15px 20px;
    border-bottom: 1px solid #edf2f7;
    font-weight: 700;
    font-size: 1.1rem;
    color: #2d3748;
    background: #fcfcfc;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.chat-list::-webkit-scrollbar {
    width: 5px;
}
.chat-list::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 10px;
}

/* Sidebar Item */
.chat-item-link {
    display: block;
    padding: 10px 15px;
    transition: all 0.2s ease;
    border-right: 3px solid transparent;
}

.chat-item-link:hover {
    background-color: #f7fafc;
}

.chat-item-link.active {
    background-color: #f0f9ff;
    border-right-color: var(--basecolor);
}

.chat-card {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.chat-info {
    flex: 1;
    min-width: 0; /* Text truncation fix */
}

.chat-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-name {
    font-weight: 600;
    color: #2d3748;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 0.75rem;
    color: #a0aec0;
}

.chat-preview-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-message-preview {
    font-size: 0.85rem;
    color: #718096;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.chat-badge {
    background-color: var(--basecolor);
    color: #fff;
    font-size: 0.7rem;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    font-weight: bold;
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%239C92AC' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    background-color: #f8fafc;
    position: relative;
}

/* Chat Header */
.chat-main-header {
    padding: 10px 20px;
    background: #fff;
    border-bottom: 1px solid #edf2f7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 65px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.chat-user-details {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-user-text {
    display: flex;
    flex-direction: column;
}

.chat-user-name {
    font-weight: 700;
    color: #2d3748;
    font-size: 1rem;
}

.chat-user-status {
    font-size: 0.8rem;
    color: #718096;
}

.chat-actions .btn {
    border-radius: 50%;
    width: 35px;
    height: 35px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 5px;
    color: #718096;
    transition: all 0.2s;
}
.chat-actions .btn:hover {
    background-color: #edf2f7;
    color: var(--basecolor);
}

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

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

.msg-row.me {
    align-self: flex-start; /* RTL: Start is right */
}
/* In RTL, flex-start is right. But we want 'me' (sender) usually on one side and 'other' on the other. 
   Standard RTL chat: Me on Left, Other on Right. 
   Let's check standard Telegram/WhatsApp RTL:
   Me (Sender): Left side.
   Other (Receiver): Right side.
*/
[dir="rtl"] .msg-row.me {
    align-self: flex-end; /* Left side in RTL flex-column */
    margin-left: auto;
    margin-right: 0;
}

[dir="rtl"] .msg-row.you {
    align-self: flex-start; /* Right side in RTL flex-column */
    margin-right: auto;
    margin-left: 0;
}

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


.msg-bubble {
    padding: 10px 14px;
    position: relative;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.6;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    min-width: 120px;
}

/* My Messages (Sent) */
.msg-row.me .msg-bubble {
    background: var(--basecolor); /* Gradient optional: linear-gradient(135deg, var(--basecolor), darken(var(--basecolor), 10%)) */
    color: #fff;
    border-bottom-left-radius: 2px; /* RTL specific corner */
}
[dir="ltr"] .msg-row.me .msg-bubble {
    border-bottom-right-radius: 2px;
    border-bottom-left-radius: 12px;
}

/* Received Messages */
.msg-row.you .msg-bubble {
    background: #fff;
    color: #2d3748;
    border-bottom-right-radius: 2px; /* RTL specific corner */
}
[dir="ltr"] .msg-row.you .msg-bubble {
    border-bottom-left-radius: 2px;
    border-bottom-right-radius: 12px;
}

.msg-content {
    word-break: break-word;
}
.msg-content img {
    border-radius: 8px;
    max-width: 100%;
    display: block;
    margin-bottom: 5px;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 0.7rem;
    opacity: 0.8;
}
.msg-row.you .msg-meta {
    color: #a0aec0;
}

/* Input Area */
.chat-input-area {
    padding: 15px;
    background: #fff;
    border-top: 1px solid #edf2f7;
    display: flex;
    align-items: flex-end; /* Align bottom if textarea grows */
    gap: 10px;
    position: relative;
}

.chat-input-wrapper {
    flex: 1;
    background: #f1f5f9;
    border-radius: 24px;
    padding: 8px 15px;
    display: flex;
    align-items: center;
    border: 1px solid transparent;
    transition: border 0.2s;
}
.chat-input-wrapper:focus-within {
    border-color: #cbd5e0;
    background: #fff;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    max-height: 100px;
    overflow-y: auto;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 0.95rem;
    padding: 8px 0;
    line-height: 1.5;
}

.btn-icon {
    border: none;
    background: transparent;
    color: #718096;
    padding: 8px;
    cursor: pointer;
    transition: color 0.2s;
    font-size: 1.2rem;
    line-height: 1;
}
.btn-icon:hover {
    color: var(--basecolor);
}

.btn-send {
    background: var(--basecolor);
    color: #fff;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: transform 0.1s;
    flex-shrink: 0;
}
.btn-send:hover {
    transform: scale(1.05);
}
.btn-send:active {
    transform: scale(0.95);
}
.btn-send i {
    font-size: 1.2rem;
    margin-right: -2px; /* Visual centering adjustment */
}

/* Audio Player Custom */
.custom-audio-player {
    min-width: 250px;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-wrapper {
        height: calc(100vh - 70px);
        border: none;
        border-radius: 0;
    }
    .chat-sidebar {
        width: 100%;
        position: absolute;
        height: 100%;
        transition: transform 0.3s ease;
    }
    .chat-main {
        width: 100%;
        position: absolute;
        height: 100%;
        transform: translateX(-100%); /* Start hidden in RTL context if sidebar is main */
        transition: transform 0.3s ease;
    }

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

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

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

    .back-to-list {
        display: inline-flex !important;
        margin-left: 10px;
        color: #4a5568;
        font-size: 1.2rem;
    }
}
@media (min-width: 769px) {
    .back-to-list { display: none !important; }
}


@media (max-width: 768px){
    .chat_sidbar_right{
        display: none;
        width: 0;
    }
    .chat-section-left{
        display: flex;
        width: 100%;
    }
}
/* استایل دکمه ضبط در حالت فعال */
.btn-mic-record.recording {
    color: #dc3545; /* رنگ قرمز */
    animation: pulse 1.5s infinite;
    border-color: #dc3545;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

/* استایل دکمه حذف پیام */
.msg-action-icon {
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    margin-right: 5px;
    color: #fff; /* قرمز */
    font-size: 0.8rem;
}
.msg-bubble:hover .msg-action-icon {
    opacity: 1;
}
.msg-row.me .msg-meta {
    justify-content: flex-end; /* آیکون‌ها در سمت چپ قرار گیرند */
}

[dir="ltr"] .chat-item-link.active{
    border-right: 0;
    border-left: 3px solid var(--basecolor);

}