/* =========================================
   PEANIR CHAT & TICKETING SYSTEM STYLES
========================================= */

/* --- 1. استایل‌های پاپ‌آپ --- */
.chat-textarea {
    width: 100%;
    height: 120px;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid #e4e4e7;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    color: #111;
    resize: none;
    background: #f8fafc;
    transition: all 0.3s ease;
    box-sizing: border-box;
}
.chat-textarea:focus { border-color: #111; background: #fff; outline: none; }
.chat-modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding-top: 16px; }
.chat-send-btn { background: #111; color: #fff; border: none; padding: 0 28px; height: 44px; border-radius: 24px; font-weight: 700; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }

/* --- 2. محیط صندوق پیام‌های کاربر (Dashboard Layout) --- */
.pean-messenger-layout {
    display: flex;
    background: #fff;
    border-radius: 20px;
    border: 1px solid #e4e4e7;
    overflow: hidden;
    height: 600px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.02);
    position: relative;
}

.pean-thread-list-pane {
    width: 350px;
    border-left: 1px solid #e4e4e7;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
}

.pean-chat-header {
    padding: 20px;
    border-bottom: 1px solid #e4e4e7;
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 70px;
    box-sizing: border-box;
}
.pean-chat-header h3 { margin: 0; font-size: 16px; font-weight: 800; color: #111; }

.pean-new-support-btn {
    all: unset;
    display: flex; align-items: center; gap: 6px;
    background: #111; color: #fff; font-size: 13px; font-weight: 700;
    padding: 8px 16px; border-radius: 20px; cursor: pointer;
}

/* لیست تیکت‌ها */
.pean-threads { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex-grow: 1; }
.pean-thread-item {
    padding: 16px 20px;
    border-bottom: 1px solid #e4e4e7;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
    background: #fff;
}
.pean-thread-item:hover { background: #f4f4f5; }
.thread-info { display: flex; flex-direction: column; gap: 6px; }
.thread-info strong { font-size: 14px; color: #111; }
.thread-info span { font-size: 12px; color: #71717a; }

/* وضعیت‌های تیکت */
.chat-badge { padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 700; }
.chat-badge.pending { background: #fff8e6; color: #d97706; }
.chat-badge.approved { background: #f0fdf4; color: #16a34a; }
.chat-badge.rejected { background: #fef2f2; color: #dc2626; }
.chat-badge.closed { background: #f4f4f5; color: #71717a; }

/* --- 3. محیط چت داخلی (Inline Chat Box) --- */
.pean-chat-box-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fafafa;
    position: relative;
}
.pean-chat-box-pane.hidden { display: none !important; }

.header-title-actions { display: flex; align-items: center; gap: 12px; }
.user-close-btn { all: unset; cursor: pointer; font-size: 11px; font-weight: bold; background: #fef2f2; color: #dc2626; padding: 4px 10px; border-radius: 12px; border: 1px solid #fecaca; }

.chat-back-btn { all: unset; cursor: pointer; color: #111; font-weight: 700; font-size: 14px; background: #e4e4e7; padding: 6px 12px; border-radius: 16px; display: none; }

.pean-chat-messages { flex-grow: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.chat-bubble-wrap { display: flex; flex-direction: column; max-width: 80%; }
.chat-bubble-wrap.bubble-mine { align-self: flex-start; }
.chat-bubble-wrap.bubble-other { align-self: flex-end; }

.chat-bubble-name { font-size: 11px; color: #71717a; margin-bottom: 4px; padding: 0 4px; }
.chat-bubble-time { font-size: 10px; color: #a1a1aa; margin-top: 4px; padding: 0 4px; text-align: right; }
.chat-bubble-text { padding: 12px 16px; border-radius: 16px; font-size: 14px; line-height: 1.6; }

.bubble-mine .chat-bubble-text { background: #111; color: #fff; border-top-right-radius: 4px; }
.bubble-mine .chat-bubble-name { text-align: right; }
.bubble-other .chat-bubble-text { background: #e4e4e7; color: #111; border-top-left-radius: 4px; }

/* باکس نوشتن ریپلای */
.pean-chat-reply-box { padding: 16px; background: #fff; border-top: 1px solid #e4e4e7; display: flex; gap: 12px; }
.pean-chat-reply-box textarea { flex-grow: 1; height: 44px; border-radius: 22px; padding: 10px 16px; border: 1px solid #e4e4e7; resize: none; outline: none; font-family: inherit; font-size: 14px; }
.pean-chat-reply-box textarea:focus { border-color: #111; }
.chat-send-reply-btn { background: #111; color: #fff; border: none; padding: 0 20px; border-radius: 22px; font-weight: 700; cursor: pointer; white-space: nowrap; }

/* اخطار چت بسته شده */
.chat-closed-notice {
    padding: 16px;
    text-align: center;
    background: #fef2f2;
    color: #dc2626;
    font-weight: bold;
    font-size: 14px;
    border-top: 1px solid #fecaca;
    margin: 0;
}

/* --- 4. ریسپانسیو فوق پیشرفته موبایل --- */
@media (max-width: 768px) {
    .pean-messenger-layout { flex-direction: column; border: none; box-shadow: none; height: auto; min-height: 80vh; }
    .pean-thread-list-pane { width: 100%; border-left: none; }
    
    /* تبدیل چت باکس به پاپ‌آپ ثابت روی کل صفحه */
    .pean-chat-box-pane {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100dvh; /* استفاده از dvh برای پشتیبانی از نوارهای متغیر مرورگرهای موبایل */
        z-index: 999999; /* بالاترین سطح برای پوشاندن هدر و فوتر المنتور */
        background: #fafafa;
        border-radius: 0;
        overflow: hidden;
    }
    
    .pean-chat-header {
        /* محافظت از رفتن زیر ناچ گوشی‌های جدید */
        padding-top: max(20px, env(safe-area-inset-top)); 
    }
    
    .pean-chat-reply-box {
        /* محافظت از دکمه هوم آیفون */
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .chat-back-btn { display: inline-flex; }
    .pean-chat-messages { max-height: none; } /* باگ اسکرول رفع شد */
}