* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: white;
    background: #3B3B3B;
    min-height: 100vh;
}

@font-face {
    font-family: 'Segoe Fluent Icons';
    src: url('../fonts/SegoeFluentIcons.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}
.icon {
    font-family: 'Segoe Fluent Icons';
    font-size: 16px;
    width: 20px;
    display: inline-block;
    color: #fff;
}

.icon-gs:before {
    content: '\E720';
    font-size: 20px;
    width: 20px;
    height: 20px;
}

.icon-file:before {
    content: '\E723';
    font-size: 20px;
    width: 20px;
    height: 20px;
}

.icon-circ:before {
    content: '\E722';
    font-size: 20px;
    width: 20px;
    height: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

a {
    text-decoration: none;
}

/* Navigation */
nav {
    background: #555555;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

nav .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
}

.logo {
    font-size: 24px;
    font-weight: bold;
    color: white;
    text-decoration: none;
}

.nav-right a {
    margin-left: 20px;
    text-decoration: none;
    color: black;
    font-weight: 500;
}

.nav-right a:hover {
    color: white;
    text-decoration: none;
}

.btn-register {
    background: #6FDBC9;
    color: black;
    padding: 8px 16px;
    border-radius: 5px;
}

.btn-notifications {
    border-radius: 12px;
    background: #616161;
    color: white;
}
.btn-notifications:hover {
    cursor: pointer;
}
.btn-logout {
    width: 100%;
    padding: 12px;
    background: #6FDBC9;
    color: black;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
    margin-top: 15px;
    display: block; 
    box-sizing: border-box;
    text-align: center;
}
.settings-container .btn-primary {
    margin-bottom: 20px;
}
.username {
    font-weight: bold;
    color: #667eea;
}

/* Flash messages */
.flash-messages {
    margin-bottom: 20px;
}

.flash-message {
    padding: 12px 15px;
    border-radius: 5px;
    margin-bottom: 10px;
    border-left: 4px solid transparent;
    font-weight: 500;
}

.flash-success {
    background: #d4edda;
    color: #155724;
    border-left-color: #28a745;
}

.flash-danger {
    background: #f8d7da;
    color: #721c24;
    border-left-color: #f5c6cb;
}

.flash-warning {
    background: #fff3cd;
    color: #856404;
    border-left-color: #ffeeba;
}

.flash-info {
    background: #d1ecf1;
    color: #0c5460;
    border-left-color: #bee5eb;
}

/* Auth pages */
.auth-container {
    max-width: 400px;
    margin: 50px auto;
    background: #262626;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.auth-container h2 {
    text-align: center;
    margin-bottom: 30px;
    color: #667eea;
}

.auth-form .form-group {
    margin-bottom: 20px;
}

.auth-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: white;
}

.auth-form input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.auth-form input:focus {
    outline: none;
    border-color: #667eea;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: #6FDBC9;
    color: black;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: #5568d3;
}

.auth-link {
    text-align: center;
    margin-top: 20px;
}

.auth-link a {
    color: #667eea;
    text-decoration: none;
    font-weight: bold;
}

.auth-link a:hover {
    text-decoration: underline;
}

.search-form-nav {
    display: inline-flex;
    align-items: center;
    margin-right: 15px;
}
.search-form-nav input {
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid #9b9b9b;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.search-form-nav input:focus {
    border-color: #000000;
}
.search-form-nav button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    margin-left: 5px;
    padding: 0 8px;
}

.in-search {
    border-radius: 12px;
    background: #616161;
    color: #C3C3C3;
}

/* Main container */
.main-container {
    background: #262626;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-top: 20px;
}

.main-container h1 {
    margin-bottom: 30px;
    color: #667eea;
    text-align: center;
}

.chats-section {
    margin-bottom: 40px;
}

.chats-section h2 {
    margin-bottom: 15px;
    color: #555;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-create {
    background: #28a745;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
}

.btn-create:hover {
    background: #218838;
}

.btn-create-chat {
    position: sticky;
    bottom: 20px;
    left: 100%;
    transform: translateX(-100%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #6FDBC9;
    border: none;
    color: #333;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    margin-top: 20px;
    z-index: 10;
}

.btn-create-chat:hover {
    background: #5bc8b5;
    transform: translateX(-100%) scale(1.05);
}

.chats-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    
    overflow: hidden;
}
.chat-item {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Убираем границу у последнего элемента, чтобы не было лишней линии */
.chats-list .chat-item:last-child {
    border-bottom: none;
}
.chat-item {
    display: flex;
    align-items: flex-start;
    padding: 12px 16px;
    gap: 12px;
    background: #2a2a2a;
    text-decoration: none;
    transition: background 0.2s ease;
    position: relative;
}
.chat-item:hover {
    background: #3a3a3a;
}
.chat-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 22px;
    font-weight: 600;
    color: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #667eea;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-weight: 600;
    font-size: 16px;
    color: white;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-last-message {
    font-size: 14px;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-last-message-text {
    color: inherit;
}

.chat-last-message-time {
    font-size: 12px;
    color: #888;
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-last-message-sender {
    font-weight: 500;
    color: #ccc;
    margin-right: 4px;
}

.chat-last-message-sender.self {
    color: #6FDBC9;
}

.chat-username {
    color: #666;
    font-size: 14px;
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 20px;
    font-style: italic;
}

/* Chat page */
.chat-container {
    background: #262626;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 150px);
}

.chat-header {
    padding: 20px;
    border-bottom: 2px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #262626;
    border-radius: 10px;
}

.chat-header h2 {
    margin: 0;
    color: #fff;
}

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #262626;
}

.message {
    max-width: 40%;
    padding: 12px 16px;
    border-radius: 10px;
    position: relative;
}

.message-in {
    align-self: flex-start;
    background: #595959;
    border: 2px solid #595959;
    color: #fff;
    border-top-left-radius: 0;
}

.message-out {
    align-self: flex-end;
    background: #333333;
    color: white;
    border-top-right-radius: 0;
}

.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 12px;
}

.message-sender {
    font-weight: bold;
}

.message-time {
    opacity: 0.8;
}

.message-text {
    white-space: pre-wrap;        /* Сохраняет переносы строк */
    word-wrap: break-word;        /* Перенос длинных слов */
    overflow-wrap: break-word;
    word-break: break-word;
}

.message-text a {
    color: #6FDBC9;
    text-decoration: none;
}
.message-text a:hover {
    text-decoration: underline;
}

.message-out .message-text a {
    color: #6FDBC9;
}

.message-input-container {
    padding: 15px;
    border-top: 2px solid #f0f0f0;
    background: #262626;
    border-radius: 10px;
}

#messageForm {
    display: flex;
    gap: 10px;
}

#messageText {
    flex: 1;
    padding: 12px;
    border: 2px solid #333;
    border-radius: 25px;
    font-size: 16px;
    resize: none;
    min-height: 45px;
    max-height: 150px;
    width: 500px;
    transition: border-color 0.3s;
    background: #595959;
}

