@font-face {
    font-family: 'Vazir';
    src: url('Vazirmatn-Regular.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Vazir';
    src: url('Vazirmatn-Medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

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

:root {
    --bg-primary: #0a1628;
    --bg-secondary: #111b21;
    --bg-tertiary: #202c33;
    --bg-message-sent: #005c4b;
    --bg-message-received: #202c33;
    --bg-input: #2a3942;
    --bg-hover: #374149;
    --color-primary: #00a884;
    --color-primary-hover: #05c288;
    --color-text: #e9edef;
    --color-text-secondary: #8696a0;
    --border-color: #2a3942;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Vazir', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.chat-container {
    max-width: 100%;
    margin: 0 auto;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
}

.chat-header {
    background: var(--bg-tertiary);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary) 0%, #008069 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 168, 132, 0.3);
}

.avatar svg {
    width: 24px;
    height: 24px;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    color: var(--color-text);
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-status {
    color: var(--color-text-secondary);
    font-size: 13px;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-secondary);
    transition: background 0.3s;
}

.user-status.online .status-dot {
    background: var(--color-primary);
    box-shadow: 0 0 6px var(--color-primary);
}

.header-actions {
    display: flex;
    gap: 4px;
}

.header-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.header-btn:hover, .header-btn:active {
    background: var(--bg-input);
}

.header-btn svg {
    width: 22px;
    height: 22px;
}

.typing-indicator {
    background: rgba(0, 168, 132, 0.1);
    padding: 8px 16px;
    display: none;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

.typing-indicator.active {
    display: flex;
}

.typing-text {
    color: var(--color-primary);
    font-size: 13px;
    font-weight: 500;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-primary);
    animation: typingDot 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-8px); opacity: 1; }
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(0, 168, 132, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(0, 168, 132, 0.03) 0%, transparent 50%);
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--bg-input);
    border-radius: 10px;
}

.welcome-message {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 40px 20px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin: 40px auto;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.welcome-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, var(--color-primary) 0%, #008069 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.welcome-icon svg {
    width: 32px;
    height: 32px;
}

.welcome-message h3 {
    color: var(--color-text);
    font-size: 18px;
    margin-bottom: 8px;
}

.welcome-message p {
    font-size: 14px;
    line-height: 1.5;
}

.message {
    display: flex;
    margin-bottom: 8px;
    animation: messageSlide 0.3s ease;
    position: relative;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    justify-content: flex-end;
}

.message.received {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.2s;
}

.message-bubble:active {
    transform: scale(0.98);
}

.message.sent .message-bubble {
    background: var(--bg-message-sent);
    border-top-right-radius: 2px;
}

.message.received .message-bubble {
    background: var(--bg-message-received);
    border-top-left-radius: 2px;
}

.message-sender {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.message.sent .message-sender {
    color: #8bc6c0;
}

.message-text {
    color: var(--color-text);
    font-size: 14.5px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-file {
    margin-top: 6px;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.1);
}

.message-file img {
    max-width: 100%;
    display: block;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-file img:active {
    opacity: 0.8;
}

.file-document {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.file-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary);
    flex-shrink: 0;
}

.file-icon svg {
    width: 22px;
    height: 22px;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    color: var(--color-text);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.file-size {
    color: var(--color-text-secondary);
    font-size: 12px;
}

.file-download {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 6px;
    background: rgba(0, 168, 132, 0.15);
    transition: background 0.2s;
    white-space: nowrap;
}

.file-download:active {
    background: rgba(0, 168, 132, 0.25);
}

.message-time {
    font-size: 11px;
    color: var(--color-text-secondary);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.message.sent .message-time {
    justify-content: flex-end;
}

.scroll-bottom {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    width: 48px;
    height: 48px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--color-text-secondary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
    transition: all 0.3s;
}

.scroll-bottom.visible {
    display: flex;
}

.scroll-bottom:active {
    transform: translateX(-50%) scale(0.95);
}

.scroll-bottom svg {
    width: 24px;
    height: 24px;
}

.unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--color-primary);
    color: white;
    font-size: 11px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    display: none;
}

.unread-badge.visible {
    display: block;
}

.input-container {
    background: var(--bg-tertiary);
    padding: 8px 16px 8px;
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
    z-index: 100;
}

#userName {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--color-text);
    font-family: 'Vazir', sans-serif;
    font-size: 15px;
    margin-bottom: 8px;
    outline: none;
    transition: all 0.2s;
}

