﻿/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@font-face {
    font-family: 'Vazirmatn';
    src: url('/fonts/vazirmatn/Vazirmatn[wght].woff2') format('woff2');
    font-style: normal;
}

:root {
    --primary-color: #2196F3;
    --primary-dark: #1976D2;
    --primary-light: #BBDEFB;
    --secondary-color: #25D366;
    --background-main: #E5DDD5;
    --background-chat: #F0F2F5;
    --sidebar-bg: #FFFFFF;
    --message-out: #DCF8C6;
    --message-in: #FFFFFF;
    --text-primary: #303030;
    --text-secondary: #667781;
    --border-color: #E9EDEF;
    --shadow: 0 1px 2px rgba(0,0,0,0.1);
    --radius: 8px;
    --header-height: 60px;
    --input-height: 60px;
}

body {
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
    direction: rtl;
    background: var(--background-chat);
    color: var(--text-primary);
    margin: 0;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 280px;
    pointer-events: auto;
    animation: slideDown 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 10px;
}

    .toast.success {
        border-right: 4px solid #4CAF50;
    }

    .toast.error {
        border-right: 4px solid #F44336;
    }

    .toast.info {
        border-right: 4px solid #2196F3;
    }

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Messenger Main Layout */
.messenger-container {
    display: flex;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* Sidebar */
.messenger-sidebar {
    width: 380px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    transition: transform 0.3s ease;
}

.sidebar-header {
    height: var(--header-height);
    background: var(--background-chat);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

    .sidebar-header h5 {
        font-size: 19px;
        font-weight: 500;
        margin: 0;
        color: var(--text-primary);
    }

.header-actions {
    display: flex;
    gap: 5px;
}

    .header-actions .btn {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: transparent;
        border: none;
        color: var(--text-secondary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
    }

        .header-actions .btn:hover {
            background: rgba(0,0,0,0.05);
            color: var(--primary-color);
        }

/* Search Box */
.search-box {
    padding: 8px 12px;
    background: var(--background-chat);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.search-input {
    width: 100%;
    height: 36px;
    border: none;
    border-radius: 18px;
    background: white;
    padding: 0 40px 0 16px;
    font-size: 15px;
    outline: none;
    transition: box-shadow 0.2s;
}

    .search-input:focus {
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }

.search-box::before {
    content: "🔍";
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    opacity: 0.5;
}

/* Contacts List */
.contacts-list {
    flex: 1;
    overflow-y: auto;
    background: white;
}

.contact-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
}

    .contact-item:hover {
        background: var(--background-chat);
    }

    .contact-item.active {
        background: var(--background-chat);
    }

    .contact-item::after {
        content: '';
        position: absolute;
        bottom: 0;
        right: 74px;
        left: 16px;
        height: 1px;
        background: var(--border-color);
    }

.contact-avatar {
    width: 49px;
    height: 49px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 500;
    margin-left: 13px;
    flex-shrink: 0;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-size: 17px;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-last-message {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.contact-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.contact-unread {
    background: var(--secondary-color);
    color: white;
    font-size: 12px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    font-weight: 500;
}

.contact-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #B3B3B3;
    position: absolute;
    bottom: 12px;
    right: 20px;
}

    .contact-status.online {
        background: var(--secondary-color);
    }

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    height: var(--header-height);
    background: var(--background-chat);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.back-btn {
    display: none;
    width: 40px;
    height: 40px;
    margin-left: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    border-radius: 50%;
    transition: background 0.2s;
}

    .back-btn:hover {
        background: rgba(0,0,0,0.05);
    }

.chat-contact-info {
    flex: 1;
    margin-right: 12px;
}

    .chat-contact-info h6 {
        font-size: 16px;
        font-weight: 500;
        margin: 0;
        color: var(--text-primary);
    }

.chat-contact-status {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect width="100" height="100" fill="%23E5DDD5"/><path d="M0 0L50 50L0 100M50 0L100 50L50 100" fill="none" stroke="%23D4CFC7" stroke-width="0.5" opacity="0.5"/></svg>');
    background-size: 100px 100px;
}

/* Messages */
.message {
    display: flex;
    margin-bottom: 12px;
    animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.incoming {
    justify-content: flex-end;
}

.message.outgoing {
    justify-content: flex-start;
}

.message-content {
    max-width: 65%;
    position: relative;
    border-radius: 7.5px;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
    overflow: hidden;
}

.incoming .message-content {
    background: white;
    border-bottom-right-radius: 0;
}

.outgoing .message-content {
    background: var(--message-out);
    border-bottom-left-radius: 0;
}

.message-text {
    padding: 6px 9px 8px;
    font-size: 14.2px;
    line-height: 19px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-time {
    float: left;
    margin: -5px -5px -5px 10px;
    padding: 4px 6px 2px;
    font-size: 11px;
    color: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    gap: 2px;
}

.message-status {
    font-size: 16px;
    color: #B3B9C1;
}

    .message-status.delivered {
        color: #B3B9C1;
    }

    .message-status.read {
        color: #53BDEB;
    }

.message-image {
    max-width: 100%;
    max-height: 300px;
    display: block;
    border-radius: 7.5px;
    cursor: pointer;
}

.message-file {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

    .message-file i {
        font-size: 24px;
        color: var(--text-secondary);
    }

    .message-file a {
        color: var(--primary-color);
        text-decoration: none;
        font-size: 14px;
        word-break: break-all;
    }

/* Chat Input */
.chat-input {
    padding: 5px 16px 10px;
    background: var(--background-chat);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border-top: 1px solid var(--border-color);
}

.chat-input-wrapper {
    flex: 1;
    background: white;
    border-radius: 21px;
    display: flex;
    align-items: flex-end;
    padding: 5px 12px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

.attach-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
}

    .attach-btn:hover {
        background: rgba(0,0,0,0.05);
        color: var(--primary-color);
    }

textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    padding: 10px 0;
    font-size: 15px;
    line-height: 20px;
    max-height: 100px;
    font-family: inherit;
}

.send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-color);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

    .send-btn:hover {
        background: var(--primary-dark);
        transform: scale(1.05);
    }

    .send-btn:active {
        transform: scale(0.95);
    }

/* Empty States */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
}

    .empty-state i {
        font-size: 64px;
        opacity: 0.3;
        margin-bottom: 16px;
    }

    .empty-state h4 {
        font-size: 20px;
        font-weight: 400;
        margin-bottom: 8px;
        color: var(--text-primary);
    }

    .empty-state p {
        font-size: 14px;
    }

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

    .modal-header h3 {
        font-size: 20px;
        font-weight: 500;
        margin: 0;
        display: flex;
        align-items: center;
        gap: 10px;
    }

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

    .close-btn:hover {
        background: rgba(0,0,0,0.05);
        color: var(--text-primary);
    }

.modal-content .form-group {
    padding: 0 24px;
    margin-bottom: 20px;
}

    .modal-content .form-group:last-child {
        margin-bottom: 24px;
    }

.form-group label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
    background: var(--background-chat);
}

    .form-control:focus {
        border-color: var(--primary-color);
        background: white;
    }

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

    .btn-primary:hover {
        background: var(--primary-dark);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(33,150,243,0.3);
    }

.btn-secondary {
    background: var(--background-chat);
    color: var(--text-primary);
}

    .btn-secondary:hover {
        background: #E0E0E0;
    }

.btn-success {
    background: #4CAF50;
    color: white;
}

.btn-danger {
    background: #F44336;
    color: white;
}

.btn-info {
    background: #2196F3;
    color: white;
}

.w-100 {
    width: 100%;
}

.d-flex {
    display: flex;
}

.gap-2 {
    gap: 8px;
}

.flex-fill {
    flex: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {

    .messenger-container {
        display: block;
    }

    .messenger-sidebar {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 10;
        transform: translateX(0);
        transition: transform 0.3s ease;
    }

        .messenger-sidebar.hide-mobile {
            transform: translateX(100%);
        }

    .chat-container {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

        .chat-container.active {
            transform: translateX(0);
        }

    .back-btn {
        display: flex;
    }

    .sidebar-header h5 {
        font-size: 17px;
    }

    .message-content {
        max-width: 80%;
    }

    .modal-content {
        margin: 20px;
        width: calc(100% - 40px);
    }
}

@media (max-width: 480px) {
    .sidebar-header {
        padding: 10px 12px;
    }

    .header-actions .btn {
        width: 36px;
        height: 36px;
    }

    .contact-avatar {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }

    .contact-name {
        font-size: 16px;
    }

    .chat-messages {
        padding: 12px;
    }

    .send-btn {
        width: 42px;
        height: 42px;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

    ::-webkit-scrollbar-thumb:hover {
        background: rgba(0,0,0,0.3);
    }

/* Loading Animation */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}

    .loading::after {
        content: '';
        width: 32px;
        height: 32px;
        margin-right: 12px;
        border: 3px solid var(--border-color);
        border-top-color: var(--primary-color);
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Auth Pages Styling */
.auth-container {
    max-width: 400px;
    margin: 50px auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    overflow: hidden;
}

.auth-header {
    background: var(--primary-color);
    color: white;
    padding: 40px 30px;
    text-align: center;
}

    .auth-header h2 {
        font-size: 28px;
        margin-bottom: 8px;
        font-weight: 500;
    }

    .auth-header p {
        font-size: 16px;
        opacity: 0.9;
    }

.auth-tabs {
    display: flex;
    background: var(--background-chat);
}

.auth-tab {
    flex: 1;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s;
    position: relative;
}

    .auth-tab.active {
        color: var(--primary-color);
        background: white;
    }

        .auth-tab.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: var(--primary-color);
        }

.auth-form {
    padding: 30px;
    display: none;
}

    .auth-form.active {
        display: block;
    }

    .auth-form .form-group {
        margin-bottom: 20px;
    }

    .auth-form .btn-primary {
        width: 100%;
        padding: 14px;
        font-size: 16px;
        margin-top: 10px;
    }

/* Admin Panel */
.admin-panel-content {
    max-width: 900px;
    margin: 20px auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    overflow: hidden;
}

.admin-tabs {
    display: flex;
    flex-wrap: wrap;
    background: var(--background-chat);
    padding: 8px;
    gap: 8px;
}

.admin-tab {
    padding: 10px 16px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

    .admin-tab:hover {
        background: var(--primary-light);
        color: var(--primary-dark);
    }

    .admin-tab.active {
        background: var(--primary-color);
        color: white;
    }

.admin-content {
    padding: 24px;
    display: none;
}

    .admin-content.active {
        display: block;
    }

.user-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--background-chat);
    border-radius: 8px;
    margin-bottom: 12px;
    transition: all 0.2s;
}

    .user-item:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    }

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 500;
    margin-left: 16px;
}

.user-info {
    flex: 1;
}

.user-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.user-role {
    font-size: 14px;
    color: var(--text-secondary);
}

.user-date {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.user-actions {
    display: flex;
    gap: 8px;
}

    .user-actions .btn {
        padding: 8px 16px;
        font-size: 13px;
    }

.alert {
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-info {
    background: #E3F2FD;
    color: #1565C0;
}

.alert-danger {
    background: #FFEBEE;
    color: #C62828;
}

/* Welcome Page */
.welcome-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.welcome-card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    padding: 48px;
    text-align: center;
    max-width: 480px;
    width: 100%;
    animation: welcomeFadeIn 0.8s ease-out;
}

@keyframes welcomeFadeIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.welcome-icon {
    font-size: 80px;
    margin-bottom: 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-title {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.welcome-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.6;
}

.welcome-actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 32px;
}

.welcome-btn {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.3s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

    .welcome-btn.btn-primary {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
    }

        .welcome-btn.btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
        }

    .welcome-btn.btn-secondary {
        background: transparent;
        border: 2px solid #E0E0E0;
        color: var(--text-primary);
    }

        .welcome-btn.btn-secondary:hover {
            background: var(--background-chat);
            border-color: var(--primary-color);
            color: var(--primary-color);
        }

.welcome-footer {
    font-size: 14px;
    color: var(--text-secondary);
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

/* RTL Specific */
.btn i, .btn .fas, .btn .fa {
    margin-left: 8px;
    margin-right: 0;
}

/* Focus States */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus-visible {
    outline-offset: 0;
}

/* Print Styles */
@media print {
    .messenger-sidebar,
    .chat-header,
    .chat-input,
    .header-actions {
        display: none !important;
    }

    .chat-messages {
        background: white !important;
    }
}
