/* --- تم روشن (Light Mode) --- */
body.light-mode {
    --bg: #efeae2;           /* پس‌زمینه کرم روشن */
    --sec: #ffffff;           /* هدرها سفید */
    --text: #111b21;          /* متن مشکی */
    --border: #e9edef;        /* حاشیه روشن */
    --msg-in: #ffffff;        /* حباب پیام ورودی سفید */
    --msg-out: #d9fdd3;       /* حباب پیام خروجی سبز روشن */
    --input-bg: #ffffff;      /* پس‌زمینه اینپوت سفید */
}

/* اصلاح کوچک برای تم روشن */
body.light-mode .input-f {
    border: 1px solid #ccc; /* اضافه کردن مرز در تم روشن برای دیده شدن اینپوت */
}
:root {
	--primary: #00a884;
	--bg: #111b21;
	--sec: #202c33;
	--text: #e9edef;
	--msg-in: #202c33;
	--msg-out: #005c4b;
	}
* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	font-family: Vazir;
	}
/* بهینه برای لمس و موبایل: حذف تأخیر و هایلایت */
html {
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
	-webkit-text-size-adjust: 100%;
}
body {
	background: #000;
	height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
	overflow: hidden;
	color: var(--text);
	-webkit-overflow-scrolling: touch;
	}
button, .icon-btn, .btn, .chat-tab, .item {
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

.view {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	display: none;
	flex-direction: column;
	}
.view.active {
	display: flex;
	}

#view-auth {
	justify-content: center;
	align-items: center;
	background: var(--bg);
	z-index: 100;
	}
.auth-card {
	text-align: center;
	padding: 20px;
	width: 100%;
	max-width: 350px;
	}
.inp {
	width: 100%;
	padding: 10px;
	margin: 10px 0;
	background: var(--sec);
	border: 1px solid #333;
	border-radius: 5px;
	outline: none;
   color:#FFF;
	}
.light-mode .inp,.light-mode .input-f{
   color:#333!important;
}
.btn {
	width: 100%;
	padding: 10px;
	background: var(--primary);
	border: none;
	color: #fff;
	border-radius: 20px;
	cursor: pointer;
	margin-top: 10px;
	}

.app {
	display: flex;
	width: 100%;
	height: 100%;
	}
.sidebar {
	width: 30%;
	border-left: 1px solid #333;
	background: var(--bg);
	display: flex;
	flex-direction: column;
	}
.header {
	padding: 10px 15px;
	background: var(--sec);
	display: flex;
	justify-content: space-between;
	align-items: center;
	height: 60px;
	}
.avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	cursor: pointer;
	}
.list {
	flex: 1;
	overflow-y: auto;
	}
.item {
	display: flex;
	padding: 10px;
	cursor: pointer;
	border-bottom: 1px solid rgba(0,0,0,0.1);
	}
.item:hover {
	background: var(--sec);
	}
.item.active {
	background: #2a3942;
	}

/* تمایز ظاهری چت گروهی و خصوصی در لیست */
.item-group .avatar {
    border: 2px solid #00a884; /* حلقه سبز برای گروه‌ها */
}
.item-private .avatar {
    border: 2px solid transparent;
}
.item-type-pill {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(134,150,160,0.2);
    color: #8696a0;
    margin-right: 6px;
}

/* چت با پیام جدید (نوتیف شبیه واتساپ ساده) */
.item.unread {
    font-weight: bold;
}
.item-unread-dot {
    margin-right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #25d366;
    display: inline-block;
}

/* تب‌های فیلتر لیست چت‌ها */
.chat-tabs {
    display: flex;
    background: var(--sec);
    border-bottom: 1px solid #333;
}
.chat-tab {
    flex: 1;
    text-align: center;
    padding: 8px 4px;
    font-size: 0.8rem;
    cursor: pointer;
    color: #8696a0;
    border-bottom: 2px solid transparent;
}
.chat-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: bold;
}

.chat-area {
	flex: 1;
	display: flex;
	flex-direction: column;
	background: var(--bg);
	}
.msgs {
	flex: 1;
	overflow-y: auto;
	padding: 20px;
	display: flex;
	flex-direction: column;
	gap: 5px;
	background-image: url('../images/message.png');
	background-blend-mode: soft-light;
	position: relative;
	}
.msg {
	max-width: 60%;
	padding: 8px 12px;
	border-radius: 7px;
	font-size: 0.95rem;
	position: relative;
	word-wrap: break-word;
	}
.msg-in {
	align-self: flex-start;
	background: var(--msg-in);
	}
.msg-out {
	align-self: flex-end;
	background: var(--msg-out);
	}

