@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
/* Variables - پالت رنگی تمیز و مدرن */
:root {
    --primary-color: #007bff; /* آبی روشن و دلنشین */
    --accent-color: #28a745; /* سبز برای بخش‌هایی مثل آنلاین */
    --bg-light: #ffffff;
    --bg-chat: #f5f7fb; /* پس زمینه چت روشن */
    --text-color: #333333;
    --text-dim: #6c757d; /* متن کمرنگ‌تر */
    --border-color: #e9ecef;
    --shadow-light: rgba(0, 0, 0, 0.08);
    --msg-sent-bg: #e0f2fe; /* حباب پیام ارسالی (آبی خیلی روشن) */
    --msg-received-bg: #ffffff; /* حباب پیام دریافتی (سفید) */
    --border-radius-main: 12px;
    --border-radius-msg: 18px;
    --transition-speed: 0.2s ease-in-out;
}

/* Dark Theme Variables */
body.dark-theme {
    --primary-color: #66b3ff; /* آبی روشن‌تر برای دارک مود */
    --accent-color: #4cd964;
    --bg-light: #1c2331; /* پس زمینه تاریک */
    --bg-chat: #28303f; /* پس زمینه چت تاریک‌تر */
    --text-color: #f8f9fa;
    --text-dim: #adb5bd;
    --border-color: #3e485e;
    --shadow-light: rgba(0, 0, 0, 0.3);
    --msg-sent-bg: #0056b3; /* حباب پیام ارسالی تاریک */
    --msg-received-bg: #3c4a63; /* حباب پیام دریافتی تاریک */
}

/* Base Styles */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    margin: 0;
    padding: 0;
    font-family: 'Vazirmatn', 'Vazir', Tahoma, sans-serif; /* فونت استاندارد و خوانا */
    background-color: var(--bg-light);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
    display: flex;
    flex-direction: column;
}

/* Scrollbar Style - تمیز و مینیمال */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}
body.dark-theme ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}
::-webkit-scrollbar-track {
    background: transparent;
}

/* Screen Transitions - انیمیشن ورود نرم صفحات */
.screen {
    display: none;
    height: 100%;
    flex-direction: column;
    opacity: 0;
    transform: translateY(10px);
    animation: fadeInSlideUp 0.3s forwards ease-out;
}
.active-screen {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}
@keyframes fadeInSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header - هدر تمیز و با سایه ملایم */
.header {
    background: var(--bg-light);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 5px var(--shadow-light);
    z-index: 10;
}
.header span, .header button {
    color: var(--text-color);
}

/* Connection Dot - نقطه وضعیت اتصال */
#server-connection-dot, #chat-server-connection-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #dc3545; /* قرمز برای قطع */
    margin-right: 8px;
    transition: background-color var(--transition-speed);
}
#server-connection-dot.connected, #chat-server-connection-dot.connected {
    background: var(--accent-color); /* سبز برای وصل */
}

/* Theme Toggle Button - دکمه تغییر تم */
.theme-toggle-btn {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 0;
    transition: transform 0.3s ease;
}
.theme-toggle-btn:hover {
    transform: rotate(30deg);
}

/* Logout Button */
#logout-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: var(--border-radius-main);
    cursor: pointer;
    font-size: 14px;
    transition: background-color var(--transition-speed);
}
#logout-btn:hover {
    background: #c82333;
}

/* Login Screen - صفحه ورود با طراحی مدرن و شیک */
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #007bff 0%, #00c6ff 100%); /* گرادینت ملایم آبی */
}
.login-box {
    background: var(--bg-light);
    padding: 40px;
    border-radius: var(--border-radius-main);
    box-shadow: 0 10px 30px var(--shadow-light);
    width: 90%;
    max-width: 350px;
    text-align: center;
    border: 1px solid var(--border-color);
}
.login-box h2 {
    color: var(--primary-color);
    margin-bottom: 25px;
    font-weight: 600;
}
.login-box input {
    width: 100%;
    padding: 12px 15px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-main);
    font-size: 16px;
    background: var(--bg-chat);
    color: var(--text-color);
    outline: none;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}
.login-box input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}
.login-box button {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: var(--border-radius-main);
    font-size: 16px;
    cursor: pointer;
    transition: background-color var(--transition-speed), transform 0.1s ease;
}
.login-box button:hover {
    background: #0056b3;
    transform: translateY(-2px);
}
#login-error {
    color: #dc3545;
    margin-top: 15px;
    font-size: 14px;
    display: none;
}

/* Tabs - مثل پنل ادمین، مینیمال و قرصی */
.tabs {
    display: inline-flex;
    gap: 8px;
    padding: 6px;
    margin: 12px 14px 10px;
    background: rgba(255,255,255,.76);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .06);
    align-self: stretch;
}
body.dark-theme .tabs { background: rgba(30, 41, 59, .72); }
.tab-btn {
    flex: 1;
    min-height: 42px;
    padding: 10px 14px;
    border: none;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 900;
    transition: .2s ease;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
.tab-btn::after { display: none; }
.tab-btn.active, .tab-btn:hover {
    color: #fff;
    background: var(--primary-color);
    box-shadow: 0 8px 20px rgba(0, 123, 255, .22);
}

/* Contact & Group List - لیست‌های تماس */
#personal-contacts, #groups-contacts, #tenkhah-contacts {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-light);
}
#contacts, #groupsList {
    list-style: none;
    padding: 0;
    margin: 0;
}
.contact-item, .group-item {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color var(--transition-speed);
    display: flex;
    align-items: center;
    gap: 15px;
}
.contact-item:hover, .group-item:hover {
    background-color: rgba(0, 123, 255, 0.05); /* هایلایت ملایم */
}
body.dark-theme .contact-item:hover, body.dark-theme .group-item:hover {
    background-color: rgba(102, 179, 255, 0.08);
}

.contact-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    font-weight: 600;
    font-size: 16px;
}
.contact-sub {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 5px;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cccccc; /* خاکستری برای آفلاین */
}
.contact-item.online .status-dot {
    background: var(--accent-color); /* سبز برای آنلاین */
}

/* Chat Screen */
/* ظرف اصلی چت */
#chat-screen {
    background-color: var(--bg-chat);
    position: relative; /* برای لایه‌بندی */
    overflow: hidden;
}

/* لایه قلبی پس‌زمینه حذف شد تا چت ظاهر ساده‌تر و تمیزتری داشته باشد. */
#chat-screen::before {
    content: none;
    display: none;
    background-image: none;
}


.back-btn {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    transform: rotate(180deg); /* فلش به سمت راست */
    transition: transform 0.2s ease-in-out;
}
.back-btn:hover {
    transform: rotate(180deg) translateX(3px);
}
#chat-username-title {
    font-weight: 600;
    font-size: 18px;
}
#chat-status {
    font-size: 12px;
    color: var(--text-dim);
}

