/* ========================================
   پیام‌رسان فارسی - استایل‌ها
   نسخه 3.3 - ریسپانسیو کامل
   ======================================== */

@font-face {
    font-family: 'Vazirmatn';
    src: url('vazirmatn.woff2') format('woff2');
    font-weight: 100 900;
    font-display: swap;
}

/* اطمینان از اعمال فونت روی کل بادی */
body {
    font-family: 'Vazirmatn', sans-serif !important;
}

* {
    font-family: 'Vazirmatn', sans-serif;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-primary: #0e1621;
    --bg-secondary: #17212b;
    --bg-tertiary: #232e3c;
    --accent: #8774e1;
    --accent-dark: #6c5ce7;
    --text-primary: #ffffff;
    --text-secondary: #8b9eb0;
    --border-color: #2b3e50;
    --message-sent: linear-gradient(135deg, #2b5278 0%, #1e3a52 100%);
    --message-received: linear-gradient(135deg, #182533 0%, #1a2836 100%);
    --online-color: #4caf50;
    --unread-color: #8774e1;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    touch-action: manipulation;
}

/* ========================================
   صفحه ورود / ثبت‌نام
   ======================================== */

.auth-container {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0e1621 0%, #1a1a2e 50%, #16213e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.auth-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%238774e1' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    opacity: 0.5;
}

.auth-box {
    background: var(--bg-secondary);
    border-radius: 1.25rem;
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 1;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.auth-logo {
    width: 90px;
    height: 90px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 30px rgba(135, 116, 225, 0.3);
    animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 10px 30px rgba(135, 116, 225, 0.3); }
    50% { box-shadow: 0 10px 40px rgba(135, 116, 225, 0.5); }
}

.auth-logo svg {
    width: 45px;
    height: 45px;
    fill: white;
}

.auth-title {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.auth-input {
    width: 100%;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.875rem 1rem;
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.auth-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(135, 116, 225, 0.2);
}

.auth-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border: none;
    border-radius: 0.75rem;
    padding: 0.875rem;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(135, 116, 225, 0.4);
}

.auth-btn:active {
    transform: translateY(0);
}

.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
}

.auth-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.5);
    color: #f87171;
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    text-align: center;
    font-size: 0.9rem;
    display: none;
}

/* ========================================
   لایه اصلی
   ======================================== */

.app-container {
    display: none;
    height: 100%;
    height: 100dvh;
}

.app-container.active {
    display: flex;
}

/* ========================================
   سایدبار
   ======================================== */

.sidebar {
    width: 320px;
    min-width: 320px;
    max-width: 320px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    height: 100%;
    overflow: hidden;
}

.sidebar-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    position: relative;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.chat-item.active {
    background: rgba(135, 116, 225, 0.15);
}

.chat-avatar {
    width: 50px;
    height: 50px;
    min-width: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 600;
    position: relative;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: var(--online-color);
    border: 3px solid var(--bg-secondary);
    border-radius: 50%;
}

.chat-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-info-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.chat-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-right: 0.5rem;
}

.chat-info-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.badges-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-preview.typing {
    color: var(--accent);
}

.unread-badge {
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    font-weight: 600;
}

.mention-badge-icon {
    background: #ef4444; /* رنگ قرمز برای منشن */
    color: white;
    font-size: 0.85rem;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(239, 68, 68, 0.4);
    animation: pulse-mention 2s infinite;
}

@keyframes pulse-mention {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.unread-badge.mention {
    background: #ef4444;
}

/* ========================================
   ناحیه چت
   ======================================== */

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%231a2836' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    height: 100%;
    overflow: hidden;
    position: relative;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    padding: 2rem;
}

.empty-state svg {
    width: 120px;
    height: 120px;
    opacity: 0.2;
    margin-bottom: 1.5rem;
}

.empty-state p {
    font-size: 1.1rem;
}

.chat-header {
    background: var(--bg-secondary);
    padding: 0.625rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    min-height: 60px;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 0.5rem;
    margin-left: -0.5rem;
}