.footer {
	padding: 10px;
	background: var(--sec);
	display: flex;
	align-items: center;
	gap: 10px;
	position: relative;
	}
.input-f {
	flex: 1;
	padding: 10px;
	background: var(--bg);
	border: none;
	border-radius: 5px;
	outline: none;
   color:#FFF;
	}
.icon-btn {
	font-size: 1.2rem;
	cursor: pointer;
	color: #8696a0;
	}
.icon-btn:hover {
	color: var(--text);
	}

.popup {
	position: absolute;
	bottom: 70px;
	right: 10px;
	background: var(--sec);
	padding: 5px;
	border-radius: 5px;
	display: none;
	flex-direction: column;
	min-width: 150px;
	box-shadow: 0 2px 10px rgba(0,0,0,0.1);
	}
.popup-item {
	padding: 8px 12px;
	cursor: pointer;
	font-size: 0.9rem;
	}
.popup-item:hover {
	background: var(--bg);
	}

.context-menu {
	position: fixed;
	z-index: 9999;
	min-width: 140px;
	background: var(--surface);
	border-radius: 8px;
	box-shadow: 0 4px 20px rgba(0,0,0,0.25);
	padding: 6px 0;
	list-style: none;
	margin: 0;
}
.context-menu-item {
	display: block;
	width: 100%;
	padding: 8px 14px;
	text-align: right;
	font-size: 0.9rem;
	color: var(--text);
	background: none;
	border: none;
	cursor: pointer;
}
.context-menu-item:hover {
	background: var(--bg);
}

.show {
	display: flex;
	}

#toast {
	position: absolute;
	bottom: 80px;
	left: 50%;
	transform: translateX(-50%);
	background: rgba(0,0,0,0.8);
	color: #fff;
	padding: 8px 16px;
	border-radius: 4px;
	opacity: 0;
	transition: 0.3s;
	pointer-events: none;
	}
#toast.show {
	opacity: 1;
	}