/* Messages List - لیست پیام‌ها با ظاهر تلگرامی */
/* تنظیمات پس‌زمینه چت با الگوی تلگرامی */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    list-style: none;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2; /* این بخش باید بالاتر از لایه پس‌زمینه باشد */
    position: relative;
    background: transparent; /* کاملاً شفاف تا طرح زیر دیده شود */
}


/* در حالت تاریک هم الگوی اضافه روی پس‌زمینه چت نمایش داده نمی‌شود. */
body.dark-theme #messages {
    background-image: none;
}


/* برای اینکه حباب پیام‌ها روی الگو بهتر دیده بشن، کمی سایه اضافه می‌کنیم */
.msg {
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}


.msg {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: var(--border-radius-msg);
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); /* سایه ملایم */
    transition: transform 0.1s ease-out; /* انیمیشن پیام */
    transform-origin: bottom;
}
.msg.sent {
    background: var(--msg-sent-bg);
    color: var(--text-color);
    align-self: flex-start;
    border-bottom-right-radius: 4px; /* گوشه پایین راست تیز */
}
.msg.received {
    background: var(--msg-received-bg);
    color: var(--text-color);
    align-self: flex-end;
    border-bottom-left-radius: 4px; /* گوشه پایین چپ تیز */
}
.msg.pending {
    opacity: 0.7;
}

.msg-sender {
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 4px;
    opacity: 0.9;
    letter-spacing: 0.2px;
}
.msg-sender.other { color: var(--primary-color); }
.msg-sender.mine { color: var(--accent-color); }

.msg-replied-to {
    background-color: rgba(0, 0, 0, 0.05);
    border-right: 3px solid var(--primary-color);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-dim);
}
body.dark-theme .msg-replied-to {
    background-color: rgba(255, 255, 255, 0.1);
}

.msg-text {
    display: block;
    white-space: pre-line;
    line-height: 1.75;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 5px;
    gap: 5px;
}
.msg-ticks {
    font-size: 12px;
    letter-spacing: -1px;
    color: #999;
}
.msg-ticks.seen {
    color: var(--primary-color);
}
body.dark-theme .msg-ticks.seen {
    color: var(--primary-color);
}
.upload-progress {
    color: var(--primary-color);
    font-weight: bold;
    font-size: 11px;
    margin-right: 5px;
}
.msg-content img,
.msg img.chat-image {
    display: block;
    width: auto;
    max-width: min(230px, 70vw) !important;
    max-height: 280px;
    object-fit: cover;
    border-radius: 10px;
    margin-top: 5px; /* فاصله از متن */
    min-height: 0;
    background: #eee;
}
body.dark-theme .msg-content img,
body.dark-theme .msg img.chat-image {
    background: #444;
}

/* Reply Container - باکس ریپلای */
#reply-container {
    display: none;
    background: var(--bg-light);
    padding: 10px 20px;
    border-right: 4px solid var(--primary-color);
    font-size: 14px;
    position: relative;
    border-top: 1px solid var(--border-color);
    color: var(--text-color);
}
#reply-container .close-reply {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-weight: bold;
    color: var(--text-dim);
    font-size: 18px;
    transition: color 0.2s;
}
#reply-container .close-reply:hover {
    color: #dc3545;
}

/* Input Form - بخش ارسال پیام شیک */
#form {
    display: flex;
    padding: 10px 15px;
    background: var(--bg-light); /* مطمئن شو که پس‌زمینه رنگ دارد و شفاف نیست */
    align-items: center;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    flex-direction: column;
    
    /* این دو خط مشکل همپوشانی را حل می‌کنند */
    position: relative;
    z-index: 10; 
}

.input-row {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 10px;
    background: var(--bg-chat);
    border-radius: var(--border-radius-msg);
    padding: 5px;
    border: 1px solid var(--border-color);
}
#input {
    flex: 1;
    padding: 10px 15px;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: 16px;
    outline: none;
}
#form button {
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color var(--transition-speed), transform 0.1s ease;
}
#form button:hover {
    background: #0056b3;
    transform: scale(1.05);
}
.attach-btn {
    background: none;
    color: var(--text-dim);
    font-size: 24px;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: color 0.2s;
}
.attach-btn:hover {
    color: var(--primary-color);
}
#file-input {
    display: none;
}

/* V131 WhatsApp-style in-app voice recorder */
.voice-btn.recording {
    background: #dc3545 !important;
    color: #fff !important;
    animation: voicePulse 1s infinite;
}

.voice-recorder {
    display: none;
    width: 100%;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 8px;
    border: 1px solid rgba(220, 53, 69, 0.25);
    border-radius: 18px;
    background: rgba(220, 53, 69, 0.08);
    color: var(--text-color);
}

.voice-recorder.active {
    display: flex;
}

.voice-recorder.preview {
    border-color: rgba(0, 132, 255, 0.28);
    background: rgba(0, 132, 255, 0.08);
}

.voice-recorder.error {
    border-color: rgba(255, 193, 7, 0.4);
    background: rgba(255, 193, 7, 0.12);
}

.voice-recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #dc3545;
    flex: 0 0 10px;
    animation: voicePulse 1s infinite;
}

.voice-recorder.preview .voice-recording-dot,
.voice-recorder.error .voice-recording-dot {
    animation: none;
    background: var(--primary-color);
}

.voice-recorder.error .voice-recording-dot {
    background: #ffc107;
}

#voice-recording-time {
    direction: ltr;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    min-width: 48px;
    text-align: center;
    color: #dc3545;
}

.voice-recorder.preview #voice-recording-time {
    color: var(--primary-color);
}

.voice-recording-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    opacity: 0.9;
}

.voice-preview-audio {
    display: none;
    width: min(280px, 42vw);
    height: 38px;
    flex: 1 1 220px;
}

.voice-recorder.preview .voice-preview-audio {
    display: block;
}

#form .voice-recorder-action {
    width: auto;
    min-width: 44px;
    height: 34px;
    border-radius: 999px;
    padding: 0 12px;
    font-size: 13px;
    flex: 0 0 auto;
    transform: none;
}

#form .voice-cancel {
    background: transparent;
    color: #dc3545;
    border: 1px solid rgba(220, 53, 69, 0.35);
}

#form .voice-stop {
    background: #dc3545;
    color: #fff;
}

#form .voice-redo {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid rgba(0, 132, 255, 0.35);
}

#form .voice-send {
    background: var(--primary-color);
    color: #fff;
}

.voice-recorder .voice-redo,
.voice-recorder .voice-send,
.voice-recorder .voice-preview-audio {
    display: none;
}

.voice-recorder.preview .voice-redo,
.voice-recorder.preview .voice-send {
    display: inline-flex;
}

.voice-recorder.preview .voice-preview-audio {
    display: block;
}

