:root {
    --bg-color: #17212b;
    --chat-bg: #0e1621;
    --panel-color: #17212b;
    --text-color: #ffffff;
    --text-muted: #7d8b99;
    --primary-color: #5288c1;
    --msg-in: #182533;  
    --msg-out: #2b5278; 
    --link-color: #4facfe;
}

@font-face { font-family: 'Vazir'; src: url('../fonts/Mahoor-Regular-FD-ELC.woff2') format('woff2'); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; outline: none; }
body, html { margin: 0; padding: 0; height: 100%; font-family: 'Vazir', sans-serif; background: var(--bg-color); color: var(--text-color); overflow: hidden; }

.app-shell { display: flex; height: 100vh; width: 100vw; position: relative; }

/* --- سایدبار --- */
.sidebar {
    width: 350px; min-width: 350px; background: var(--panel-color); 
    display: flex; flex-direction: column; border-left: 1px solid #000; z-index: 20;
}
.sidebar-top { padding: 10px; background: var(--panel-color); }

/* تب‌ها */
.sidebar-tabs { display: flex !important; flex-direction: row !important; width: 100%; margin-top: 10px; border-bottom: 2px solid #0e1621; }
.tab-btn { flex: 1; text-align: center; padding: 10px 0; color: var(--text-muted); cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab-btn.active { color: var(--link-color); border-bottom-color: var(--link-color); }

/* پروفایل */
.me { display: flex; align-items: center; padding: 10px; cursor: pointer; border-radius: 8px; margin-bottom: 5px; }
.me:hover { background: rgba(255,255,255,0.05); }
/* محدودیت اندازه آواتارها (حل مشکل تصویر غول پیکر) */
.avatar { width: 45px; height: 45px; min-width: 45px; border-radius: 50%; background: #333; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.avatar img { width: 100%; height: 100%; object-fit: cover; } 

.me-meta { margin-right: 10px; flex: 1; overflow: hidden; }
.settings-link { font-size: 13px; color: var(--link-color); text-decoration: none; display: block; margin-top: 4px; font-weight: bold; }

.top-actions { display: flex; gap: 10px; margin-top: 5px; }
.pill { flex: 1; background: #2f3b47; color: white; border: none; padding: 8px; border-radius: 6px; font-size: 12px; cursor: pointer; text-align: center; white-space: nowrap; }

.room-list { flex: 1; overflow-y: auto; }
.room-item { display: flex; align-items: center; padding: 10px 15px; cursor: pointer; transition: 0.2s; border-bottom: 1px solid rgba(0,0,0,0.2); }
.room-item:hover { background: rgba(255,255,255,0.03); }
.room-item.active { background: var(--primary-color); }

/* --- چت --- */
.chat {
    flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); position: relative;
    background-image: radial-gradient(#151f2b 15%, transparent 16%), radial-gradient(#151f2b 15%, transparent 16%);
    background-size: 20px 20px; background-position: 0 0, 10px 10px; z-index: 10;
}
.chat-header {
    height: 60px; background: var(--panel-color); display: flex; align-items: center; 
    justify-content: space-between; padding: 0 15px; border-bottom: 1px solid #000;
}
/* حل مشکل آواتار هدر */
.chat-header-avatar { width: 40px; height: 40px; min-width: 40px; border-radius: 50%; overflow: hidden; margin-left: 10px; background: #333; }
.chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-header-left { display: flex; align-items: center; overflow: hidden; flex: 1; }
.chat-title { font-weight: bold; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-right { display: flex; gap: 10px; align-items: center; }
.btn-icon { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; padding: 5px; }

/* --- پیام‌ها (اصلاح نام و چیدمان) --- */
.messages { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; gap: 10px; }
.msg-row { display: flex; width: 100%; margin-bottom: 2px; }

.msg-row.me { justify-content: flex-start; } /* پیام من (راست) */
.msg-row.other { justify-content: flex-end; } /* پیام مخاطب (چپ) */

.msg-bubble { 
    max-width: 75%; padding: 8px 12px; position: relative; font-size: 14px; line-height: 1.5; 
    border-radius: 12px; word-wrap: break-word; text-align: right; color: white; display: flex; flex-direction: column;
}
.msg-row.me .msg-bubble { background-color: var(--msg-out); border-radius: 15px 15px 0 15px; }
.msg-row.other .msg-bubble { background-color: var(--msg-in); border-radius: 15px 15px 15px 0; }

.sender-name { font-size: 11px; font-weight: bold; margin-bottom: 4px; color: #4facfe; }
.msg-row.me .sender-name { color: #a3d1ff; display: none; /* معمولا روی پیام خودمان اسم نمی‌زنیم اما اگر بخواهید هست */ }
.msg-time { font-size: 10px; color: rgba(255,255,255,0.5); align-self: flex-end; margin-top: 2px; }

.composer { background: var(--panel-color); padding: 8px; display: flex; align-items: center; gap: 8px; border-top: 1px solid #000; }
#msgInput { flex: 1; background: var(--bg-color); border: none; color: white; padding: 10px 15px; border-radius: 20px; height: 45px; resize: none; font-family: inherit; font-size: 15px; }

/* --- پنل مدیریت (اصلاح شده) --- */
.admin-container { padding: 20px; max-width: 800px; margin: 0 auto; height: 100vh; overflow-y: auto; }
.section { background: #242f3d; padding: 15px; border-radius: 10px; margin-bottom: 20px; border: 1px solid #0e1621; }
.grid-form { display: flex; flex-wrap: wrap; gap: 10px; }
.grid-form input, .grid-form select { flex: 1; min-width: 120px; padding: 10px; background: #17212b; border: 1px solid #0e1621; color: white; border-radius: 5px; }
.table-wrapper { overflow-x: auto; margin-top: 10px; }
.data-table { width: 100%; border-collapse: collapse; min-width: 500px; }
.data-table th { text-align: right; color: #7d8b99; padding: 10px; border-bottom: 1px solid #444; }
.data-table td { padding: 10px; border-bottom: 1px solid #333; color: white; }

/* موبایل */
#backToMenuBtn { display: none; font-size: 24px; color: white; background: none; border: none; margin-left: 10px; }
@media (max-width: 768px) {
    .sidebar { width: 100%; position: absolute; height: 100%; transition: transform 0.3s ease; z-index: 20; }
    .chat { width: 100%; position: absolute; height: 100%; transform: translateX(100%); transition: transform 0.3s ease; z-index: 30; }
    .app-shell.view-chat .sidebar { transform: translateX(-100%); }
    .app-shell.view-chat .chat { transform: translateX(0); }
    .app-shell.view-list .sidebar { transform: translateX(0); }
    .app-shell.view-list .chat { transform: translateX(100%); }
    #backToMenuBtn { display: block; }
}

/* Sticker & Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: none; align-items: center; justify-content: center; z-index: 4000; }
.modal-box { background: var(--panel-color); padding: 20px; border-radius: 10px; width: 90%; max-width: 350px; text-align: center; max-height: 80vh; overflow-y: auto; }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 10px; }
.sticker-item { font-size: 28px; cursor: pointer; padding: 5px; transition: 0.2s; }
.sticker-item:hover { transform: scale(1.2); }