/* =========================================
   معرفی فونت‌های محلی (لود از هاست)
========================================= */
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-Light.woff2') format('woff2');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-bold.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* =========================================
   متغیرهای رنگی (سبک طبیعت تاریک - Dark Forest Glass)
========================================= */
:root {
    --primary: #4ade80;         /* سبز ملایم متناسب با طبیعت */
    --primary-hover: #22c55e;
    --bg-glass: rgba(18, 25, 22, 0.65); /* شیشه تیره متمایل به سبز دودی */
    --bg-glass-hover: rgba(255, 255, 255, 0.06);
    --border-glass: rgba(255, 255, 255, 0.08); 
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --msg-sent: rgba(74, 222, 128, 0.15); /* حباب پیام سبز ملایم */
    --msg-received: rgba(255, 255, 255, 0.05); /* حباب پیام دودی */
    --unread-bg: #4ade80;
    --shadow-glass: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* =========================================
   اسکرول‌بار اختصاصی تاریک و محو
========================================= */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* =========================================
   استایل‌های عمومی و قفل صفحه
========================================= */
* { box-sizing: border-box; outline: none; }

html, body {
    overflow: hidden !important; 
    width: 100%;
    margin: 0;
    padding: 0;
}

body, input, button, textarea, select, div, span, p, a { 
    font-family: 'Vazirmatn', sans-serif; 
    font-weight: 300; 
}

h1, h2, h3, h4, h5, h6, b, strong, .sidebar-header, .chat-header-info {
    font-weight: 400 !important;
}

/* =========================================
   بدنه اصلی (پس‌زمینه جنگل تاریک)
========================================= */
body {
    display: flex; 
    height: 100vh; 
    height: 100dvh; 
    /* یک عکس تاریک از جنگل کاج. می‌توانید URL عکس دلخواه خود را قرار دهید */
    background: url('../images/bg.webp') center/cover no-repeat;
    background-color: #050b08; /* رنگ پشتیبان */
    color: var(--text-main); 
    padding: 24px; /* ایجاد فاصله از لبه‌های مانیتور */
    gap: 24px; /* فاصله بین سایدبار و بخش چت */
}

/* مه و غبار ملایم در پس‌زمینه (اختیاری) */
.bg-shapes { position: fixed; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; z-index: -1; pointer-events: none; background: radial-gradient(circle at bottom, rgba(74, 222, 128, 0.05), transparent 50%); }

/* =========================================
   بخش ۱: کدهای صفحه لاگین
========================================= */
body.login-body {
    align-items: center; justify-content: center;
    padding: 20px;
}

.login-glass {
    background: var(--bg-glass); 
    backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--border-glass); 
    border-radius: 28px; 
    padding: 50px 40px; 
    width: 100%; max-width: 400px; 
    margin: auto;
    box-shadow: var(--shadow-glass); 
    text-align: center; position: relative; z-index: 10;
    animation: fadeInUP 0.8s ease forwards;
}
@keyframes fadeInUP { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.login-glass h2 { font-size: 1.7rem; margin-bottom: 35px; color: #ffffff; }

.input-group { position: relative; margin-bottom: 25px; text-align: right; }
.input-group i { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 1.1rem; }
.input-group input { 
    width: 100%; padding: 16px 50px 16px 20px; 
    background: rgba(0, 0, 0, 0.4); 
    border: 1px solid var(--border-glass); 
    border-radius: 18px; font-size: 0.95rem; color: #ffffff; transition: all 0.3s ease; 
}
.input-group input::placeholder { color: var(--text-muted); }
.input-group input:focus { background: rgba(0, 0, 0, 0.6); border-color: var(--primary); }
.input-group input:focus + i { color: var(--primary); }

.btn-submit { 
    width: 100%; padding: 16px; background: rgba(255,255,255,0.05); color: #ffffff; 
    border: 1px solid var(--border-glass); border-radius: 18px; font-size: 1.05rem; 
    cursor: pointer; transition: all 0.3s ease; margin-top: 10px; display: flex; justify-content: center; align-items: center; gap: 10px; 
}
.btn-submit:hover { background: var(--primary); color: #000; border-color: var(--primary); box-shadow: 0 5px 20px rgba(74, 222, 128, 0.3); }

.error-msg { background: rgba(239, 68, 68, 0.1); color: #fca5a5; padding: 12px; border-radius: 14px; margin-bottom: 20px; font-size: 0.85rem; border: 1px solid rgba(239, 68, 68, 0.2); display: none; }

/* =========================================
   بخش ۲: محیط اصلی چت (پنل‌های معلق)
========================================= */

/* سایدبار (لیست مخاطبین) */
.sidebar { 
    width: 320px; height: 100%; background: var(--bg-glass); 
    backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px);
    display: flex; flex-direction: column; border: 1px solid var(--border-glass); 
    border-radius: 28px; z-index: 10; transition: all 0.3s ease; overflow: hidden; box-shadow: var(--shadow-glass);
}
.sidebar-header { 
    padding: 20px 24px; background: rgba(0, 0, 0, 0.2); border-bottom: 1px solid var(--border-glass); 
    display: flex; align-items: center; justify-content: space-between; 
    flex-shrink: 0; 
    position: sticky; /* Make it sticky */
    top: 0;
    z-index: 20;
}
.user-list { overflow-y: auto; flex-grow: 1; padding: 10px 0; }
.list-sep { 
    padding: 8px 24px; margin-top: 5px;
    background: transparent; 
    font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px;
    border-bottom: none; 
}
.user-item { 
    padding: 12px 24px; margin: 4px 12px; border-radius: 16px;
    cursor: pointer; transition: all 0.2s; 
    display: flex; align-items: center; gap: 15px; border: none;
    position: relative; 
}
.user-item:hover { background: var(--bg-glass-hover); }
.user-item.active { 
    background: rgba(255, 255, 255, 0.1) !important; 
    box-shadow: inset 0 0 0 1px var(--border-glass);
}

/* پروفایل‌ها */
.user-avatar { 
    width: 46px; height: 46px; border-radius: 50%; 
    background: #1f2937; display: flex; align-items: center; justify-content: center; 
    color: white; object-fit: cover; flex-shrink: 0; 
}
.user-info b { font-size: 0.95rem; color: #e2e8f0; }
.unread-badge { 
    background: var(--primary); color: #000; border-radius: 20px; 
    padding: 2px 8px; font-size: 11px; font-weight: 500; margin-right: auto; 
}

/* بخش چت */
.chat-area { 
    flex-grow: 1; height: 100%;
    background: var(--bg-glass);
    backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--border-glass);
    border-radius: 28px;
    display: flex; flex-direction: column; position: relative; 
    overflow: hidden; box-shadow: var(--shadow-glass);
}
.chat-header { 
    padding: 15px 24px; 
    background: rgba(0, 0, 0, 0.1); 
    border-bottom: 1px solid var(--border-glass); 
    display: flex; justify-content: space-between; align-items: center; 
    z-index: 5; 
}
.back-btn { display: none; background: none; border: none; font-size: 1.2rem; color: var(--text-muted); cursor: pointer; padding: 5px; transition: color 0.2s; }

.messages { 
    flex-grow: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; 
    background: transparent; 
}

/* استایل پیام‌ها (بدون تیزی، فقط حباب گرد) */
.msg-wrapper { display: flex; gap: 12px; max-width: 80%; }
.msg-wrapper.sent { flex-direction: row-reverse; align-self: flex-end; }
.msg-wrapper.received { align-self: flex-start; }
.msg-avatar-mini { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: rgba(255,255,255,0.1); color: white; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.msg-body { display: flex; flex-direction: column; max-width: 100%; }

.msg { 
    padding: 12px 18px; border-radius: 20px; font-size: 0.95rem; line-height: 1.6; 
    word-wrap: break-word; position: relative; cursor: pointer; 
    animation: fadeIn 0.3s ease forwards;
}
.sent .msg { 
    background: var(--msg-sent); 
    color: #fff; border: 1px solid rgba(74, 222, 128, 0.2);
}
.received .msg { 
    background: var(--msg-received); 
    color: #e2e8f0; border: 1px solid var(--border-glass); 
}
.sender-name { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; margin-right: 5px; }
.msg img { max-width: 100%; max-height: 250px; border-radius: 12px; display: block; margin-top: 5px; object-fit: cover; }
.msg audio { display: block; margin-top: 5px; height: 40px; max-width: 100%; filter: invert(0.8) hue-rotate(180deg); opacity: 0.8; }

/* فوتر (بخش ارسال پیام مدل Pill) */
.footer { 
    padding: 12px 20px; /* Reduced padding for a tighter look */
    padding-bottom: calc(12px + env(safe-area-inset-bottom)); 
    background: rgba(18, 25, 22, 0.8); /* Slightly less transparent for readability */
    backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px);
    border-top: 1px solid var(--border-glass); 
    display: flex; gap: 10px; align-items: center; 
    flex-shrink: 0; /* Prevents squishing */
    z-index: 10;
}

.input-wrapper { 
    flex-grow: 1; display: flex; align-items: center; 
    background: rgba(0, 0, 0, 0.4); 
    border-radius: 24px; /* More rounded pill shape */
    padding: 6px 16px; 
    border: 1px solid var(--border-glass); transition: all 0.3s; 
}
.input-wrapper:focus-within { background: rgba(0, 0, 0, 0.6); border-color: var(--primary); }
.input-wrapper input[type="text"] { flex-grow: 1; padding: 10px 5px; border: none; background: transparent; color: white; font-size: 0.95rem; }
.input-wrapper input::placeholder { color: var(--text-muted); }

/* دکمه ارسال کاملا گرد */
.btn-send { 
    background: var(--primary); color: #000; border: none; 
    width: 44px; height: 44px; /* Perfect circle */
    border-radius: 50%; cursor: pointer; 
    display: flex; align-items: center; justify-content: center; font-size: 1.1rem; 
    box-shadow: 0 4px 15px rgba(74, 222, 128, 0.2); transition: transform 0.2s; flex-shrink: 0;
}
.btn-send:hover { transform: scale(1.05); background: var(--primary-hover); }

/* مدال‌ها و منوها */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); display: none; z-index: 10000; align-items: center; justify-content: center; backdrop-filter: blur(8px); }
.modal-content { 
    background: var(--bg-glass); backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px);
    width: 90%; max-width: 400px; padding: 30px; border-radius: 28px; 
    border: 1px solid var(--border-glass); box-shadow: var(--shadow-glass); color: white;
}
.modal-content input[type="text"] { background: rgba(0,0,0,0.4); border: 1px solid var(--border-glass); color: white; }