#messageText:focus {
    outline: none;
    border-color: #000000;
}

.btn-send {
    padding: 12px 25px;
    background: #333333;
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-send:hover {
    background: #4d4d4d;
}

/* Buttons */
.btn-secondary {
    padding: 10px 20px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    text-decoration: none;
    display: inline-block;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-secondary:hover {
    background: #5a6268;
}

/* Search page */
.search-container {
    background: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-top: 20px;
}

.search-form {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
}

.search-form input {
    flex: 1;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
}

.search-form input:focus {
    outline: none;
    border-color: #667eea;
}

.users-list {
    display: grid;
    gap: 15px;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 15px;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    font-weight: bold;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-info {
    flex: 1;
}

.user-name {
    font-weight: bold;
    color: #333;
    margin-bottom: 3px;
}

.user-username {
    color: #666;
    font-size: 14px;
}

/* Profile page */
.profile-container {
    background: #262626;
    border-radius: 10px;
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-top: 20px;
    text-align: center;
}

.profile-header {
    margin-bottom: 30px;
}

.profile-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto 20px;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 48px;
    font-weight: bold;
    
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-header h1 {
    font-size: 32px;
    color: white;
    margin-bottom: 10px;
}

.username {
    font-size: 20px;
    color: #667eea;
    font-weight: bold;
    margin-bottom: 10px;
}

.last-online,
.phone {
    color: white;
    margin: 8px 0;
}

.profile-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

/* Settings page */
.settings-container {
    background: #262626;
    border-radius: 10px;
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-top: 20px;
}

.settings-container h1 {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

.settings-form .form-group {
    margin-bottom: 25px;
    color: white;
}

.set-username {
    color: white;
}

.in-set-username {
    border-radius: 12px;
    background: #616161;
    color: #C3C3C3;
    padding-left: 12px;
}

.set-name {
    color: white;
}

.in-set-name {
    border-radius: 12px;
    background: #616161;
    color: #C3C3C3;
    padding-left: 12px;
}

.set-photo {
    color: white;
}

.settings-form label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    font-size: 16px;
    color: white;
}

.current-photo {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 15px;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 36px;
    font-weight: bold;
    margin-left: auto;
}

.current-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.settings-form input[type="file"] {
    margin-top: 10px;
}

.settings-form small {
    display: block;
    color: #999;
    font-size: 14px;
    margin-top: 5px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: #333;
    margin: 10% auto;
    padding: 30px;
    border-radius: 10px;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    position: relative;
}

.close {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #999;
}

.close:hover {
    color: #333;
}

.modal-content h2 {
    margin-bottom: 20px;
    color: white;
}

.modal-content .form-group {
    margin-bottom: 20px;
}

.user-checkbox {
    display: flex;
    align-items: center;
    padding: 10px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 5px;
}

.user-checkbox input[type="checkbox"] {
    margin-right: 10px;
    width: 18px;
    height: 18px;
}

.user-checkbox {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid transparent;
    transition: all 0.3s;
    cursor: pointer;
}

.user-checkbox:hover {
    background: #e9ecef;
    border-color: #667eea;
}

.user-checkbox input[type="checkbox"] {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.user-checkbox label {
    cursor: pointer;
    width: 100%;
    color: white;
}

.modal-content .form-group label {
    font-weight: 500;
    margin-bottom: 8px;
    display: block;
}

/* Chat header with avatar */
.chat-header {
    padding: 20px;
    border-bottom: 2px solid #f0f0f0;
    background: #262626;
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    gap: 20px;
    border-radius: 10px;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    min-width: 300px;
}

.chat-header-right {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.chat-avatar-large {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    font-weight: bold;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

.chat-avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-title h2 {
    margin: 0 0 5px 0;
    color: #fff;
    font-size: 24px;
}

.chat-status,
.chat-members-count {
    font-size: 14px;
    color: #666;
}

.status-online {
    color: #28a745;
    font-weight: bold;
}

.status-offline {
    color: #999;
}

/* Members list */
.members-list-container {
    background: #333;
    border-bottom: 2px solid #f0f0f0;
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.members-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f0f0f0;
}

.members-list-header h3 {
    margin: 0;
    color: #6FDBC9;
}

.close-members {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #999;
    transition: color 0.3s;
}

.close-members:hover {
    color: #000000;
}

.members-list {
    display: flex;
    flex-direction: column;
    background: #333;
}

.member-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: #333;

    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}
.members-list .member-item:last-child{
    border-bottom: none;
}
.member-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 12px;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 18px;
}

.member-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.member-info {
    flex: 1;
}

.member-name {
    font-weight: bold;
    color: white;
    margin-bottom: 2px;
}

.member-username {
    color: #666;
    font-size: 13px;
}

.badge-creator {
    background: #ffc107;
    color: #000;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    margin-left: 8px;
}

.member-status {
    margin-right: 10px;
}

.status-online-small {
    color: #28a745;
    font-size: 20px;
}

.status-offline-small {
    color: #999;
    font-size: 20px;
}

.btn-remove-member {
    background: #e74c3c;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
    margin-left: 10px;
}

.btn-remove-member:hover {
    background: #c0392b;
    transform: scale(1.1);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .chat-header {
        
        align-items: flex-start;
    }
    .btn-notifications {
        border-color: #333; 
    }
    .chat-header-left {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .chat-header-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .btn-secondary {
        padding: 8px 12px;
        font-size: 14px;
        margin-right: 50px;
    }
    
    .members-list-container {
        max-height: 300px;
    }
    
    .member-item {
        flex-wrap: wrap;
    }
    
    .member-info {
        width: 100%;
        margin-top: 10px;
    }
    
    .member-status,
    .btn-remove-member {
        position: absolute;
        right: 12px;
        top: 50%;
        transform: translateY(-50%);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    nav .container {
        flex-direction: column;
        padding: 10px;
    }
    
    .nav-right {
        margin-top: 10px;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .nav-right a {
        margin: 5px 10px;
    }
    
    .chat-item,
    .user-item {
        /* flex-direction: column; */
        align-items: left;
    }
    .chat-time {
        font-size: 11px;
        margin-top: 1px;
    }
    .chat-time,
    .chat-avatar {
        align-self: flex-end;
    }
    
    .messages-container {
        padding: 10px;
    }
    
    .message {
        max-width: 90%;
    }
    
    #messageForm {
        flex-direction: column;
    }
    
    .profile-avatar {
        width: 80px;
        height: 80px;
        font-size: 32px;
    }
}

.unread-badge {
    background-color: #6FDBC9;
    color: #1e1e1e;
    border-radius: 30px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: bold;
    min-width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.chat-name-link, .chat-avatar-link, .member-link {
    text-decoration: none;
    color: inherit;
}
.chat-name-link:hover, .member-link:hover {
    text-decoration: none;
    color:#5568d3
}
.username-link {
    text-decoration: none;
    color: inherit;
    font-weight: bold;
}
.username-link:hover {
    text-decoration: underline;
}

.online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #ccc;
    border: 2px solid white;
}
.online-dot.online {
    background-color: #4caf50;
}
.online-dot.offline {
    background-color: #9e9e9e;
}

/* Voice message */
.message.voice-message {
    max-width: 300px;
    background: #f0f0f0;
    border-radius: 18px;
    padding: 8px 12px;
    margin: 5px 0;
}

.voice-player {
    display: flex;
    align-items: center;
    gap: 10px;
}

.voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #667eea;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.voice-play-btn:hover {
    background: #5568d3;
}

.voice-play-btn.playing::before {
    content: "⏸️";
}

.voice-play-btn::before {
    content: "▶️";
}

.voice-waveform {
    flex: 1;
    height: 40px;
    background: linear-gradient(90deg, #667eea 0%, #a8b5ff 100%);
    border-radius: 20px;
    position: relative;
    overflow: hidden;
}

.voice-progress {
    height: 100%;
    width: 0%;
    background: rgba(255,255,255,0.3);
    transition: width 0.1s linear;
}

.voice-time {
    font-size: 12px;
    color: #666;
    min-width: 45px;
    text-align: right;
}

/* Video message */
.message.video-message {
    max-width: 200px;
    padding: 0;
    overflow: hidden;
    background: transparent;
    border: none;
}

.video-circle {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    object-fit: cover;
    cursor: pointer;
    background: #000;
    border: 2px solid #333;
    transition: transform 0.2s;
    
}

.video-circle:hover {
    transform: scale(1.02);
}

/* Video modal */
.video-modal {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-modal video {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
    
}

.video-modal .close-video {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2001;
}

#videoPreviewContainer {
    position: fixed;
    bottom: 100px;
    right: 20px;
    background: #000;
    border-radius: 10px;
    padding: 10px;
    z-index: 1000;
}

#videoPreview {
    max-width: 300px;
    max-height: 200px;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}
#messageText {
    flex: 1;
}
.media-buttons {
    display: flex;
    gap: 5px;
}
.btn-media {
    background: #333333;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-media:hover {
    background: #4d4d4d;
}
.btn-media.recording {
    background: #ff4444;
    color: white;
}

.message-menu {
    position: relative;
    display: inline-block;
    margin-left: 10px;
}



.menu-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #999;
    padding: 0 5px;
}



.menu-btn:hover {
    color: #000000;
}


.menu-dropdown {
    position: absolute;
    right: 0;
    top: 25px;
    background: #6d6d6d;
    border: 1px solid #000;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 10;
    min-width: 150px;
}




.menu-dropdown button {
    display: block;
    width: 100%;
    padding: 10px 15px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    color: #ffffff;
}



.menu-dropdown button:hover {
    background: #f0f0f0;
}

.menu-dropdown .delete-all {
    color: #e74c3c;
}

.btn-danger {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
}

.btn-danger:hover {
    background: #c0392b;
}

#deleteConfirmModal .modal-content {
    text-align: center;
}

#deleteConfirmModal .btn-danger,
#deleteConfirmModal .btn-secondary {
    margin: 10px;
}

.image-modal {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.image-modal .close-image {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2001;
}

.file-message {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0f0f0;
    padding: 8px 12px;
    border-radius: 8px;
}

.file-icon {
    font-size: 24px;
}

.file-message a {
    color: #667eea;
    text-decoration: none;
    word-break: break-all;
}

.file-message a:hover {
    text-decoration: underline;
}

.unread-banner {
    position: sticky;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    backdrop-filter: blur(5px);
    font-size: 14px;
    width: fit-content;
    pointer-events: auto;
}
.unread-banner button {
    background: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: black;
    transition: background 0.2s;
}
.unread-banner button:hover {
    background: #f0f0f0;
}
.unread-highlight {
    background-color: rgba(255, 255, 0, 0.2);
    transition: background-color 0.5s;
}

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    margin-bottom: 4px;
}
.reaction-item {
    background: rgba(0,0,0,0.05);
    border-radius: 16px;
    padding: 2px 8px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}
.reaction-item:hover {
    background: rgba(0,0,0,0.1);
}
.reaction-item.user-reaction {
    background: #667eea00;
    color: white;
}
.message-out .reaction-item.user-reaction {
    background: #5568d300;
}
.add-reaction-btn {
    background: none;
    border: 1px dashed #aaa;
    border-radius: 16px;
    padding: 2px 8px;
    font-size: 13px;
    cursor: pointer;
    color: #aaa;
    transition: all 0.2s;
}
.add-reaction-btn:hover {
    border-color: #afafaf;
    color: #afafaf;
}

.reaction-picker {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 30px;
    padding: 8px 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    gap: 10px;
    z-index: 1000;
}
.reaction-option {
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s;
}
.reaction-option:hover {
    transform: scale(1.3);
}

.message-reply-preview {
    background-color: rgba(0, 0, 0, 0.03);
    border-left: 3px solid #667eea;
    border-radius: 6px;
    padding: 8px 12px;
    margin: 8px 0 6px 0;
    font-size: 0.9em;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
}
.message-out .message-reply-preview {
    background-color: rgba(255, 255, 255, 0.1);
    border-left-color: #ffffff;
}
.message-reply-preview:hover {
    background-color: rgba(0, 0, 0, 0.06);
}
.message-out .message-reply-preview:hover {
    background-color: rgba(255, 255, 255, 0.15);
}
.reply-sender {
    font-weight: 600;
    color: #667eea;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.reply-sender::before {
    content: "↩️";
    font-size: 12px;
    opacity: 0.7;
}
.message-out .reply-sender {
    color: #ffffff;
}
.reply-content {
    color: #666;
    word-break: break-word;
    font-style: italic;
}
.message-out .reply-content {
    color: rgba(110, 110, 110, 0.8);
}
.reply-deleted {
    color: #999;
    font-style: italic;
}

.reply-preview-container {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-left: 4px solid #667eea;
}
.reply-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.reply-to-label {
    font-weight: bold;
    color: #667eea;
}
.reply-preview-text {
    color: #333;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#cancelReplyBtn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #999;
    margin-left: auto;
}
#cancelReplyBtn:hover {
    color: #333;
}

