/* --- تعریف فونت‌های اختصاصی --- */
@font-face {
    font-family: 'IranSansX';
    src: url('IranSansX-Regular.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'IranSansX';
    src: url('IranSansX-Bold.woff2') format('woff2');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

/* --- تنظیمات آیکون‌های SVG --- */
.icon {
    width: 24px;
    height: 24px;
    display: inline-block;
    vertical-align: middle;
    fill: currentColor; /* رنگ آیکون همان رنگ متن یا والد می‌شود */
    flex-shrink: 0;
}

/* --- متغیرهای رنگی و تنظیمات پایه --- */
:root {
    --bg-body: #f0f2f5;
    --bg-sidebar: #ffffff;
    --bg-chat: #efeae2;
    --primary: #0088cc;
    --primary-hover: #0077b5;
    --border: #e4e6eb;
    --text-main: #050505;
    --text-sec: #65676b;
    --msg-in: #ffffff;
    --msg-out: #e3f2fd;
    --error: #ea0038;
    --success: #00a884;
}
* {
    box-sizing: border-box;
    font-family: 'IranSansX', sans-serif;
    margin: 0;
    padding: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
body {
    background-color: var(--bg-body);
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* --- کامپوننت اصلی اپلیکیشن --- */
.app-container {
    width: 100%;
    height: 100%;
    max-width: 1600px;
    background: white;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* --- سایدبار --- */
.sidebar {
    width: 320px;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 20;
    flex-shrink: 0;
    transition: transform 0.3s ease-in-out;
}
.sidebar-header {
    padding: 15px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    flex-shrink: 0;
}
.my-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}
.my-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}
.search-box {
    padding: 10px 15px;
    background: var(--bg-sidebar);
    flex-shrink: 0;
    position: relative; /* برای قرارگیری آیکون جستجو */
}
.search-input {
    width: 100%;
    padding: 10px 15px 10px 40px; /* فضای خالی سمت چپ برای آیکون */
    background: var(--bg-body);
    border: none;
    border-radius: 20px;
    font-size: 0.9rem;
}
/* آیکون جستجو */
.search-icon-wrapper {
    position: absolute;
    left: 25px; /* موقعیت در RTL */
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-sec);
    pointer-events: none;
}

.users-list {
    flex: 1;
    overflow-y: auto;
}
.user-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    transition: 0.2s;
    border-bottom: 1px solid #f7f7f7;
}
.user-item:hover { background: #f5f6f6; }
.user-item.active { background: #e3f2fd; }
.user-avatar {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-left: 15px;
    flex-shrink: 0;
    position: relative;
}
.badge-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
}
.bg-Owner { background: #ec4899; }
.bg-Admin { background: #f59e0b; }
.bg-VIP { background: #6366f1; }
.bg-Member { background: #10b981; }
.user-info { flex: 1; overflow: hidden; }
.user-top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.user-name { font-weight: bold; font-size: 0.95rem; color: var(--text-main); }
.user-time { font-size: 0.75rem; color: var(--text-sec); }
.user-last-msg { font-size: 0.85rem; color: var(--text-sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- پنل چت --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-chat);
    background-image: radial-gradient(#d1d5db 1px, transparent 1px);
    background-size: 20px 20px;
    position: relative;
    min-width: 0;
}
.chat-header {
    padding: 10px 20px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
    height: 60px;
    flex-shrink: 0;
}
.chat-title { font-weight: bold; font-size: 1.1rem; display: flex; align-items: center; gap: 10px; }
.chat-subtitle { font-size: 0.8rem; color: var(--text-sec); }

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

/* --- استایل پیام‌ها --- */
.message-wrapper {
    display: flex;
    width: 100%;
    margin-bottom: 8px;
    position: relative;
}
.message-wrapper.mine { justify-content: flex-end; }
.message-wrapper.others { justify-content: flex-start; }
.message {
    max-width: 75%;
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.6;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    word-wrap: break-word;
}
.msg-in { background: var(--msg-in); border-top-right-radius: 0; }
.msg-out { background: var(--msg-out); border-top-left-radius: 0; }
.msg-meta { font-size: 0.7rem; color: #888; margin-bottom: 3px; display: flex; align-items: center; gap: 5px; }
.msg-sender { font-weight: bold; color: var(--primary); cursor: pointer; }
.msg-sender:hover { text-decoration: underline; }

/* فایل پیوست */
.msg-image { max-width: 100%; border-radius: 8px; margin-top: 5px; cursor: pointer; }
.msg-file { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,0.05); padding: 10px; border-radius: 8px; margin-top: 5px; text-decoration: none; color: var(--text-main); }

/* منوی عملیات */
.message-actions {
    position: absolute;
    top: -10px;
    left: 10px;
    background: rgba(0,0,0,0.7);
    border-radius: 5px;
    padding: 2px 5px;
    display: none;
    gap: 5px;
    z-index: 5;
}
.message-wrapper:hover .message-actions { display: flex; }
.action-btn { 
    color: white; 
    cursor: pointer; 
    font-size: 0.8rem; 
    padding: 2px; 
    display: flex; 
    align-items: center; 
    justify-content: center;
}
.action-btn:hover { color: var(--primary); }
.action-btn .icon { width: 16px; height: 16px; } /* سایز کوچکتر برای دکمه‌های اکشن */

.edited-mark { font-size: 0.6rem; color: #888; font-style: italic; margin-right: 5px; }

/* --- ورودی و هینت --- */
.chat-input-area {
    padding: 10px;
    background: var(--bg-sidebar);
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    padding: 12px 15px;
    border-radius: 25px;
    border: 1px solid var(--border);
    background: var(--bg-body);
    font-size: 16px;
}
.send-btn, .file-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    flex-shrink: 0;
    background: transparent; /* پس‌زمینه شفاف برای دکمه‌های آیکونی */
}
.send-btn { background: var(--primary); color: white; }
.send-btn:hover { background: var(--primary-hover); transform: scale(1.05); }
.file-btn { color: var(--text-sec); }
.file-btn:hover { background: #e4e6eb; border-radius: 50%; }

/* کادر هینت */
.hint-box {
    position: absolute;
    bottom: 70px;
    left: 20px;
    width: 300px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    display: none;
    z-index: 100;
    overflow: hidden;
    border: 1px solid var(--border);
}
.hint-item { padding: 10px 15px; cursor: pointer; border-bottom: 1px solid #f0f0f0; transition: 0.2s; }
.hint-item:hover { background: #f9f9f9; }
.hint-cmd { font-weight: bold; color: var(--primary); display: block; }
.hint-desc { font-size: 0.8rem; color: var(--text-sec); }

/* --- استایل‌های صفحه ورود --- */
.login-card {
    background: var(--bg-sidebar);
    width: 100%;
    max-width: 400px;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    text-align: center;
}
.login-card h2 { margin-bottom: 20px; color: var(--text-main); }
.form-group { margin-bottom: 15px; text-align: right; }
.form-group label { display: block; margin-bottom: 8px; color: var(--text-sec); font-size: 0.9rem; }
.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-body);
    font-size: 16px;
}
.form-control:focus { border-color: var(--primary); background: white; }
.btn-block {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 10px;
    font-weight: bold;
    transition: 0.3s;
}
.btn-block:hover { background: var(--primary-hover); }
.toggle-link { margin-top: 20px; font-size: 0.9rem; color: var(--primary); cursor: pointer; display: block; }
.toggle-link:hover { text-decoration: underline; }
.alert { padding: 10px; border-radius: 5px; margin-bottom: 15px; font-size: 0.9rem; }
.error { background: #ffebee; color: var(--error); }
.success { background: #e8f5e9; color: var(--success); }
.hidden { display: none; }

/* --- ریسپانسیو موبایل --- */
@media (max-width: 768px) {
    .app-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    .sidebar {
        position: absolute;
        top: 0;
        right: 0;
        width: 80%;
        max-width: 300px;
        height: 100%;
        transform: translateX(100%);
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    }
    .sidebar.active {
        transform: translateX(0);
    }
    /* دکمه منو */
    .menu-btn {
        display: block !important;
        cursor: pointer;
        font-size: 1.5rem;
        margin-left: 10px;
        color: var(--text-main);
    }
    .bg-green { background-color: #00a884; } /* آنلاین */
    .bg-yellow { background-color: #f59e0b; } /* اخیرا آنلاین */
    .bg-gray { background-color: #9ca3af; }  /* آفلاین */
    .chat-area {
        width: 100%;
    }
    .message {
        max-width: 85%;
        font-size: 0.9rem;
    }
    .chat-input-area {
        padding: 10px;
        gap: 5px;
    }
    .chat-input {
        padding: 10px;
    }
}