.voice-recorder.preview .voice-stop,
.voice-recorder.error .voice-stop,
.voice-recorder.error .voice-redo,
.voice-recorder.error .voice-send,
.voice-recorder.error .voice-preview-audio {
    display: none;
}

.voice-message {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(320px, 100%);
    max-width: 100%;
}

.voice-message-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.08);
    flex: 0 0 34px;
}

.voice-message-info {
    font-size: 12px;
    opacity: 0.75;
    white-space: nowrap;
    flex: 0 0 auto;
}

.voice-message audio {
    width: 190px;
    max-width: 100%;
    height: 38px;
    flex: 1 1 auto;
}

@keyframes voicePulse {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.45); }
    70% { box-shadow: 0 0 0 8px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}


/* Mention Box */
#mention-box {
    position: absolute;
    bottom: 70px; /* بالای اینپوت قرار می‌گیرد */
    right: 15px;
    width: 250px;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-light);
    border-radius: var(--border-radius-main);
    box-shadow: 0 5px 15px var(--shadow-light);
    display: none;
    z-index: 999;
    border: 1px solid var(--border-color);
}
.mention-user {
    padding: 10px 15px;
    cursor: pointer;
    color: var(--text-color);
    font-size: 15px;
    transition: background-color var(--transition-speed);
}
.mention-user:hover {
    background: var(--bg-chat);
}
.group-mention-badge {
    color: var(--primary-color);
    font-weight: bold;
    margin-right: 8px;
    font-size: 16px;
}

/* Unread Badge */
.unread-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 8px;
    border-radius: 11px;
    background: var(--accent-color);
    color: #fff;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: auto;
    font-weight: 600;
}

/* Save Button (اگر در UI وجود دارد) */
.save-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(0,0,0,0.05);
    padding: 4px 10px;
    border-radius: 8px;
    transition: var(--transition-speed);
    font-size: 13px;
    color: var(--text-color);
}
.save-btn:hover {
    background: rgba(0,0,0,0.1);
    transform: translateY(-1px);
}
body.dark-theme .save-btn {
    background: rgba(255,255,255,0.1);
}
/* مخفی کردن محتوای تب‌ها به صورت پیش‌فرض */
#personal-contacts, #groups-contacts, #tenkhah-contacts {
    display: none; /* اول همه رو مخفی کن */
}

/* نمایش فقط تبی که کلاس active دارد */
#personal-contacts.active, #groups-contacts.active, #tenkhah-contacts.active {
    display: block; /* فقط اونی که فعاله رو نشون بده */
}

/* V121 Message actions / share modal */
.msg-actions-btn {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0 4px;
    opacity: 0.75;
}
.msg-actions-btn:hover { opacity: 1; }
.message-action-menu {
    position: fixed;
    z-index: 9999;
    min-width: 145px;
    background: var(--card-bg, #fff);
    color: var(--text-color, #222);
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18);
    overflow: hidden;
    direction: rtl;
}
.message-action-menu button {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    padding: 10px 12px;
    text-align: right;
    cursor: pointer;
    font-family: inherit;
}
.message-action-menu button:hover { background: rgba(0,0,0,0.08); }
.share-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.share-modal {
    width: min(420px, 96vw);
    max-height: 82vh;
    background: var(--card-bg, #fff);
    color: var(--text-color, #222);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    direction: rtl;
}
.share-modal-header, .share-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
}
.share-modal-footer { border-bottom: 0; border-top: 1px solid rgba(0,0,0,0.08); }
.share-modal-header button {
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 24px;
    cursor: pointer;
}
.share-preview {
    margin: 10px 14px;
    padding: 10px;
    border-radius: 10px;
    background: rgba(0,0,0,0.06);
    max-height: 80px;
    overflow: auto;
    font-size: 13px;
    white-space: pre-wrap;
}
.share-recipient-list {
    overflow: auto;
    padding: 4px 10px 10px;
}
.share-section-title {
    font-size: 12px;
    opacity: 0.7;
    padding: 10px 4px 6px;
}
.share-recipient-row {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    display: block;
    text-align: right;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
}
.share-recipient-row:hover,
.share-recipient-row.selected {
    background: rgba(0, 132, 255, 0.14);
}
.share-empty {
    font-size: 12px;
    opacity: 0.6;
    padding: 8px;
}
.share-send-btn {
    border: 0;
    border-radius: 10px;
    padding: 10px 18px;
    cursor: pointer;
    background: var(--primary-color, #0084ff);
    color: #fff;
    font-family: inherit;
}
.share-send-btn:disabled { opacity: 0.55; cursor: wait; }

/* V128 Mobile composer visibility fix + V129 voice recorder
   Fixes mobile browsers where 100vh/flex can push the message input out of view. */
html {
    height: 100%;
    min-height: 100%;
    overflow: hidden;
}

body {
    width: 100%;
    min-height: 100vh;
    min-height: 100svh;
    height: var(--app-height, 100dvh);
    overflow: hidden;
}

.screen,
#chat-screen,
#dashboard-screen,
#login-screen {
    width: 100%;
    min-height: 0;
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
    overflow: hidden;
}

#chat-screen.active-screen {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#chat-screen .header,
#reply-container,
.composer-shell,
#form {
    flex: 0 0 auto;
}

#messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
}

.composer-shell {
    position: relative;
    z-index: 30;
    background: var(--bg-light);
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 0px);
}

#form {
    width: 100%;
    position: relative;
    z-index: 31;
}

.input-row {
    min-height: 54px;
}

#input {
    min-width: 0;
}

@media (max-width: 640px) {
    .header {
        padding: 10px 12px;
        min-height: 56px;
    }

    #messages {
        padding: 10px;
    }

    #form {
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .input-row {
        gap: 6px;
        padding: 4px;
    }

    .attach-btn,
    #form button {
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
    }

    .voice-recorder {
        gap: 7px;
        padding: 7px 8px;
        margin-bottom: 6px;
    }

    .voice-recording-label {
        font-size: 12px;
    }

    #form .voice-recorder-action {
        height: 32px;
        min-width: 38px;
        padding: 0 10px;
    }

    .voice-message {
        width: min(280px, 100%);
    }

    .voice-message audio {
        width: 150px;
    }

    .msg img.chat-image,
    .msg-content img {
        max-width: min(200px, 66vw) !important;
        max-height: 240px;
    }

    #input {
        font-size: 16px;
        padding: 9px 10px;
    }

    #mention-box {
        bottom: 64px;
        right: 10px;
        width: min(280px, calc(100vw - 20px));
    }
}



/* V132 Global Vazir/Vazirmatn + minimal visual refresh */
*, button, input, select, textarea, audio, option {
    font-family: 'Vazirmatn', 'Vazir', Tahoma, sans-serif !important;
}