.message.highlight {
    background-color: rgba(0, 255, 221, 0.2);
    transition: background-color 0.5s;
    border-radius: 8px;
}

/* ========== МОБИЛЬНЫЙ ДИЗАЙН ДИАЛОГОВ (как в Telegram) ========== */
@media screen and (max-width: 768px) {
    /* Контейнер и отступы */
    .container {
        padding: 10px;
    }
    body {
        -webkit-text-size-adjust: 100%;
    }
    .main-container,
    .auth-container,
    .settings-container,
    .profile-container,
    .search-container {
        padding: 20px 15px;
    }
    .message {
        max-width: 20%;
        padding: 12px 16px;
        border-radius: 10px;
        position: relative;
    }
    /* Навигация */
    nav .container {
        flex-direction: column;
        padding: 10px;
    }
    .nav-right {
        margin-top: 10px;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }
    .nav-right a {
        margin: 0;
        padding: 8px 12px;
        font-size: 14px;
    }

    /* Кнопка создания чата */
    .btn-create-chat {
        width: 48px;
        height: 48px;
        font-size: 28px;
        bottom: 15px;
        right: 15px;
        transform: none;
        left: auto;
    }

    /* Стили для диалогов — главное исправление */
    /* .chat-item {
        display: flex;
        flex-wrap: nowrap !important;        /* Запрещаем перенос 
        align-items: center;
        padding: 12px 16px;
        gap: 12px;
    } */
    /* .chat-avatar {
        width: 48px;
        height: 48px;
        font-size: 20px;
        flex-shrink: 0;
    } */
    .chat-info {
        flex: 1;
        min-width: 0; /* важно для обрезания текста */
    }
    /* .chat-name {
        font-size: 16px;
        font-weight: 500;
        margin-bottom: 4px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    } */
    /* .chat-last-message {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 6px;
        font-size: 13px;
        width: 100%;
    } */
    .chat-last-message-text {
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 13px;
        line-height: 1.3;
    }
    .chat-last-message-time {
        font-size: 11px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .unread-badge {
        font-size: 12px;
        padding: 2px 6px;
        min-width: 20px;
        flex-shrink: 0;
        margin-left: 4px;
    }
    .pin-btn {
        font-size: 20px;
        margin-left: 6px;
        padding: 6px;
        flex-shrink: 0;
        opacity: 0.6;
    }
    .pin-btn:active {
        opacity: 1;
    }

    /* Секции */
    .section-header {
        margin: 20px 0 8px 0;
    }
    .section-header h2 {
        font-size: 14px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: #aaa;
    }

    /* Остальные мобильные стили (без изменений) */
    .modal-content {
        margin: 20% 5%;
        width: 90%;
        padding: 20px;
    }
    #messageText {
        padding: 12px;
        font-size: 16px !important;
    }
    .btn-send {
        padding: 10px 18px;
        font-size: 18px;
    }
    .btn-media {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    .profile-avatar {
        width: 100px;
        height: 100px;
        font-size: 40px;
    }
    .profile-header h1 {
        font-size: 24px;
    }
    .username {
        font-size: 18px;
    }
    .settings-form input[type="text"],
    .settings-form input[type="file"] {
        font-size: 14px;
        padding: 10px;
    }
    .current-photo {
        width: 80px;
        height: 80px;
        font-size: 30px;
    }
    .chat-header {
        padding: 12px;
    }
    .chat-avatar-large {
        width: 45px;
        height: 45px;
        font-size: 22px;
    }
    .chat-title h2 {
        font-size: 18px;
    }
    .chat-status,
    .chat-members-count {
        font-size: 12px;
    }
    .btn-secondary {
        padding: 6px 12px;
        font-size: 13px;
    }
    .member-item {
        padding: 10px;
    }
    .member-name {
        font-size: 14px;
    }
    .member-username {
        font-size: 12px;
    }
    .btn-remove-member {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    .reaction-picker {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: auto;
        max-width: 90vw;
        flex-wrap: wrap;
        justify-content: center;
        background: white;
        border-radius: 40px;
        padding: 12px 16px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.2);
        z-index: 2000;
    }
    .reaction-option {
        font-size: 32px;
        padding: 5px;
    }
    .video-modal video,
    .image-modal img {
        max-width: 95%;
        max-height: 80%;
    }
    .video-modal .close-video,
    .image-modal .close-image {
        top: 10px;
        right: 20px;
        font-size: 32px;
    }
    .auth-container {
        margin: 30px auto;
        padding: 25px 20px;
    }
    .auth-form input {
        padding: 12px;
        font-size: 16px;
    }
    .btn-primary {
        padding: 14px;
        font-size: 18px;
    }
}

/* Увеличенная область нажатия для тач-устройств */
@media (hover: none) and (pointer: coarse) {
    .nav-right a,
    .btn-primary,
    .btn-secondary,
    .btn-create-chat,
    .chat-item,
    .user-item,
    .member-item {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
    }
    .chat-item:hover,
    .user-item:hover,
    .member-item:hover {
        transform: none;
        background: inherit;
    }
    .chat-item:active,
    .user-item:active,
    .member-item:active {
        background: #6FDBC9;
        opacity: 0.8;
    }
}

/* Прочие элементы (не менялись) */
.message-forward-preview {
    background-color: rgba(0, 0, 0, 0.03);
    border-left: 3px solid #4bccc6;
    border-radius: 6px;
    padding: 4px 8px;
    margin: 4px 0 6px 0;
    font-size: 0.9em;
    color: #666;
}
.message-out .message-forward-preview {
    background-color: rgba(255, 255, 255, 0.1);
    border-left-color: #4bccc6;
    color: rgba(255,255,255,0.8);
}
.forward-sender {
    font-weight: 600;
    color: #ff9800;
}
.message-out .forward-sender {
    color: #ffb74d;
}
.forward-deleted {
    color: #999;
    font-style: italic;
}

.pin-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    margin-left: 4px;
    opacity: 0.5;
    transition: opacity 0.2s;
    color: #ccc;
    flex-shrink: 0;
}
.pin-btn:hover {
    opacity: 1;
}