.msg-menu { 
    position: fixed; background: rgba(20, 25, 20, 0.85); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-radius: 16px; box-shadow: var(--shadow-glass); display: none; z-index: 9999; 
    min-width: 160px; border: 1px solid var(--border-glass); overflow: hidden; 
}
.msg-menu div { padding: 14px 18px; cursor: pointer; font-size: 0.95rem; color: #f1f5f9; transition: 0.2s; display: flex; align-items: center; gap: 10px; }
.msg-menu div:hover { background: rgba(255,255,255,0.08); }

/* ویدیو کال */
#videoOverlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: #050b08; /* Solid dark background for calls */
    display: none; z-index: 10000; flex-direction: column; align-items: center; justify-content: center; 
}
.video-box { 
    position: relative; width: 100%; height: 100%; /* Full screen */
    background: #000; overflow: hidden; 
}
#remoteVideo { width: 100%; height: 100%; object-fit: cover; }
#localVideo { 
    width: 120px; aspect-ratio: 3/4; position: absolute; bottom: 100px; right: 20px; 
    border: 2px solid rgba(255,255,255,0.8); border-radius: 16px; object-fit: cover; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.5); z-index: 2;
}
#videoOverlay button {
    position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
    z-index: 100;
}
    .btn-icon {
    background: rgba(255, 255, 255, 0.05) !important; /* شیشه‌ای بسیار محو */
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
    width: 42px;
    height: 42px;
    border-radius: 50% !important; /* کاملاً گرد */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    cursor: pointer;
    padding: 0 !important;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.15) !important;
    transform: translateY(-2px);
    border-color: var(--primary) !important;
}