/* ========== بهینه‌سازی موبایل ========== */
@media (max-width: 768px) {
    html, body {
        background: var(--bg);
        height: 100%;
        min-height: 100vh;
        min-height: 100dvh;
        overflow-x: hidden;
    }
    body {
        justify-content: flex-start;
        align-items: stretch;
        overflow: hidden;
    }

    .view {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        min-height: 0;
    }

    .app {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        min-height: 0;
        overflow: hidden;
    }

    /* سایدبار */
    .sidebar {
        width: 100%;
        height: 100%;
        min-height: 0;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
    }
    .sidebar .header {
        min-height: 56px;
        padding: 8px 12px;
        padding-top: max(8px, env(safe-area-inset-top));
        flex-wrap: wrap;
        gap: 4px;
    }
    .sidebar .header .avatar {
        width: 44px;
        height: 44px;
    }
    .sidebar .header > div {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 2px;
    }
    .sidebar .icon-btn {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 10px;
        font-size: 1.1rem;
    }
    .sidebar .list {
        -webkit-overflow-scrolling: touch;
    }
    .sidebar .item {
        min-height: 64px;
        padding: 12px 14px;
        align-items: center;
    }
    .sidebar .item .avatar {
        width: 48px;
        height: 48px;
        flex-shrink: 0;
    }
    .chat-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .chat-tabs::-webkit-scrollbar {
        display: none;
    }
    .chat-tab {
        min-width: 80px;
        padding: 10px 8px;
        font-size: 0.8rem;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .sidebar.hide {
        transform: translateX(-100%);
    }

    /* ناحیه چت */
    .chat-area {
        width: 100%;
        height: 100%;
        min-height: 0;
        transform: translateX(100%);
        transition: transform 0.25s ease-out;
        position: absolute;
        z-index: 20;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    .chat-area.open {
        transform: translateX(0);
    }
    .chat-area .header {
        flex-shrink: 0;
        min-height: 56px;
        padding: 10px 12px;
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-top: max(10px, env(safe-area-inset-top));
    }
    .chat-area .header .icon-btn {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 10px;
    }
    .chat-area .header #backBtn {
        min-width: 44px;
        min-height: 44px;
    }
    .chat-area .header #chatName {
        font-size: 1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .chat-area .msgs {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overflow-x: hidden;
        padding: 12px 10px;
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
    .chat-area .msg {
        max-width: 85%;
        padding: 10px 12px;
        font-size: 1rem;
    }
    .msg-sender-name { font-size: 0.8rem; }
    .msg-action-btn {
        min-width: 36px;
        min-height: 36px;
        padding: 6px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .msg:hover .msg-opts { opacity: 1; }

    /* فوتر ورودی پیام */
    #chatFooter,
    .chat-area .footer {
        flex-shrink: 0;
        padding: 10px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        gap: 8px;
    }
    #chatFooter .icon-btn,
    .chat-area .footer .icon-btn {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    #chatFooter .input-f,
    .chat-area .footer .input-f {
        min-height: 44px;
        padding: 12px 14px;
        font-size: 16px;
    }
    #sendBtn {
        display: inline-flex !important;
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
    }

    /* بنر ریپلی */
    #replyBanner {
        padding: 10px 12px;
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        font-size: 0.85rem;
    }

    /* نوتیف */
    #toast {
        bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
        left: 50%;
        transform: translateX(-50%);
        max-width: 90%;
    }

    /* صفحه ورود */
    #view-auth {
        padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
    }
    .auth-card {
        padding: 24px 20px;
        max-width: 100%;
    }
    .auth-card .inp {
        min-height: 48px;
        padding: 14px 16px;
        font-size: 16px;
    }
    .auth-card .btn {
        min-height: 48px;
        padding: 14px;
    }

    /* مودال‌ها */
    #forwardModal {
        position: fixed;
        z-index: 9999;
        padding: 16px;
    }
    #forwardList {
        max-height: 70vh;
        width: 100%;
        max-width: 320px;
    }
    #groupInfoModal {
        padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
    }
    #groupInfoModal .modal-content {
        max-height: 85vh;
        width: 100%;
    }
    #groupInfoModal button {
        min-height: 44px;
        padding: 10px 16px;
    }

    /* تماس */
    .call-modal-content {
        padding: 24px 20px;
        max-width: 100%;
    }
    .call-btn {
        width: 60px;
        height: 60px;
        font-size: 1.3rem;
    }
    .call-btn.hangup {
        width: 64px;
        height: 64px;
    }
    .call-videos video {
        max-width: 100%;
        width: 100%;
    }

    /* لودینگ */
    .global-loader-content {
        padding: 24px 28px;
    }

    /* نمایش بیشتر */
    .load-more-btn {
        min-height: 44px;
        padding: 12px 24px;
    }
    .load-more-wrap {
        padding: 14px;
    }

    /* پاپ‌آپ پیوست و ایموجی */
    .popup {
        bottom: 60px;
        right: 8px;
        left: 8px;
        min-width: auto;
    }
    .popup-item {
        min-height: 44px;
        padding: 12px 14px;
        display: flex;
        align-items: center;
    }
    .emoji-grid {
        width: 100%;
        max-width: 320px;
        max-height: 240px;
    }
    .emoji-item {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* گوشی‌های خیلی کوچک */
@media (max-width: 380px) {
    .sidebar .header > div .icon-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
    }
    .chat-tab {
        min-width: 72px;
        font-size: 0.75rem;
    }
    .chat-area .msg {
        max-width: 92%;
    }
    .auth-card .inp,
    .auth-card .btn {
        min-height: 44px;
    }
}
/* اضافه کنید به استایل‌ها */
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    width: 300px;
    height: 200px;
    overflow-y: auto;
    bottom: 70px;
    right: 10px;
    background: var(--sec);
    padding: 5px;
    border-radius: 5px;
}

.emoji-item {
    text-align: center;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 5px;
}

.emoji-item:hover {
    background: rgba(255,255,255,0.1);
}
/* استایل حالت خالی */
.empty-state {
    display: flex; /* پیش‌فرض نمایش داده شود */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    background-color: var(--bg);
    background-image: url('../images/background.png');
    background-repeat: repeat;
    background-blend-mode: soft-light;
    position: absolute; /* روی همه چیز قرار می‌گیرد */
    top: 0;
    left: 0;
    width: 100%;
    z-index: 20; /* بالاتر از پیام‌ها */
    border-bottom: 6px solid var(--primary);
    transition: opacity 0.3s ease;
}

/* کلاس مخفی برای استفاده در جاوا اسکریپت */
.hidden {
    display: none !important;
}
/* منوی پیام */
.msg-opts {
    position: absolute;
    top: 5px;
    left: 5px;
    color: #8696a0;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 5px;
    opacity: 0;
    transition: 0.2s;
}
.msg:hover .msg-opts { opacity: 1; }
.msg-opts:hover { color: var(--text-main); }