.section-header {
    margin: 20px 0 12px 0;
    padding: 0 8px;
}
.section-header h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #aaa;
    margin: 0;
}

/* Адаптация для мобильных (дополнительно) */
@media (max-width: 768px) {
    .chat-item {
        padding: 10px 12px;
        /* gap: 10px; */
    }
    .chat-avatar {
        width: 44px;
        height: 44px;
        font-size: 18px;
        margin-right: 100px;
    }
    .chat-name {
        font-size: 15px;
    }
    .chat-last-message {
        font-size: 13px;
    }
    .chat-last-message-time {
        font-size: 11px;
    }
    .unread-badge {
        font-size: 11px;
        padding: 2px 6px;
        min-width: 18px;
    }
}

/* Скрываем навигацию на мобильных на странице чата */
@media (max-width: 768px) {
    body.chat-page nav {
        display: none;
    }
}

/* Замена иконок на эмодзи для мобильных, если шрифт не загружается */
@media (max-width: 768px) {
    .icon-gs:before {
        content: "🎤";
        font-size: 20px;
        font-family: inherit;
    }
    .icon-file:before {
        content: "📎";
        font-size: 20px;
        font-family: inherit;
    }
    .icon-circ:before {
        content: "📹";
        font-size: 20px;
        font-family: inherit;
    }
    .icon {
        font-family: inherit;
    }
}