.back-btn:hover {
    background: var(--bg-tertiary);
}

.back-btn svg {
    width: 24px;
    height: 24px;
}

.chat-header-avatar {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 600;
    overflow: hidden;
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-text {
    flex: 1;
    min-width: 0;
}

.chat-header-text h3 {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.chat-header-status.online {
    color: var(--online-color);
}

.chat-header-status.typing {
    color: var(--accent);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    scroll-behavior: smooth;
}

/* دکمه‌های شناور */
.floating-buttons {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    z-index: 50;
}

.scroll-btn {
    background: var(--bg-tertiary);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    transform: scale(0);
    opacity: 0;
}

.scroll-btn.visible {
    transform: scale(1);
    opacity: 1;
}

.scroll-btn:hover {
    background: var(--accent);
}

.scroll-btn svg {
    width: 22px;
    height: 22px;
}

.scroll-btn .badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--accent);
    color: white;
    font-size: 0.65rem;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    font-weight: 600;
}

.scroll-btn .badge.mention {
    background: #ef4444;
}

/* پیام */
.message {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    max-width: 75%;
    animation: messageIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: pan-y;
    position: relative;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.sent {
    align-self: flex-start;
    flex-direction: row;
}

.message.received {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    overflow: hidden;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message.received .message-avatar {
    display: none;
}

.message-bubble {
    padding: 0.5rem 0.75rem;
    border-radius: 1rem;
    position: relative;
    cursor: pointer;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-width: 80px;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.message.sent .message-bubble {
    background: var(--message-sent);
    border-bottom-right-radius: 0.25rem;
}

.message.received .message-bubble {
    background: var(--message-received);
    border-bottom-left-radius: 0.25rem;
}

.message-sender {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.message-text {
    line-height: 1.5;
    white-space: pre-wrap;
    font-size: 0.95rem;
}

.message-text .mention {
    color: var(--accent);
    font-weight: 500;
    cursor: pointer;
    background: rgba(135, 116, 225, 0.2);
    padding: 0 0.25rem;
    border-radius: 0.25rem;
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

.message-time {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
}

.message-status {
    width: 16px;
    height: 16px;
    color: rgba(255, 255, 255, 0.5);
    transition: color 0.3s;
}

.message-status.read {
    color: #4fc3f7;
}

.reply-preview {
    border-right: 3px solid var(--accent);
    background: rgba(135, 116, 225, 0.15);
    padding: 0.375rem 0.5rem;
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
}

.reply-preview:hover {
    background: rgba(135, 116, 225, 0.25);
}

.reply-preview-name {
    color: var(--accent);
    font-weight: 600;
}

.reply-preview-text {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.forward-badge {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.forward-badge svg {
    width: 12px;
    height: 12px;
}

.forward-from {
    color: var(--accent);
    font-weight: 500;
}

.message-reactions-container {
    min-height: 0;
}

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.375rem;
}

.reaction-bubble {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    padding: 0.125rem 0.5rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.reaction-bubble:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.reaction-bubble.mine {
    border-color: var(--accent);
}

.reaction-count {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* مدیا */
.message-media {
    margin: 0.25rem 0;
    border-radius: 0.5rem;
    overflow: hidden;
    max-width: 300px;
}

.message-media img {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    cursor: pointer;
    display: block;
    transition: transform 0.2s;
    background: rgba(0,0,0,0.2);
}

.message-media img:hover {
    transform: scale(1.02);
}

.message-media video {
    width: 100%;
    max-height: 300px;
    display: block;
    background: #000;
}

.message-media.gif {
    position: relative;
}

.message-media.gif::after {
    content: 'GIF';
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.6);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.message-media.gif video {
    max-height: 200px;
}

/* فایل */
.message-file {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.75rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: inherit;
    min-width: 200px;
    transition: background 0.2s;
}

.message-file:hover {
    background: rgba(0, 0, 0, 0.3);
}

.file-icon {
    width: 44px;
    height: 44px;
    background: var(--accent);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9rem;
}

.file-size {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* موزیک */
.music-message {
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.75rem;
    border-radius: 0.75rem;
    min-width: 240px;
    max-width: 300px;
}

.music-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.music-cover {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.music-cover svg {
    width: 24px;
    height: 24px;
    color: white;
}

.music-info {
    flex: 1;
    min-width: 0;
}

.music-title {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.music-artist {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.music-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.music-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #22c55e;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, background 0.2s;
}

.music-play-btn:hover {
    transform: scale(1.1);
    background: #16a34a;
}

.music-play-btn svg {
    width: 18px;
    height: 18px;
}

.music-progress-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.music-progress {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.music-progress-bar {
    height: 100%;
    background: #22c55e;
    width: 0%;
    transition: width 0.1s;
    border-radius: 3px;
}

.music-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ویس */
.voice-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 200px;
    max-width: 280px;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 1.5rem;
}

.voice-play-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, background 0.2s;
}

.voice-play-btn:hover {
    transform: scale(1.1);
    background: var(--accent-dark);
}

.voice-play-btn:active {
    transform: scale(0.95);
}

.voice-play-btn svg {
    width: 20px;
    height: 20px;
}

.voice-content {
    flex: 1;
    min-width: 0;
}

.voice-waveform {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 28px;
    margin-bottom: 4px;
    cursor: pointer;
}

.voice-bar {
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    transition: height 0.15s, opacity 0.15s;
    opacity: 0.5;
}

.voice-bar.active {
    opacity: 1;
}

.voice-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ========================================
   ناحیه ورودی
   ======================================== */

.input-area {
    background: var(--bg-secondary);
    padding: 0.625rem 1rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-area.disabled {
    display: none;
}

.reply-bar {
    display: none;
    background: var(--bg-tertiary);
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
    justify-content: space-between;
    animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.reply-bar.active {
    display: flex;
}

.reply-bar-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.reply-bar-line {
    width: 3px;
    height: 32px;
    background: var(--accent);
    border-radius: 2px;
    flex-shrink: 0;
}

.reply-bar-info {
    font-size: 0.85rem;
    min-width: 0;
    flex: 1;
}

.reply-bar-name {
    color: var(--accent);
    font-weight: 600;
}

.reply-bar-text {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-bar-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.reply-bar-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.reply-bar-close svg {
    width: 20px;
    height: 20px;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.input-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.input-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.input-btn svg {
    width: 22px;
    height: 22px;
}

.message-input-wrapper {
    flex: 1;
    position: relative;
}

.message-input {
    width: 100%;
    background: var(--bg-primary);
    border: none;
    border-radius: 1.25rem;
    padding: 0.625rem 1rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    transition: box-shadow 0.2s;
}

.message-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent);
}

.message-input::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

.recording-indicator {
    display: none;
    align-items: center;
    justify-content: space-between;
    background: rgba(239, 68, 68, 0.15);
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    animation: slideUp 0.2s ease-out;
}

.recording-indicator.active {
    display: flex;
}

.recording-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.recording-dot {
    width: 10px;
    height: 10px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.9); }
}

.recording-text {
    color: #f87171;
    font-size: 0.9rem;
}

.recording-time {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: monospace;
}

.recording-cancel {
    background: none;
    border: none;
    color: #f87171;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background 0.2s;
}

.recording-cancel:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ========================================
   منوها و پاپ‌آپ‌ها
   ======================================== */

.attach-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 0.5rem);
    right: 0;
    background: var(--bg-tertiary);
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    z-index: 100;
    min-width: 180px;
}

.attach-menu.active {
    display: block;
    animation: popIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.9) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.attach-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    color: var(--text-primary);
}

.attach-item:hover {
    background: rgba(135, 116, 225, 0.2);
}

.attach-item input {
    display: none;
}

.attach-item svg {
    width: 22px;
    height: 22px;
}

/* منوی کانتکست */
.context-menu {
    display: none;
    position: fixed;
    background: var(--bg-tertiary);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    z-index: 200;
    min-width: 200px;
    max-width: 280px;
}

.context-menu.active {
    display: block;
    animation: popIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.context-header {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.context-reactions {
    display: flex;
    justify-content: center;
    gap: 0.125rem;
    flex-wrap: wrap;
}

.context-reaction {
    font-size: 1.1rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
    line-height: 1;
}

.context-reaction:hover {
    transform: scale(1.2);
    background: rgba(255, 255, 255, 0.1);
}

.context-reaction:active {
    transform: scale(0.9);
}

.context-body {
    padding: 0.375rem;
}

.context-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    background: none;
    color: var(--text-primary);
    width: 100%;
    text-align: right;
    font-size: 0.9rem;
    border-radius: 0.5rem;
}

.context-item:hover {
    background: rgba(135, 116, 225, 0.2);
}

.context-item.danger {
    color: #f87171;
}

.context-item.danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

.context-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.context-footer {
    padding: 0.5rem;
    border-top: 1px solid var(--border-color);
    max-height: 150px;
    overflow-y: auto;
}

.context-footer-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    margin-bottom: 0.25rem;
}

.reaction-detail {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    font-size: 0.85rem;
    border-radius: 0.375rem;
}

.reaction-detail-emoji {
    font-size: 1rem;
}

.reaction-detail-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* منشن پاپ‌آپ */
.mention-popup {
    display: none;
    position: absolute;
    bottom: calc(100% + 0.5rem);
    right: 0;
    left: 0;
    background: var(--bg-tertiary);
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
}

.mention-popup.active {
    display: block;
    animation: popIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mention-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.mention-item:hover {
    background: rgba(135, 116, 225, 0.2);
}

.mention-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    overflow: hidden;
}

.mention-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mention-name {
    font-weight: 500;
}

/* فوروارد مودال */
.forward-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 250;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.forward-modal.active {
    display: flex;
}

.forward-modal-content {
    background: var(--bg-secondary);
    border-radius: 1rem;
    width: 100%;
    max-width: 360px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: popIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.forward-modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.forward-modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.forward-modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    display: flex;
    transition: all 0.2s;
}

.forward-modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.forward-modal-close svg {
    width: 24px;
    height: 24px;
}

.forward-modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.forward-chat-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.forward-chat-item:hover {
    background: var(--bg-tertiary);
}

.forward-chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 600;
    overflow: hidden;
}

.forward-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.forward-chat-name {
    font-weight: 500;
}

/* دراپ زون */
.drop-zone {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(135, 116, 225, 0.9);
    z-index: 100;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
}

.drop-zone.active {
    display: flex;
}

.drop-zone svg {
    width: 80px;
    height: 80px;
    color: white;
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.drop-zone p {
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
}

/* ========================================
   پروفایل
   ======================================== */

.profile-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 250;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.profile-modal.active {
    display: flex;
}

.profile-modal-content {
    background: var(--bg-secondary);
    border-radius: 1rem;
    width: 100%;
    max-width: 360px;
    padding: 1.5rem;
    animation: popIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.profile-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.profile-modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.profile-avatar-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.profile-avatar-preview {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 600;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s;
}

.profile-avatar-preview:hover {
    transform: scale(1.05);
}

.profile-avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar-preview:hover::after {
    content: '📷';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.profile-avatar-preview input {
    display: none;
}

.profile-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border: none;
    border-radius: 0.75rem;
    padding: 0.75rem;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.profile-btn:hover {
    transform: translateY(-2px);
}

/* گیف‌های ذخیره شده */
.saved-gifs-panel {
    display: none;
    position: absolute;
    bottom: calc(100% + 0.5rem);
    right: 0;
    background: var(--bg-tertiary);
    border-radius: 0.75rem;
    padding: 0.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    z-index: 100;
    width: 280px;
    max-height: 240px;
}

.saved-gifs-panel.active {
    display: block;
    animation: popIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.saved-gifs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
}

.saved-gifs-header h4 {
    font-size: 0.9rem;
    font-weight: 600;
}

.saved-gifs-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.375rem;
    max-height: 180px;
    overflow-y: auto;
}

.saved-gif-item {
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s;
}

.saved-gif-item:hover {
    transform: scale(1.05);
}

.saved-gif-item img,
.saved-gif-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.saved-gif-item:hover::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
}

.saved-gif-remove {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
    background: rgba(239, 68, 68, 0.9);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 0.7rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.saved-gif-item:hover .saved-gif-remove {
    display: flex;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-tertiary);
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    z-index: 300;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ========================================
   ریسپانسیو
   ======================================== */

@media (max-width: 768px) {
    .context-menu {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 1.5rem 1.5rem 0 0 !important;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.1, 0.7, 0.1, 1);
        display: block !important; /* همیشه در دام باشد ولی مخفی با ترنسفرم */
        opacity: 1 !important;
        z-index: 1000;
    }

    .context-menu.active {
        transform: translateY(0);
    }

    /* بک گراند تاریک پشت منو */
    .context-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        display: none;
        backdrop-filter: blur(2px);
    }
    .context-menu.active + .context-overlay,
    .context-overlay.active {
        display: block;
    }

    .context-reactions {
        padding: 1rem 0.5rem;
        gap: 0.75rem;
        justify-content: space-around;
    }

    .context-reaction {
        font-size: 1.8rem; /* آیکون بزرگتر برای لمس */
        padding: 0.5rem;
        background: rgba(255,255,255,0.05);
    }

    .context-item {
        padding: 1rem;
        font-size: 1rem;
        border-bottom: 1px solid rgba(255,255,255,0.05);
    }
}

@media (max-width: 480px) {
    .message {
        max-width: 90%;
    }
    
    .message-media {
        max-width: 220px;
    }
    
    .voice-message {
        min-width: 160px;
        max-width: 220px;
    }
    
    .music-message {
        min-width: 200px;
        max-width: 260px;
    }
    
    .forward-modal-content {
        max-width: 100%;
    }
    
    .profile-modal-content {
        max-width: 100%;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .messages-container {
        padding: 0.5rem;
    }
    
    .chat-header {
        padding: 0.375rem 1rem;
        min-height: 50px;
    }
    
    .input-area {
        padding: 0.375rem 1rem;
    }
}
/* --- اصلاحات ریسپانسیو و موبایل --- */

/* مخفی کردن اسکرول اضافی در موبایل */
body, html {
    overflow: hidden;
    height: 100%;
    position: fixed; /* جلوگیری از اسکرول کلی صفحه در iOS */
    width: 100%;
}

@media (max-width: 768px) {
    .app-container {
        position: relative;
        width: 100%;
        height: 100%;
    }

    /* سایدبار تمام صفحه */
    .sidebar {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        position: absolute;
        z-index: 20;
        background: var(--bg-secondary);
        transition: transform 0.3s ease-in-out;
        transform: translateX(0);
    }

    /* وقتی چت باز است، سایدبار برود کنار */
    .sidebar.hidden {
        transform: translateX(100%); /* در حالت RTL این یعنی برود سمت راست */
    }

    /* ناحیه چت تمام صفحه */
    .chat-area {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 10;
    }

    /* دکمه بازگشت */
    .back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: 0.5rem;
        padding: 8px;
    }

    /* اصلاح اینپوت در موبایل */
    .input-area {
        padding: 10px;
        position: fixed; /* چسبیدن به پایین */
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        background: var(--bg-secondary);
        z-index: 30;
    }
    
    .messages-container {
        padding-bottom: 80px; /* فضای خالی برای اینپوت */
    }

    /* اصلاح منوی کانتکست (Copy/Reply) */
    .context-menu {
        width: 90% !important;
        left: 5% !important;
        right: 5% !important;
        bottom: 20px !important;
        top: auto !important;
        border-radius: 15px !important;
        transform: translateY(120%);
        transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    .context-menu.active {
        transform: translateY(0);
    }

    /* جلوگیری از زوم شدن روی اینپوت در آیفون */
    input, textarea {
        font-size: 16px !important; 
    }
}