#userName:focus {
    background: var(--bg-hover);
    border-color: var(--color-primary);
}

.message-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.attach-btn, .emoji-btn {
    width: 42px;
    height: 42px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.attach-btn:active, .emoji-btn:active {
    background: var(--bg-input);
    transform: scale(0.95);
}

.attach-btn svg, .emoji-btn svg {
    width: 24px;
    height: 24px;
}

.input-emoji-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

#messageInput {
    width: 100%;
    padding: 12px 48px 12px 16px;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: 24px;
    color: var(--color-text);
    font-family: 'Vazir', sans-serif;
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
}

#messageInput:focus {
    background: var(--bg-hover);
    border-color: var(--color-primary);
}

.emoji-btn {
    position: absolute;
    left: 4px;
}

.send-btn {
    width: 42px;
    height: 42px;
    border: none;
    background: var(--color-primary);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 168, 132, 0.4);
}

.send-btn:active {
    background: var(--color-primary-hover);
    transform: scale(0.95);
}

.send-btn svg {
    width: 22px;
    height: 22px;
}

.file-preview {
    margin-top: 8px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 12px;
}

.file-preview.active {
    display: flex;
}

.preview-info {
    flex: 1;
    color: var(--color-text);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-file {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.remove-file:active {
    background: var(--bg-hover);
    transform: scale(0.95);
}

.remove-file svg {
    width: 20px;
    height: 20px;
}

.emoji-picker {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 8px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    max-height: 250px;
    overflow-y: auto;
}

.emoji-picker.active {
    display: block;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 4px;
}

.emoji-item {
    font-size: 28px;
    padding: 8px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    text-align: center;
    user-select: none;
}

.emoji-item:active {
    background: var(--bg-input);
    transform: scale(1.1);
}

.context-menu {
    position: fixed;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: none;
}

.context-menu.active {
    display: block;
}

.context-menu-item {
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--color-text);
    font-family: 'Vazir', sans-serif;
    font-size: 14px;
    text-align: right;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
}

.context-menu-item:active {
    background: var(--bg-input);
}

.context-menu-item svg {
    width: 20px;
    height: 20px;
    color: var(--color-text-secondary);
}

.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-modal.active {
    display: flex;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2001;
    transition: all 0.2s;
}

.modal-close:active {
    transform: scale(0.95);
}

.modal-close svg {
    width: 24px;
    height: 24px;
}

#modalImage {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.install-prompt, .notification-prompt {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-tertiary);
    border-top: 2px solid var(--color-primary);
    padding: 16px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1500;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.install-prompt.show, .notification-prompt.show {
    transform: translateY(0);
}

.install-content, .notification-content {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
}

.install-icon, .notification-icon {
    width: 48px;
    height: 48px;
    background: var(--color-primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.install-icon svg, .notification-icon svg {
    width: 28px;
    height: 28px;
}

.install-text, .notification-text {
    flex: 1;
    min-width: 0;
}

.install-text strong, .notification-text strong {
    display: block;
    color: var(--color-text);
    font-size: 15px;
    margin-bottom: 4px;
}

.install-text p, .notification-text p {
    color: var(--color-text-secondary);
    font-size: 13px;
    margin: 0;
}

.install-btn, .notification-allow {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'Vazir', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}

.install-btn:active, .notification-allow:active {
    background: var(--color-primary-hover);
}

.notification-deny {
    background: transparent;
    color: var(--color-text-secondary);
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'Vazir', sans-serif;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.install-close {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .chat-container {
        max-width: 900px;
        margin: 0 auto;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    }
    
    .message-bubble {
        max-width: 65%;
    }
    
    .scroll-bottom {
        bottom: 160px;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 8px 12px;
    }
    
    .messages-container {
        padding: 12px;
    }
    
    .input-container {
        padding: 8px 12px;
    }
    
    #userName, #messageInput {
        font-size: 16px;
    }
}