@media screen and (max-width: 768px) {
    /* Скрываем скролл страницы и убираем отступы */
    body.chat-page {
        overflow: hidden;
        height: 100%;
        margin: 0;
        padding: 0;
    }

    /* Контейнер чата занимает весь экран */
    .chat-container {
        height: 100vh !important;
        max-height: 100vh !important;
        margin-top: 0 !important;
        border-radius: 0 !important;
        padding: 0 !important;
    }

    /* Хедер чата – компактный, кнопки в две строки */
    .chat-header {
        padding: 10px !important;
        
        align-items: flex-start !important;
        gap: 8px;
        background: #262626;
    }

    .chat-header-left {
        width: 100%;
        gap: 10px;
    }

    .chat-header-right {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-start;
    }

    .chat-header-right .btn-secondary,
    .chat-header-right .btn-danger {
        padding: 5px 10px;
        font-size: 12px;
        margin: 0;
    }

    /* Аватар и название */
    .chat-avatar-large {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    .chat-title h2 {
        font-size: 16px;
        margin-bottom: 2px;
    }

    .chat-status, .chat-members-count {
        font-size: 11px;
    }

    /* Контейнер сообщений – занимает всё оставшееся место */
    .messages-container {
        flex: 1;
        overflow-y: auto;
        padding: 10px;
    }

    /* Сообщения */
    .message {
        max-width: 85%;
        padding: 8px 12px;
        font-size: 14px;
    }

    .message-header {
        font-size: 11px;
    }

    /* Поле ввода – всегда внизу */
    .message-input-container {
        padding: 10px;
        border-top: 1px solid #444;
        background: #262626;
        width: 100%;
        box-sizing: border-box;
    }

    .input-wrapper {
        display: flex;
        gap: 2px;
        flex-wrap: nowrap; /* запрещаем перенос */
        align-items: center;
    }

    #messageText {
        flex: 1 1 auto;
        min-width: 0;         /* разрешаем сжатие */
        width: auto;
        font-size: 16px;      /* предотвращает автоматический zoom в iOS */
        padding: 8px 10px;
        line-height: 1.2;
        box-sizing: border-box;
    }
    .media-buttons {
        display: flex;
        gap: 2px;
        flex-shrink: 0;       /* кнопки не сжимаются */
    }
    .btn-media {
        width: 36px;
        height: 36px;
        font-size: 18px;
        flex-shrink: 0;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .btn-send {
        padding: 8px 12px;
        font-size: 18px;
        flex-shrink: 0;
        white-space: nowrap;
        line-height: 1;
        box-sizing: border-box;
    }

    /* Меню реакций на мобильных – прилипает снизу */
    .reaction-picker {
        position: fixed;
        bottom: 70px;
        left: 50%;
        transform: translateX(-50%);
        width: auto;
        max-width: 90%;
        flex-wrap: wrap;
        justify-content: center;
        background: white;
        border-radius: 40px;
        padding: 10px 16px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.2);
        z-index: 2000;
    }

    .reaction-option {
        font-size: 28px;
        padding: 5px;
    }

    /* Модальные окна */
    .modal-content {
        margin: 20% auto;
        width: 90%;
        padding: 20px;
    }

    /* Убираем скругление и отступы у основного контейнера */
    .main-container {
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    /* Скрываем приветствие на главной, если оно есть (оставлено для контекста) */
    .welcome-section {
        display: none;
    }

    

    

    
}

/* Уведомление об обновлении */
.update-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    padding: 12px 20px;
    border-radius: 40px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    font-size: 14px;
    font-weight: 500;
    backdrop-filter: blur(4px);
    transition: transform 0.2s;
}
.update-notification:hover {
    transform: translateY(-2px);
}
.update-notification button {
    background: white;
    border: none;
    padding: 6px 14px;
    border-radius: 30px;
    cursor: pointer;
    color: #007bff;
    font-weight: bold;
    transition: 0.2s;
}
.update-notification button:hover {
    background: #f0f0f0;
    transform: scale(1.02);
}