/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    direction: rtl;
}

/* Landing Page */
.landing-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.landing-container {
    max-width: 1200px;
    padding: 2rem;
    text-align: center;
    color: white;
}

.logo h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
    font-weight: 700;
}

.logo p {
    font-size: 1.2rem;
    margin-bottom: 3rem;
    opacity: 0.9;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.feature {
    background: rgba(255, 255, 255, 0.1);
    padding: 2rem;
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

.feature h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.auth-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Auth Pages */
.auth-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-container {
    width: 100%;
    max-width: 400px;
}

.auth-form {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h2 {
    color: #333;
    margin-bottom: 0.5rem;
}

.auth-header p {
    color: #666;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.auth-footer {
    text-align: center;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid #e1e5e9;
}

.auth-footer a {
    color: #667eea;
    text-decoration: none;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
    transform: translateY(-2px);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Telegram-like Layout */
.telegram-container {
    display: flex;
    height: 100vh;
    background: #f5f5f5;
}

/* Sidebar */
.sidebar {
    width: 350px;
    background: white;
    border-left: 1px solid #e1e5e9;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
}

.user-info {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

.user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    margin-left: 1rem;
}

.user-avatar.large {
    width: 80px;
    height: 80px;
    font-size: 2rem;
}

.user-details h3 {
    margin-bottom: 0.25rem;
    font-size: 1.1rem;
}

.username {
    color: #666;
    font-size: 0.9rem;
}

.sidebar-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chat-search {
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
}

.chat-search input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #e1e5e9;
    border-radius: 20px;
    font-size: 0.9rem;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s;
}

.chat-item:hover {
    background: #f8f9fa;
}

.chat-item.active {
    background: #e3f2fd;
    border-left: 3px solid #667eea;
}

.chat-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-left: 1rem;
    flex-shrink: 0;
}

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

.chat-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-last-message {
    color: #666;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    text-align: left;
    font-size: 0.8rem;
    color: #999;
}

.chat-time {
    margin-bottom: 0.25rem;
}

.member-count {
    background: #e9ecef;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
}

.no-chats {
    padding: 2rem;
    text-align: center;
    color: #666;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
}

.welcome-screen {
    text-align: center;
    max-width: 500px;
    padding: 2rem;
}

.welcome-content h2 {
    margin-bottom: 1rem;
    color: #333;
}

.welcome-features {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.feature-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.feature-icon {
    font-size: 2rem;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
    background: white;
}

.chat-header .chat-info {
    display: flex;
    align-items: center;
}

.chat-header .chat-avatar {
    margin-left: 1rem;
}

.chat-details h3 {
    margin-bottom: 0.25rem;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8f9fa;
}

.message {
    margin-bottom: 1rem;
    max-width: 70%;
}

.message.own-message {
    margin-right: auto;
    margin-left: 30%;
}

.message-sender {
    font-size: 0.85rem;
    color: #667eea;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.message-reply {
    background: rgba(102, 126, 234, 0.1);
    border-right: 3px solid #667eea;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border-radius: 5px;
    font-size: 0.9rem;
}

.reply-author {
    color: #667eea;
    font-weight: 500;
    font-size: 0.8rem;
}

.reply-text {
    color: #666;
    margin-top: 0.25rem;
}

.message-content {
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 15px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    position: relative;
}

.own-message .message-content {
    background: #667eea;
    color: white;
}

.message-time {
    font-size: 0.75rem;
    color: #999;
    margin-top: 0.25rem;
    text-align: left;
}

.own-message .message-time {
    color: rgba(255, 255, 255, 0.7);
}

.edited-label {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-right: 0.5rem;
}

/* Message Input */
.message-input-container {
    padding: 1rem;
    background: white;
    border-top: 1px solid #e1e5e9;
}

.reply-preview {
    background: #f8f9fa;
    border-right: 3px solid #667eea;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.reply-content {
    flex: 1;
}

.cancel-reply {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #999;
}

.input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    border: 1px solid #e1e5e9;
    border-radius: 20px;
    padding: 0.75rem 1rem;
    resize: none;
    max-height: 120px;
    font-family: inherit;
}

.send-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.send-btn:hover {
    background: #5a6fd8;
}

/* Chat Info Panel */
.chat-info-panel {
    width: 300px;
    background: white;
    border-right: 1px solid #e1e5e9;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
}

.panel-header button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.chat-details {
    text-align: center;
    margin-bottom: 2rem;
}

.chat-details h4 {
    margin: 1rem 0 0.5rem;
}

.invite-link-section {
    margin-bottom: 2rem;
}

.invite-link {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.invite-link input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #e1e5e9;
    border-radius: 5px;
    font-size: 0.9rem;
}

.members-section h5 {
    margin-bottom: 1rem;
}

.members-list {
    max-height: 300px;
    overflow-y: auto;
}

.member-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.member-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-left: 0.75rem;
    font-size: 0.9rem;
}

.member-info {
    flex: 1;
}

.member-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.member-status {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.8rem;
}

.admin-badge {
    background: #28a745;
    color: white;
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    font-size: 0.7rem;
}

.online-status.online {
    color: #28a745;
}

.online-status.offline {
    color: #6c757d;
}

/* Admin Page */
.admin-page {
    background: #f8f9fa;
    min-height: 100vh;
}

.admin-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: white;
    padding: 1.5rem;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.admin-nav {
    display: flex;
    gap: 1rem;
}

.admin-section {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.admin-section h2 {
    margin-bottom: 1.5rem;
    color: #333;
}

.admin-form {
    max-width: 600px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.chats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

.chat-card {
    border: 1px solid #e1e5e9;
    border-radius: 10px;
    overflow: hidden;
}

.chat-card-header {
    background: #f8f9fa;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-type {
    background: #667eea;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 15px;
    font-size: 0.8rem;
}

.chat-card-body {
    padding: 1rem;
}

.chat-stats {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
    font-size: 0.9rem;
    color: #666;
}

.invite-link label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.link-container {
    display: flex;
    gap: 0.5rem;
}

.invite-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #e1e5e9;
    border-radius: 5px;
    font-size: 0.9rem;
}

.chat-card-actions {
    padding: 1rem;
    background: #f8f9fa;
    display: flex;
    gap: 0.5rem;
}

.users-table {
    overflow-x: auto;
}

.users-table table {
    width: 100%;
    border-collapse: collapse;
}

.users-table th,
.users-table td {
    padding: 1rem;
    text-align: right;
    border-bottom: 1px solid #e1e5e9;
}

.users-table th {
    background: #f8f9fa;
    font-weight: 500;
}

.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-badge.online {
    background: #d4edda;
    color: #155724;
}

.status-badge.offline {
    background: #f8d7da;
    color: #721c24;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 10px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    padding: 1rem;
}

.add-member-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #e1e5e9;
}

/* Join Page */
.join-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.join-container {
    max-width: 500px;
    padding: 2rem;
}

.join-content {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    text-align: center;
}

.error-message h2 {
    color: #dc3545;
    margin-bottom: 1rem;
}

.chat-preview h2 {
    margin: 1rem 0;
}

.join-actions {
    margin-top: 2rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 1rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .telegram-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 40vh;
    }
    
    .chat-area {
        height: 60vh;
    }
    
    .chat-info-panel {
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
    }
    
    .features {
        grid-template-columns: 1fr;
    }
    
    .auth-buttons {
        flex-direction: column;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .chats-grid {
        grid-template-columns: 1fr;
    }
    
    .admin-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .welcome-features {
        flex-direction: column;
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .landing-container {
        padding: 1rem;
    }
    
    .logo h1 {
        font-size: 2rem;
    }
    
    .auth-form {
        padding: 1.5rem;
    }
    
    .admin-container {
        padding: 1rem;
    }
    
    .sidebar {
        width: 100%;
    }
    
    .message {
        max-width: 85%;
    }
    
    .message.own-message {
        margin-left: 15%;
    }
}