/* نام فرستنده و دکمه‌های پاسخ/فوروارد */
.msg-sender-name {
    font-size: 0.75rem;
    color: var(--primary);
    margin-bottom: 4px;
    font-weight: bold;
}
.msg-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
    clear: both;
}
.msg-time {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
}
.msg-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}
.msg-action-btn {
    cursor: pointer;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.6);
    padding: 2px 4px;
}
.msg-action-btn:hover {
    color: var(--primary);
}
.msg-forwarded-label {
    font-size: 0.7rem;
    color: #eab308;
    margin-bottom: 3px;
}
.msg-reply-context {
    border-right: 3px solid #41525d;
    padding-right: 8px;
    margin-bottom: 4px;
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
}
.msg-out .msg-reply-context.msg-reply-out {
    border-right-color: #128c7e;
}
body.light-mode .msg-time,
body.light-mode .msg-action-btn {
    color: rgba(0,0,0,0.5);
}
body.light-mode .msg-action-btn:hover {
    color: var(--primary);
}
body.light-mode .msg-reply-context {
    color: rgba(0,0,0,0.6);
}

/* دکمه نمایش بیشتر پیام‌ها */
.load-more-wrap {
    text-align: center;
    padding: 12px;
    flex-shrink: 0;
}
.load-more-btn {
    padding: 8px 20px;
    background: var(--sec);
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
}
.load-more-btn:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
}
.load-more-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}
body.light-mode .load-more-btn {
    background: #fff;
    border-color: var(--primary);
    color: var(--primary);
}
body.light-mode .load-more-btn:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
}

/* بنر ریپلی بالای اینپوت */
#replyBanner {
    display: none; /* پیش‌فرض مخفی */
    background: var(--sec);
    padding: 8px 10px;
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    justify-content: space-between;
    align-items: center;
    color: var(--primary);
}
#replyBanner span { color: var(--text-main); margin-right: 10px; }

/* مودال فوروارد */
#forwardModal {
    display: none;
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    justify-content: center;
    align-items: center;
}
#forwardList {
    background: var(--bg);
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
    border-radius: 8px;
}

/* مودال اطلاعات گروه - نمایش روی همه چیز */
#groupInfoModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}
#groupInfoModal .modal-content {
    background: var(--sec);
    color: var(--text);
    width: 90%;
    max-width: 400px;
    border-radius: 8px;
    padding: 15px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
#groupInfoModal h3 { margin-bottom: 10px; }
#groupInfoModal label { font-size: 0.85rem; display: block; margin-top: 10px; }
#groupInfoModal input[type="text"] {
    width: 100%;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #333;
    margin-top: 4px;
    background: var(--bg);
    color: var(--text);
}
#groupInfoModal .row { margin-top: 10px; display: flex; align-items: center; gap: 8px; }
#groupInfoModal .members { margin-top: 10px; font-size: 0.85rem; }
#groupInfoModal .members div { padding: 4px 0; border-bottom: 1px solid rgba(0,0,0,0.2); }
#groupInfoModal .btn-row { margin-top: 15px; display: flex; justify-content: flex-end; gap: 8px; }
#groupInfoModal button { padding: 6px 12px; border-radius: 4px; border: none; cursor: pointer; }
#groupInfoModal .btn-primary { background: var(--primary); color: #fff; }
#groupInfoModal .btn-secondary { background: #444; color: #fff; }

/* مودال تماس صوتی/تصویری - z-index بالا برای نمایش روی سافاری موبایل */
.call-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background: rgba(0,0,0,0.95);
    z-index: 2147483647;
    justify-content: center;
    align-items: center;
    -webkit-overflow-scrolling: touch;
    overflow: auto;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}
.call-modal.call-modal-visible {
    display: flex !important;
}
.call-modal-content {
    text-align: center;
    color: #fff;
    padding: 20px;
}
.call-modal p {
    margin: 15px 0;
    font-size: 1.1rem;
}
.call-btn-row {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}
.call-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    cursor: pointer;
    font-size: 1.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.call-btn.reject {
    background: #ef5350;
    color: #fff;
}
.call-btn.accept {
    background: #00a884;
    color: #fff;
}
.call-videos {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 20px;
    max-width: 100%;
}
.call-videos video {
    width: 200px;
    max-width: 45%;
    border-radius: 8px;
    background: #222;
}
.call-videos #callLocalVideo {
    transform: scaleX(-1);
}
.call-btn.hangup {
    width: 64px;
    height: 64px;
    font-size: 1.5rem;
}

/* لودینگ سراسری */
.global-loader {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
}
.global-loader-content {
    background: var(--sec);
    border-radius: 16px;
    padding: 28px 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.global-loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: globalLoaderSpin 0.9s linear infinite;
}
.global-loader-text {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text);
}
@keyframes globalLoaderSpin {
    to { transform: rotate(360deg); }
}