:root {
    --surface: rgba(255,255,255,0.86);
    --surface-strong: rgba(255,255,255,0.96);
    --soft-ring: 0 0 0 3px rgba(0, 123, 255, 0.13);
}
body.dark-theme {
    --surface: rgba(28,35,49,0.86);
    --surface-strong: rgba(28,35,49,0.96);
}

.header {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    background: var(--surface-strong);
}

.dashboard-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.profile-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-chat);
    color: var(--text-color);
    border-radius: 999px;
    padding: 6px 10px 6px 12px;
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.profile-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 22px var(--shadow-light);
    border-color: rgba(0, 123, 255, .38);
}
.profile-btn-text { font-weight: 700; font-size: 13px; }

.avatar {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #3b82f6, #22c55e);
    background-size: cover;
    background-position: center;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.28), 0 5px 14px rgba(0,0,0,.12);
    flex: 0 0 auto;
    user-select: none;
}
.avatar.has-image { color: transparent; }
.avatar-mini { width: 30px; height: 30px; min-width: 30px; font-size: 11px; }
.contact-avatar, .group-list-avatar { width: 46px; height: 46px; min-width: 46px; font-size: 15px; }
.chat-header-avatar { width: 42px; height: 42px; min-width: 42px; }
.msg-sender-avatar { width: 24px; height: 24px; min-width: 24px; font-size: 10px; box-shadow: none; }