.btn-icon svg {
    width: 20px;
    height: 20px;
    stroke-width: 1.5; /* خطوط ظریف‌تر مثل عکس مرجع */
}
/* =========================================
   ریسپانسیو (موبایل) - حل قطعی مشکل کیبورد
========================================= */
@media (max-width: 768px) {
    /* قفل کردن مطلق بادی به ارتفاع واقعی مرورگر */
    body { 
        padding: 0; 
        gap: 0; 
        height: 100vh;
        height: var(--app-height, 100vh); 
        position: fixed; 
        top: 0; left: 0; right: 0; bottom: 0;
        overflow: hidden !important;
    }
    
    .sidebar, .chat-area { 
        width: 100%; border-radius: 0; border: none; height: 100%; 
    }
    
    .chat-area { 
        display: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 20; 
        flex-direction: column; background: var(--bg-glass); /* Ensure background covers */
    }
    body.chat-active .sidebar { display: none; }
    body.chat-active .chat-area { display: flex; animation: slideIn 0.3s ease; }
    .back-btn { display: block; color: #fff; }
    
    /* جلوگیری از فشرده شدن هدر و فوتر */
    .chat-header, .footer { flex-shrink: 0; }
    
    .footer { padding: 10px 15px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
    .input-wrapper { border-radius: 20px; padding: 4px 12px; }
    .btn-send { width: 40px; height: 40px; } /* Slightly smaller on mobile */

    /* فقط باکس پیام‌ها اسکرول می‌خورد */
    .messages { 
        flex-grow: 1; 
        overflow-y: auto; 
        -webkit-overflow-scrolling: touch; 
        padding: 15px;
    }

    .msg-wrapper { max-width: 90%; }
    
    /* لاگین موبایل */
    body.login-body { padding: 20px; position: static; height: auto; min-height: 100vh; }
    .login-glass { padding: 35px 25px; border-radius: 24px; width: 100%; max-width: 350px; margin: auto; }
    .login-glass h2 { font-size: 1.5rem; margin-bottom: 25px; }
    .input-group input { padding: 14px 45px 14px 15px; font-size: 0.9rem; }
    .login-glass .btn-submit { padding: 14px; font-size: 1rem; width: 100%; border-radius: 18px;} /* Ensure login button isn't affected by chat btn-send */

    /* ویدیو کال موبایل */
    #localVideo { width: 90px; bottom: 90px; right: 15px; }
    /* این کدها را داخل @media اضافه کن */
    #videoOverlay { z-index: 999999; background: #000; }
    .video-box { width: 100%; height: 100%; border-radius: 0; border: none; }
    #localVideo { width: 100px; bottom: 100px; right: 20px; }
    #videoOverlay button { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); z-index: 100; }
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/* افکت باز شدن منوی پیام */
.msg-menu { 
    transform-origin: top right;
    animation: menuPop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes menuPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.msg-menu div i { width: 20px; text-align: center; font-size: 1.1rem; }
#headerAvatarBox .user-avatar { width: 36px; height: 36px; font-size: 1rem; }
/* =========================================
   تنظیم شروع پیام‌ها از پایین (Bottom Alignment)
========================================= */
.messages::before {
    content: '';
    flex-grow: 1; /* این خط تمام فضای خالی را به بالا هل می‌دهد */
}

/* =========================================
   صفحه لودینگ (Loading Screen)
========================================= */
#app-loader {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-body); /* هم‌رنگ پس‌زمینه اصلی */
    z-index: 999999; display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s;
}
.spinner {
    width: 50px; height: 50px; 
    border: 4px solid rgba(74, 222, 128, 0.1);
    border-top-color: var(--primary); 
    border-radius: 50%;
    animation: spin 1s linear infinite; 
    margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: var(--text-muted); font-size: 1rem; font-weight: 400; letter-spacing: 1px;}
body.loaded #app-loader { opacity: 0; visibility: hidden; }