.contact-item, .group-item {
    margin: 8px 10px;
    border-radius: 18px;
    border: 1px solid transparent;
    background: transparent;
}
.contact-item:hover, .group-item:hover {
    background: var(--surface);
    border-color: var(--border-color);
    box-shadow: 0 8px 26px var(--shadow-light);
}
.contact-info {
    flex: 1;
    min-width: 0;
}
.contact-top span:first-child,
.group-content b {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.group-list-avatar { background: linear-gradient(135deg, #6366f1, #06b6d4); }

.msg {
    border: 1px solid rgba(255,255,255,.28);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.msg-sender {
    display: flex;
    align-items: center;
    gap: 7px;
}

#form {
    background: var(--surface-strong);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}
.input-row {
    background: var(--surface);
    border-radius: 999px;
    padding: 6px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
#input::placeholder { color: var(--text-dim); }
#form button, .attach-btn {
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
}

/* Chat wallpaper presets */
body[data-chat-bg="default"] { --bg-chat: #f5f7fb; }
body[data-chat-bg="mint"] { --bg-chat: #e9f8f1; --msg-sent-bg: #d9fbe8; --msg-received-bg: #ffffff; }
body[data-chat-bg="sky"] { --bg-chat: #eaf5ff; --msg-sent-bg: #dbeafe; --msg-received-bg: #ffffff; }
body[data-chat-bg="lavender"] { --bg-chat: #f3efff; --msg-sent-bg: #ede9fe; --msg-received-bg: #ffffff; }
body[data-chat-bg="sand"] { --bg-chat: #fbf3e6; --msg-sent-bg: #ffedd5; --msg-received-bg: #ffffff; }
body[data-chat-bg="slate"] { --bg-chat: #18212f; --msg-sent-bg: #1f6feb; --msg-received-bg: #263247; }
body[data-chat-bg="slate"] #chat-screen { --text-color: #f8fafc; --text-dim: #cbd5e1; --border-color: #334155; }
body[data-chat-bg="doodle"] { --bg-chat: #eef8f3; --msg-sent-bg: #dcfce7; --msg-received-bg: rgba(255,255,255,.94); }
body.dark-theme[data-chat-bg="default"] { --bg-chat: #28303f; }
body.dark-theme[data-chat-bg="mint"] { --bg-chat: #12261d; --msg-sent-bg: #14532d; --msg-received-bg: #1f2937; }
body.dark-theme[data-chat-bg="sky"] { --bg-chat: #10243b; --msg-sent-bg: #1d4ed8; --msg-received-bg: #1f2937; }
body.dark-theme[data-chat-bg="lavender"] { --bg-chat: #211a34; --msg-sent-bg: #4c1d95; --msg-received-bg: #1f2937; }
body.dark-theme[data-chat-bg="sand"] { --bg-chat: #2d2416; --msg-sent-bg: #92400e; --msg-received-bg: #1f2937; }
body.dark-theme[data-chat-bg="slate"] { --bg-chat: #0f172a; --msg-sent-bg: #1e40af; --msg-received-bg: #1e293b; }
body.dark-theme[data-chat-bg="doodle"] { --bg-chat: #10251d; --msg-sent-bg: #166534; --msg-received-bg: #1f2937; }

/* Account modal */
body.modal-open { overflow: hidden; }
.account-modal-overlay[hidden] { display: none !important; }
.account-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    background: rgba(15, 23, 42, .52);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.account-modal {
    width: min(520px, 96vw);
    max-height: 88vh;
    overflow: auto;
    background: var(--bg-light);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    box-shadow: 0 24px 80px rgba(0,0,0,.28);
    padding: 18px;
}
.account-modal-header,
.account-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.account-modal-header h3 { margin: 0 0 4px; font-size: 22px; }
.account-modal-header p { margin: 0; color: var(--text-dim); font-size: 13px; }
.modal-close-btn {
    border: 0;
    background: var(--bg-chat);
    color: var(--text-color);
    border-radius: 50%;
    width: 42px;
    height: 42px;
    font-size: 26px;
    cursor: pointer;
}
.account-profile-card {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 18px 0;
    padding: 16px;
    border-radius: 22px;
    background: var(--bg-chat);
    border: 1px solid var(--border-color);
}
.profile-avatar-preview {
    width: 86px;
    height: 86px;
    min-width: 86px;
    border-radius: 50%;
    object-fit: cover;
    background: linear-gradient(135deg, #3b82f6, #22c55e);
    border: 4px solid rgba(255,255,255,.75);
    box-shadow: 0 10px 28px rgba(0,0,0,.16);
}
.profile-avatar-info { flex: 1; min-width: 0; }
.profile-avatar-info strong { display: block; font-size: 18px; margin-bottom: 3px; }
.profile-avatar-info span { color: var(--text-dim); font-size: 13px; }
.profile-avatar-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#profile-avatar-input { display: none; }
.profile-upload-btn,
.profile-light-btn,
.profile-save-btn {
    border: 0;
    border-radius: 999px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
}
.profile-upload-btn,
.profile-save-btn {
    background: var(--primary-color);
    color: #fff;
}
.profile-light-btn {
    background: var(--bg-chat);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}
.profile-save-btn:disabled { opacity: .6; cursor: wait; }
.wallpaper-section h4 { margin: 8px 0 12px; }
.wallpaper-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.wallpaper-choice {
    border: 1px solid var(--border-color);
    background: var(--bg-light);
    color: var(--text-color);
    border-radius: 18px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.wallpaper-choice:hover,
.wallpaper-choice.selected {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px var(--shadow-light);
    border-color: var(--primary-color);
}
.wallpaper-choice span {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: 1px solid rgba(0,0,0,.06);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.4);
}
.wallpaper-choice[data-bg="default"] span { background: #f5f7fb; }
.wallpaper-choice[data-bg="mint"] span { background: linear-gradient(135deg, #e9f8f1, #bbf7d0); }
.wallpaper-choice[data-bg="sky"] span { background: linear-gradient(135deg, #eaf5ff, #bfdbfe); }
.wallpaper-choice[data-bg="lavender"] span { background: linear-gradient(135deg, #f3efff, #ddd6fe); }
.wallpaper-choice[data-bg="sand"] span { background: linear-gradient(135deg, #fbf3e6, #fed7aa); }
.wallpaper-choice[data-bg="slate"] span { background: linear-gradient(135deg, #0f172a, #334155); }
.wallpaper-choice[data-bg="doodle"] span { background: radial-gradient(circle at 20% 20%, #22c55e 0 4px, transparent 5px), radial-gradient(circle at 70% 55%, #3b82f6 0 4px, transparent 5px), #eef8f3; }
.profile-status {
    min-height: 22px;
    margin: 12px 2px 4px;
    font-size: 13px;
    color: var(--text-dim);
}
.profile-status.success { color: #16a34a; }
.profile-status.error { color: #dc2626; }
.profile-status.loading { color: var(--primary-color); }

.account-security-section {
    margin: 18px 0 8px;
    padding: 16px;
    border-radius: 22px;
    background: var(--bg-chat);
    border: 1px solid var(--border-color);
}
.account-section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.account-section-head h4 { margin: 0 0 4px; }
.account-section-head p { margin: 0; color: var(--text-dim); font-size: 13px; line-height: 1.8; }
.account-password-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
.account-password-grid label {
    display: block;
    font-size: 13px;
    font-weight: 800;
    color: var(--text-dim);
}
.account-password-grid input {
    width: 100%;
    margin-top: 6px;
    padding: 12px 13px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-light);
    color: var(--text-color);
    direction: ltr;
    outline: none;
}
.account-password-grid input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}
.account-password-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}
#account-password-status {
    flex: 1;
    min-width: 180px;
    margin: 0;
}


@media (max-width: 640px) {
    .profile-btn-text { display: none; }
    .profile-btn { padding: 5px; }
    .account-modal { border-radius: 22px; padding: 14px; }
    .account-profile-card { align-items: flex-start; }
    .wallpaper-grid { grid-template-columns: 1fr; }
    .contact-item, .group-item { margin: 6px 8px; border-radius: 16px; }
    .contact-avatar, .group-list-avatar { width: 42px; height: 42px; min-width: 42px; }
}


/* Profile settings functional fix + group message avatars */
.msg.group-message {
    overflow: visible;
}
.msg-sender {
    display: flex;
    align-items: center;
    gap: 7px;
}
.msg-sender.mine {
    flex-direction: row-reverse;
}
.msg-sender-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,.10);
    border: 2px solid rgba(255,255,255,.65);
}
.profile-upload-btn,
.wallpaper-choice,
.profile-light-btn,
.profile-save-btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.wallpaper-choice.selected::after {
    content: '✓';
    margin-inline-start: auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: #fff;
    font-weight: 800;
}

/* Tenkhah composer/helper */
.tenkhah-template-btn {
    width: auto !important;
    min-width: 72px;
    border-radius: 999px !important;
    padding: 0 12px !important;
    font-size: 12px !important;
    font-weight: 900;
    background: linear-gradient(135deg, #16a34a, #22c55e) !important;
    color: #fff !important;
    white-space: nowrap;
}
.msg[data-tenkhah="true"], .tenkhah-card {
    border-color: rgba(34, 197, 94, .45) !important;
}
@media (max-width: 520px) {
    .tenkhah-template-btn { min-width: 58px; font-size: 11px !important; padding: 0 8px !important; }
}


.tenkhah-template-menu {
    position: fixed;
    z-index: 10080;
    direction: rtl;
    border: 1px solid rgba(148, 163, 184, .28);
    border-radius: 20px;
    padding: 12px;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 18px 45px rgba(15, 23, 42, .22);
    animation: tenkhahMenuPop .16s ease-out;
}
body.dark-theme .tenkhah-template-menu {
    background: rgba(15, 23, 42, .96);
    border-color: rgba(148, 163, 184, .22);
}
.tenkhah-template-menu-title {
    font-size: 12px;
    font-weight: 900;
    color: var(--text-dim);
    margin: 0 2px 10px;
    line-height: 1.6;
}
.tenkhah-template-menu-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.tenkhah-template-menu-btn {
    border: none;
    border-radius: 16px;
    min-height: 42px;
    padding: 9px 10px;
    cursor: pointer;
    font-family: inherit !important;
    font-size: 13px;
    font-weight: 950;
    color: #fff;
    box-shadow: 0 8px 20px rgba(15,23,42,.12);
    transition: transform .15s ease, filter .15s ease;
}
.tenkhah-template-menu-btn:hover { transform: translateY(-1px); filter: brightness(1.03); }
.tenkhah-template-menu-btn.withdraw { background: linear-gradient(135deg, #f97316, #ef4444); }
.tenkhah-template-menu-btn.deposit { background: linear-gradient(135deg, #16a34a, #22c55e); }
@keyframes tenkhahMenuPop {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (max-width: 520px) {
    .tenkhah-template-menu { border-radius: 18px; padding: 10px; }
    .tenkhah-template-menu-btn { min-height: 40px; font-size: 12px; }
}



/* Multi-line composer for Tenkhah templates */
.input-row textarea#input {
    flex: 1;
    min-width: 0;
    min-height: 42px;
    max-height: 130px;
    resize: none;
    overflow-y: auto;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-color);
    font-family: inherit !important;
    font-size: 15px;
    line-height: 1.7;
    padding: 9px 4px;
}
.input-row textarea#input::placeholder { color: var(--text-dim); }

/* Tenkhah management inside messenger */
.tenkhah-dashboard-panel {
    padding: 14px;
    overflow-y: auto;
    position: relative;
}
.tenkhah-dashboard-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    border-radius: 22px;
    background: rgba(255,255,255,.72);
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
}
body.dark-theme .tenkhah-dashboard-head { background: rgba(30,41,59,.70); }
.tenkhah-dashboard-head h3 { margin: 0 0 4px; font-size: 18px; }
.tenkhah-dashboard-head p { margin: 0; color: var(--text-dim); font-size: 12px; line-height: 1.8; }
.tenkhah-dashboard-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tenkhah-refresh-btn, .tenkhah-export-btn, .tenkhah-action-btn {
    border: none;
    border-radius: 999px;
    min-height: 36px;
    padding: 8px 13px;
    font-weight: 900;
    cursor: pointer;
    font-family: inherit !important;
    transition: .16s ease;
}
.tenkhah-refresh-btn { background: var(--primary-color); color: #fff; }
.tenkhah-export-btn { background: #16a34a; color: #fff; }
.tenkhah-refresh-btn:hover, .tenkhah-export-btn:hover, .tenkhah-action-btn:hover { transform: translateY(-1px); }
.tenkhah-stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.tenkhah-stat-card {
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: rgba(255,255,255,.74);
    padding: 10px;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 800;
}
body.dark-theme .tenkhah-stat-card { background: rgba(30,41,59,.72); }
.tenkhah-stat-card b { display: block; color: var(--text-color); font-size: 20px; margin-top: 4px; }
.tenkhah-management-status { min-height: 20px; margin: 4px 2px 10px; font-size: 12px; font-weight: 800; color: var(--text-dim); }
.tenkhah-management-status.error { color: #ef4444; }
.tenkhah-management-status.warning { color: #f59e0b; }
.tenkhah-management-status.success { color: #16a34a; }
.tenkhah-records-list { display: grid; gap: 12px; }
.tenkhah-record-card {
    background: rgba(255,255,255,.82);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 14px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .07);
}
body.dark-theme .tenkhah-record-card { background: rgba(30,41,59,.78); }
.tenkhah-record-header { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.tenkhah-record-header strong { display: block; direction: ltr; text-align: right; font-size: 13px; }
.tenkhah-record-header small { display: block; color: var(--text-dim); margin-top: 4px; line-height: 1.6; }
.tenkhah-status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 900;
    background: rgba(59,130,246,.12);
    color: #2563eb;
    white-space: nowrap;
}
.tenkhah-status-pill.approved { background: #dcfce7; color: #166534; }
.tenkhah-status-pill.rejected { background: #fee2e2; color: #991b1b; }
.tenkhah-status-pill.needs_revision { background: #fef3c7; color: #92400e; }
.tenkhah-status-pill.bank_attached { background: #e0f2fe; color: #075985; }
.tenkhah-record-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.tenkhah-field-row { border: 1px solid var(--border-color); border-radius: 14px; padding: 8px 10px; background: rgba(248,250,252,.62); }
body.dark-theme .tenkhah-field-row { background: rgba(15,23,42,.42); }
.tenkhah-field-row span { display: block; color: var(--text-dim); font-size: 11px; margin-bottom: 4px; }
.tenkhah-field-row b { display: block; font-size: 13px; line-height: 1.7; word-break: break-word; }
.tenkhah-file-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: #fff; background: #0ea5e9; border-radius: 999px; padding: 8px 12px; font-weight: 900; font-size: 12px; }
.tenkhah-history { border-top: 1px dashed var(--border-color); padding-top: 10px; margin-top: 8px; }
.tenkhah-history > strong { display: block; margin-bottom: 8px; font-size: 13px; }
.tenkhah-history-step { position: relative; padding: 8px 12px; border-radius: 14px; background: rgba(34,197,94,.08); margin-bottom: 7px; }
.tenkhah-history-step span { display: block; font-weight: 900; font-size: 12px; }
.tenkhah-history-step small { display: block; color: var(--text-dim); margin-top: 3px; font-size: 11px; }
.tenkhah-history-step p { margin: 6px 0 0; white-space: pre-line; line-height: 1.7; font-size: 12px; }
.tenkhah-history-empty { color: var(--text-dim); font-size: 12px; }
.tenkhah-record-actions, .tenkhah-message-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
.tenkhah-message-actions { border-top: 1px solid rgba(148,163,184,.25); padding-top: 8px; }
.tenkhah-action-btn.approve { background: #16a34a; color: #fff; }
.tenkhah-action-btn.revision { background: #f59e0b; color: #fff; }
.tenkhah-action-btn.reject { background: #ef4444; color: #fff; }
.tenkhah-action-btn.light { background: rgba(148,163,184,.18); color: var(--text-color); }
.tenkhah-action-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.45);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.tenkhah-action-modal {
    width: min(460px, 100%);
    background: var(--bg-light);
    color: var(--text-color);
    border-radius: 24px;
    padding: 18px;
    border: 1px solid var(--border-color);
    box-shadow: 0 24px 70px rgba(0,0,0,.24);
}
body.dark-theme .tenkhah-action-modal { background: #1e293b; }
.tenkhah-action-modal h3 { margin: 0 0 8px; }
.tenkhah-action-modal p { margin: 0 0 12px; color: var(--text-dim); line-height: 1.8; font-size: 13px; }
.tenkhah-action-modal textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 12px;
    resize: vertical;
    min-height: 120px;
    background: rgba(255,255,255,.75);
    color: var(--text-color);
    outline: none;
    font-family: inherit !important;
    line-height: 1.8;
}
body.dark-theme .tenkhah-action-modal textarea { background: rgba(15,23,42,.55); }
.tenkhah-action-modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
@media (max-width: 720px) {
    .tabs { margin-inline: 10px; overflow-x: auto; }
    .tab-btn { flex: 1 0 auto; font-size: 13px; }
    .tenkhah-dashboard-head { flex-direction: column; }
    .tenkhah-dashboard-actions { width: 100%; }
    .tenkhah-dashboard-actions button { flex: 1; }
    .tenkhah-stat-grid, .tenkhah-record-body { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .tenkhah-stat-grid, .tenkhah-record-body { grid-template-columns: 1fr; }
    .tenkhah-record-header { flex-direction: column; }
    .tenkhah-record-actions .tenkhah-action-btn, .tenkhah-message-actions .tenkhah-action-btn { flex: 1; }
}


/* Tenkhah V2: separate panel button and system notices */
.tenkhah-top-btn {
    background: linear-gradient(135deg, #16a34a, #22c55e) !important;
    color: #fff !important;
    box-shadow: 0 10px 24px rgba(22, 163, 74, .18);
}
.msg.system-generated {
    align-self: center !important;
    max-width: min(92%, 620px) !important;
    background: rgba(241, 245, 249, .92) !important;
    border: 1px dashed rgba(34, 197, 94, .38) !important;
    color: var(--text-color) !important;
    box-shadow: none !important;
    border-radius: 18px !important;
}
body.dark-theme .msg.system-generated {
    background: rgba(15, 23, 42, .72) !important;
}
.msg.kind-tenkhah_notice .msg-text::before,
.msg.kind-tenkhah_document .msg-text::before,
.msg.kind-tenkhah_source_document .msg-text::before,
.msg.kind-tenkhah_bank_print .msg-text::before {
    content: "اعلان تنخواه";
    display: inline-flex;
    margin: 0 0 8px 8px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(34, 197, 94, .14);
    color: #15803d;
    font-size: 11px;
    font-weight: 900;
}
.tenkhah-action-input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 11px 12px;
    margin-bottom: 10px;
    background: rgba(255,255,255,.75);
    color: var(--text-color);
    outline: none;
    font-family: inherit !important;
}
body.dark-theme .tenkhah-action-input { background: rgba(15,23,42,.55); }
@media (max-width: 520px) { .tenkhah-top-btn span { font-size: 12px; } }

.tenkhah-bank-upload-actions {
    border-top: 1px dashed rgba(34,197,94,.35);
    margin-top: 8px;
    padding-top: 8px;
}
.tenkhah-bank-upload-help {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(14,165,233,.12);
    color: #0369a1;
    font-size: 11px;
    font-weight: 900;
}
body.dark-theme .tenkhah-bank-upload-help { color:#7dd3fc; background:rgba(14,165,233,.16); }


/* Group profile, reply jump, attachment preview, drag/drop */
.chat-title-clickable { cursor: pointer; }
.chat-title-clickable:hover { opacity: .78; }
.group-profile-modal { max-width: 520px; }
.group-profile-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 22px;
    background: rgba(255, 255, 255, .72);
    margin-bottom: 16px;
}
.group-profile-avatar-preview {
    width: 84px;
    height: 84px;
    font-size: 28px;
    flex: 0 0 84px;
    background-size: cover;
    background-position: center;
}
.group-profile-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.group-profile-main strong { font-size: 18px; }
.group-profile-main span { color: var(--text-muted, #64748b); font-size: 13px; }
#group-photo-input { display: none; }
.group-members-section h4 { margin: 10px 0; }
.group-members-list { display: grid; gap: 8px; max-height: 330px; overflow: auto; padding-inline-end: 2px; }
.group-member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(248, 250, 252, .84);
    border: 1px solid rgba(15, 23, 42, .06);
}
.group-member-avatar { width: 38px; height: 38px; flex: 0 0 38px; font-size: 14px; }
.group-member-info { display: flex; flex-direction: column; min-width: 0; }
.group-member-info strong { font-size: 14px; }
.group-member-info span { direction: ltr; text-align: right; font-size: 12px; opacity: .65; }
.group-member-empty { padding: 18px; text-align: center; opacity: .65; }
.msg-replied-to.clickable-reply { cursor: pointer; }
.msg-replied-to.clickable-reply:hover { filter: brightness(.96); }
.jump-highlight { animation: jumpFlash 1.8s ease; }
@keyframes jumpFlash {
    0%, 100% { box-shadow: none; }
    20%, 70% { box-shadow: 0 0 0 4px rgba(59, 130, 246, .24), 0 8px 24px rgba(59,130,246,.2); }
}
.mention-highlight {
    color: #2563eb;
    font-weight: 800;
    background: rgba(37, 99, 235, .08);
    border-radius: 8px;
    padding: 0 3px;
}
.attachment-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 10px 8px;
    padding: 9px 10px;
    border-radius: 18px;
    background: rgba(255,255,255,.86);
    border: 1px solid rgba(15,23,42,.08);
    box-shadow: 0 8px 22px rgba(15,23,42,.07);
}
.attachment-preview[hidden] { display: none !important; }
.attachment-preview-media {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(226,232,240,.75);
    background-size: cover;
    background-position: center;
    flex: 0 0 46px;
}
.attachment-preview-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.attachment-preview-info strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-preview-info span { font-size: 11px; opacity: .62; }
.attachment-preview-cancel {
    border: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e2e8f0;
    cursor: pointer;
    font-weight: 800;
}
.drag-drop-overlay {
    position: absolute;
    inset: 10px;
    z-index: 20;
    border-radius: 24px;
    border: 2px dashed #3b82f6;
    background: rgba(219, 234, 254, .72);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    color: #1d4ed8;
    pointer-events: none;
}
.drag-drop-overlay[hidden] { display: none !important; }
.msg-text { white-space: pre-wrap; }


/* V134 - Image viewer, clean attachment button, send button on the right */
.msg img.chat-image {
    cursor: zoom-in;
}

.image-viewer-overlay[hidden] {
    display: none !important;
}

.image-viewer-overlay {
    position: fixed;
    inset: 0;
    z-index: 50000;
    background: rgba(2, 6, 23, 0.90);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 24px;
}

.image-viewer-overlay img {
    max-width: min(96vw, 1200px);
    max-height: 82vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 18px;
    box-shadow: 0 24px 80px rgba(0,0,0,.45);
    background: rgba(255,255,255,.04);
}

.image-viewer-close {
    position: fixed;
    top: max(18px, env(safe-area-inset-top, 0px));
    right: max(18px, env(safe-area-inset-right, 0px));
    width: 46px;
    height: 46px;
    border: 0;
    border-radius: 50%;
    background: rgba(255,255,255,.14);
    color: #fff;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .2s ease, transform .2s ease;
}

.image-viewer-close:hover {
    background: rgba(255,255,255,.24);
    transform: scale(1.05);
}

.image-viewer-caption {
    max-width: min(92vw, 900px);
    margin-top: 12px;
    color: rgba(255,255,255,.86);
    font-size: 13px;
    text-align: center;
    direction: rtl;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#form .input-row {
    direction: rtl;
}

#form .input-row button[type="submit"] {
    order: -30;
    flex: 0 0 44px;
}

#form .input-row #voice-btn {
    order: -20;
}

#form .input-row #input {
    order: 0;
    min-width: 0;
}

#form .input-row .attach-btn {
    order: 10;
}

#form .input-row #tenkhah-template-btn {
    order: 20;
}

.attach-btn,
#form .attach-btn,
.input-row .attach-btn {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    outline: none !important;
}

.attach-btn:hover,
#form .attach-btn:hover,
.input-row .attach-btn:hover {
    background: transparent !important;
    box-shadow: none !important;
}

@media (max-width: 520px) {
    .image-viewer-overlay {
        padding: 12px;
    }
    .image-viewer-overlay img {
        max-width: 98vw;
        max-height: 84vh;
        border-radius: 12px;
    }
    .image-viewer-close {
        width: 42px;
        height: 42px;
        font-size: 28px;
    }
    #form .input-row button[type="submit"] {
        flex-basis: 40px;
    }
}


/* V133 iPhone keyboard/chat viewport stability
   Prevents iOS browsers from panning the whole page to the top when the composer is focused. */
html, body {
    overscroll-behavior: none;
}

@supports (-webkit-touch-callout: none) {
    @media (max-width: 820px) {
        html,
        body {
            position: fixed;
            inset: 0;
            width: 100%;
            height: var(--app-height, 100dvh) !important;
            max-height: var(--app-height, 100dvh) !important;
            overflow: hidden !important;
        }

        body.mobile-keyboard-open {
            transform: translateY(var(--visual-viewport-offset-top, 0px));
        }

        #chat-screen.active-screen {
            height: var(--app-height, 100dvh) !important;
            max-height: var(--app-height, 100dvh) !important;
            overflow: hidden !important;
        }

        #messages {
            flex: 1 1 auto;
            min-height: 0;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            overscroll-behavior: contain;
        }

        .composer-shell,
        #form {
            flex-shrink: 0;
            transform: translateZ(0);
            -webkit-transform: translateZ(0);
        }
    }
}

/* V134 unread tab badges + desktop/mobile notification button */
.tab-btn.has-unread {
    padding-inline-end: 32px;
}
.tab-unread-badge {
    position: absolute;
    top: 4px;
    left: 10px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 6px 14px rgba(239, 68, 68, .28);
}
.notification-btn {
    min-width: 42px;
    justify-content: center;
    font-size: 18px;
}
.contact-item,
.group-item {
    position: relative;
}
.contact-item .unread-badge,
.group-item .unread-badge {
    margin-right: auto;
    flex: 0 0 auto;
    background: #ef4444;
    font-weight: 900;
}

/* V134 iPhone bottom composer tightening
   iOS normal Safari already excludes browser chrome from visualViewport; double safe-area padding made the composer float. */
.composer-shell {
    padding-bottom: 0 !important;
}
#form {
    padding-bottom: 6px !important;
}
@media (max-width: 640px) {
    #form {
        padding: 7px 8px 6px !important;
    }
    body.mobile-keyboard-open #form {
        padding-bottom: 4px !important;
    }
    body.mobile-keyboard-open .composer-shell {
        padding-bottom: 0 !important;
    }
}
@supports (-webkit-touch-callout: none) {
    @media (max-width: 820px) {
        .composer-shell {
            padding-bottom: 0 !important;
        }
        #form {
            padding-bottom: 5px !important;
        }
        body.mobile-keyboard-open #form {
            padding-bottom: 3px !important;
        }
        body.mobile-keyboard-open {
            transform: translateY(0) !important;
        }
    }
}

/* V135 stable numeric UX + iOS font stabilization */
html, body, button, input, select, textarea {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
.amount-cell,
.money-value,
.tenkhah-amount,
.tenkhah-record-card b,
.tenkhah-field-row b,
.tenkhah-stat-card b,
.balance-card b,
#tenkhah-entry-amount,
#tenkhah-action-amount,
#bank-amount {
    font-variant-numeric: tabular-nums;
    letter-spacing: .01em;
}
@supports (-webkit-touch-callout: none) {
    html, body,
    body *,
    button, input, select, textarea, option {
        font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Tahoma, Arial, sans-serif !important;
        -webkit-font-smoothing: antialiased;
        text-rendering: optimizeLegibility;
    }
    input, textarea, select {
        font-size: 16px !important;
    }
}
html.ios-device body,
html.ios-device body *,
html.ios-device button,
html.ios-device input,
html.ios-device select,
html.ios-device textarea,
html.ios-device option {
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Tahoma, Arial, sans-serif !important;
    -webkit-font-smoothing: antialiased;
}
.unread-badge,
.tab-unread-badge {
    direction: ltr;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif !important;
    font-variant-numeric: tabular-nums;
}


/* V136 iOS Persian shaping fix: never apply letter spacing to Persian/Arabic text on iPhone */
html.ios-device body,
html.ios-device body *,
html.ios-device button,
html.ios-device input,
html.ios-device textarea,
html.ios-device select {
    letter-spacing: normal !important;
    word-spacing: normal !important;
    font-kerning: normal;
    text-rendering: auto;
}
@supports (-webkit-touch-callout: none) {
    body, body *, button, input, textarea, select {
        letter-spacing: normal !important;
        word-spacing: normal !important;
        font-kerning: normal;
        text-rendering: auto;
    }
    .msg-text, .msg-sender, .msg-replied-to, .group-content, .contact-info, .chat-title, #messages {
        letter-spacing: normal !important;
        word-spacing: normal !important;
        unicode-bidi: plaintext;
    }
}
html.ios-device .msg-text,
html.ios-device .msg-sender,
html.ios-device .msg-replied-to,
html.ios-device .group-content,
html.ios-device .contact-info,
html.ios-device .chat-title,
html.ios-device #messages {
    letter-spacing: normal !important;
    word-spacing: normal !important;
    unicode-bidi: plaintext;
}

/* V137 admin/tenkhah quick navigation */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.header-quick-btn {
    border: 0;
    border-radius: 999px;
    background: #eef6f2;
    color: #0f766e;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .08);
}
.header-quick-btn:hover {
    transform: translateY(-1px);
}
#admin-panel-btn,
#chat-admin-panel-btn {
    background: #eff6ff;
    color: #1d4ed8;
}
#tenkhah-panel-btn,
#chat-tenkhah-panel-btn {
    background: #ecfdf5;
    color: #15803d;
}
@media (max-width: 720px) {
    .chat-header-actions {
        gap: 6px;
    }
    .header-quick-btn {
        padding: 7px 10px;
        font-size: 11px;
    }
}

/* V138 accessibility: keyboard focus visibility */
:where(button, a, input, textarea, select, [tabindex]):focus-visible {
    outline: 3px solid #2563eb !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 5px rgba(37, 99, 235, .16) !important;
}


/* V139 required password-change modal */
.password-change-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, .58);
    backdrop-filter: blur(10px);
}
.password-change-overlay[hidden] {
    display: none !important;
}
.password-change-card {
    width: min(440px, 100%);
    background: #fff;
    color: #111827;
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .22);
    direction: rtl;
}
.password-change-card h3 {
    margin: 0 0 8px;
    font-size: 20px;
}
.password-change-card p {
    margin: 0 0 18px;
    color: #64748b;
    line-height: 1.9;
    font-size: 14px;
}
.password-change-card label {
    display: block;
    margin: 12px 0 6px;
    font-weight: 800;
    font-size: 13px;
}
.password-change-card input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 15px;
    direction: ltr;
}
.password-change-message {
    min-height: 22px;
    margin-top: 12px;
    font-size: 13px;
    color: #dc2626;
}
.password-change-message.info { color: #2563eb; }
.password-change-message.success { color: #16a34a; }
.password-change-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}
.password-change-actions button {
    flex: 1;
    border: 0;
    border-radius: 14px;
    padding: 12px 14px;
    font-weight: 900;
    cursor: pointer;
}
#password-change-submit {
    background: #2563eb;
    color: #fff;
}
.password-change-secondary {
    background: #f1f5f9;
    color: #334155;
}
body.dark-theme .password-change-card {
    background: #0f172a;
    color: #f8fafc;
}
body.dark-theme .password-change-card p { color: #cbd5e1; }
body.dark-theme .password-change-card input {
    background: #111827;
    color: #f8fafc;
    border-color: #334155;
}
body.dark-theme .password-change-secondary {
    background: #1e293b;
    color: #e2e8f0;
}
