* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== СТИЛИ ДЛЯ СТАРТОВОЙ СТРАНИЦЫ (НЕ ТРОГАТЬ) ===== */
.container {
    background: white;
    padding: 2.5rem;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 400px;
    max-width: 90%;
    text-align: center;
}

h1 {
    font-size: 2.5rem;
    color: #333;
    margin-bottom: 1rem;
}

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

.subtitle {
    color: #666;
    margin-bottom: 2.5rem;
    font-size: 1.1rem;
}

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

.btn {
    padding: 0.8rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

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

.btn-secondary {
    background: #48bb78;
    color: white;
}

.form-group {
    margin-bottom: 1.2rem;
    text-align: left;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: #555;
    font-weight: 500;
}

input {
    width: 100%;
    padding: 0.8rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: #667eea;
}

.link {
    text-align: center;
    margin-top: 1.5rem;
}

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

.link a:hover {
    text-decoration: underline;
}

.error {
    color: #e53e3e;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    text-align: left;
}

.success {
    color: #48bb78;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.family-image {
    margin-bottom: 2rem;
    text-align: center;
}

.family-image img {
    max-width: 300px;
    width: 100%;
    height: auto;
    display: inline-block;
}

/* ===== СТИЛИ ДЛЯ ОСНОВНОГО ПРИЛОЖЕНИЯ ===== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 0 20px;
}

/* Верхняя панель - ИСПРАВЛЕННАЯ ВЕРСИЯ */
.header {
    background: transparent;
    color: white;
    padding: 2rem 2rem 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.header-left h2 {
    font-size: 2rem;
    color: white;
    margin: 0;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-left: auto;
    padding-left: 2rem;
}

#welcomeUser {
    margin-right: 1rem;
    font-size: 1rem;
    color: white;
    opacity: 0.9;
    font-weight: 400;
    padding-right: 0.5rem;
}

#welcomeUser #username {
    font-weight: 600;
    color: white;
}

.header .btn-icon {
    color: white;
    opacity: 0.8;
    font-size: 1.3rem;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
}

.header .btn-icon:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
    transform: translateY(-1px);
}

/* Основная колонка */
.main-column {
    background: transparent;
    border-radius: 10px;
    overflow: hidden;
    max-width: 800px;
    margin: 1rem auto 0;
    width: 100%;
}

/* Вкладки */
.tabs {
    display: flex;
    gap: 2rem;
    padding: 1rem;
    background: transparent;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.tab {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1rem;
    font-weight: 500;
    padding: 0.5rem 0;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.tab:hover {
    color: white;
}

.tab.active {
    color: white;
    font-weight: 600;
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: white;
    border-radius: 2px;
}

/* Контейнер для контента */
.tab-content {
    padding: 20px;
    background: rgba(255,255,255,0.95);
    border-radius: 0 0 10px 10px;
    min-height: 500px;
}

/* ===== СТИЛИ ДЛЯ ЧАТОВ ===== */
.chats-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-item {
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.chat-item:hover {
    background: #f8f9fa;
    border-color: #667eea;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.chat-item-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    width: 100%;
    position: relative;
}

.chat-type {
    font-size: 1.2rem;
    min-width: 30px;
}

.chat-name {
    font-weight: bold;
    flex: 1;
    color: #333;
}

.chat-time {
    font-size: 0.8rem;
    color: #999;
}

.chat-last-message {
    font-size: 0.9rem;
    color: #666;
    margin-left: 2rem;
    margin-bottom: 0.3rem;
}

.chat-meta {
    font-size: 0.8rem;
    color: #999;
    margin-left: 2rem;
    margin-top: 0.3rem;
}

/* Кнопка настроек группы */
.settings-btn {
    margin-left: auto;
    opacity: 0.5;
    transition: all 0.2s ease;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 5px;
    line-height: 1;
    color: #666;
}

.settings-btn:hover {
    opacity: 1;
    transform: scale(1.1);
    color: #333;
}

.chat-item:hover .settings-btn {
    opacity: 0.8;
}

/* ===== СТИЛИ ДЛЯ ПОИСКА ===== */
.search-box {
    margin-bottom: 20px;
}

.search-box input {
    width: 100%;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
}

.search-box input:focus {
    outline: none;
    border-color: #667eea;
}

.search-results {
    margin-top: 10px;
    max-height: 300px;
    overflow-y: auto;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    display: none;
}

.search-results-list {
    padding: 1rem;
    overflow-y: auto;
    max-height: calc(100vh - 250px);
}

.search-result-item {
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: #f5f5f5;
}

.user-name {
    font-weight: 500;
}

/* ===== СТИЛИ ДЛЯ СОЗДАНИЯ ЧАТА / ПОИСКА (одинаковая «карточка» вкладки) ===== */
.create-chat-container,
.search-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 420px;
}

.secondary-tabs {
    display: flex;
    gap: 1rem;
    background: #f5f5f5;
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 20px;
}

.secondary-tabs .tab {
    flex: 1;
    padding: 0.8rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: #666;
    transition: all 0.2s;
}

.secondary-tabs .tab.active {
    background: white;
    color: #667eea;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.create-chat-section {
    display: none;
}

.create-chat-section.active {
    display: block;
}

.selected-user, .selected-users {
    margin: 15px 0;
    padding: 15px;
    background: #f5f5f5;
    border-radius: 8px;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: #667eea;
    color: white;
    border-radius: 20px;
    margin: 3px;
    font-size: 0.9rem;
}

.user-chip .btn-small {
    background: rgba(255,255,255,0.2);
    padding: 2px 5px;
    border: none;
    border-radius: 3px;
    color: white;
    cursor: pointer;
}

.user-chip .btn-small:hover {
    background: rgba(255,255,255,0.3);
}

.selected-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 10px;
}

.empty-selection {
    color: #999;
    font-style: italic;
    text-align: center;
    padding: 10px;
}

/* ===== КНОПКИ ===== */
.btn-small {
    padding: 6px 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

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

.btn-primary {
    background: #667eea;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

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

.btn-primary:disabled {
    background: #a0aec0;
    cursor: not-allowed;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

.btn-danger {
    background: #e53e3e;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

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

.btn-warning {
    background: #f59e0b;
    color: white;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-icon-small {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 3px 5px;
    border-radius: 3px;
    transition: background 0.2s;
}

.btn-icon-small:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* ===== МОДАЛЬНЫЕ ОКНА ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin-bottom: 15px;
    color: #333;
}

.modal-content textarea {
    width: 100%;
    min-height: 100px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 15px;
}

.modal-content textarea:focus {
    outline: none;
    border-color: #667eea;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 15px;
}

.warning {
    color: #e53e3e;
    font-weight: bold;
    margin: 1rem 0;
}

/* Preview modal */
.preview-content {
    max-width: 500px;
}

.preview-info {
    margin: 1rem 0;
    padding: 1rem;
    background: #f5f5f5;
    border-radius: 5px;
}

.preview-participants {
    margin-top: 1rem;
}

.preview-participants ul {
    margin: 0.5rem 0 0 1.5rem;
    color: #666;
}

.preview-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* ===== СТРАНИЦА ПРОФИЛЯ ===== */
.profile-container {
    max-width: 800px;
    margin: 2rem auto;
    padding: 2rem;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.back-link {
    color: #667eea;
    text-decoration: none;
}

.profile-card {
    text-align: center;
}

.profile-avatar {
    margin-bottom: 2rem;
}

.avatar-placeholder {
    width: 100px;
    height: 100px;
    background: #667eea;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: white;
    margin: 0 auto;
}

.profile-info {
    text-align: left;
    margin-bottom: 2rem;
}

.info-row {
    display: flex;
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
}

.info-row label {
    width: 120px;
    font-weight: bold;
    color: #555;
}

.user-id {
    font-family: monospace;
    font-size: 0.9rem;
    color: #999;
}

/* ===== СТРАНИЦА ЧАТА (мобильный viewport: не 100vh — учитываем панели браузера; flex + min-height:0 — скролл в ленте) ===== */
/* Важно: глобальный `body { min-height: 100vh }` выше по файлу. На телефоне 100vh часто > видимой области,
   тело становится выше 100dvh → при overflow:hidden нижняя панель ввода оказывается за кадром. */
html.page-chat-root,
body.page-chat {
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
}

@supports (height: 100svh) {
    html.page-chat-root,
    body.page-chat {
        height: 100svh;
        max-height: 100svh;
        min-height: 100svh;
    }
}

body.page-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    margin: 0;
    background: #f5f5f5;
    padding-bottom: 0;
    box-sizing: border-box;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    align-self: stretch;
    background: #f5f5f5;
}

.chat-header {
    flex-shrink: 0;
    background: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    gap: 0.5rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.chat-type-badge {
    padding: 0.3rem 0.8rem;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: bold;
}

.chat-type-badge.group {
    background: #667eea;
    color: white;
}

.chat-type-badge.private {
    background: #48bb78;
    color: white;
}

/* flex-basis: 0 — иначе на мобильных WebKit минимальная высота = высота всего контента,
   лента выталкивает .message-input-container за пределы 100dvh → поле ввода «пропадает». */
.messages-container {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 1rem 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 70%;
    padding: 0.8rem 1rem;
    border-radius: 10px;
    position: relative;
    animation: fadeIn 0.3s;
}

.message.own {
    align-self: flex-end;
    background: #667eea;
    color: white;
}

.message:not(.own) {
    align-self: flex-start;
    background: white;
    color: #333;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
}

.message.own .message-header {
    color: rgba(255,255,255,0.8);
}

.message:not(.own) .message-header {
    color: #666;
}

.message-sender {
    font-weight: bold;
}

.message-content {
    word-wrap: break-word;
    line-height: 1.4;
}

.message-input-container {
    position: relative;
    flex-shrink: 0;
    z-index: 2;
    background: white;
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    border-top: 1px solid #e0e0e0;
    box-sizing: border-box;
}

.compose-emoji-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #eef2ff;
    color: #4c51bf;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.compose-emoji-btn:active {
    transform: scale(0.96);
}

.compose-emoji-popover {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    max-width: min(100vw - 2rem, 320px);
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 50;
}

.compose-emoji-popover.is-open {
    display: flex;
}

.compose-insert-btn {
    border: none;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 1.35rem;
    line-height: 1;
    padding: 6px 8px;
    cursor: pointer;
}

.compose-insert-btn:active {
    transform: scale(0.95);
}

.context-reaction-menu {
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 280px;
    padding: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.context-reaction-pick {
    border: none;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 1.35rem;
    line-height: 1;
    padding: 6px 8px;
    cursor: pointer;
}

.context-reaction-pick:active {
    transform: scale(0.95);
}

.message-input-container textarea {
    flex: 1;
    padding: 0.8rem;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    max-height: 100px;
}

.message-input-container textarea:focus {
    outline: none;
    border-color: #667eea;
}

.message-input-container button {
    padding: 0 1.25rem;
    border-radius: 20px;
    flex-shrink: 0;
}

/* Реакции под сообщением (ПКМ → выбор; пилюля как в референсе) */
.message-reactions-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.message-reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px 2px 4px;
    border-radius: 999px;
    background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
    color: #fff;
    font-size: 0.85rem;
    line-height: 1.2;
    box-shadow: 0 1px 3px rgba(14, 165, 233, 0.35);
}

.message-reaction-pill-emoji {
    font-size: 1.1rem;
    line-height: 1;
}

.message-reaction-pill-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    color: #0369a1;
    font-size: 0.7rem;
    font-weight: 700;
}

@media (max-width: 600px) {
    .chat-header {
        padding: 0.6rem 0.75rem;
    }

    .header-left h2 {
        font-size: 1rem;
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .messages-container {
        padding: 0.65rem 0.65rem 0.5rem;
    }

    .message {
        max-width: 92%;
    }

    .message-input-container {
        padding-left: 0.65rem;
        padding-right: 0.65rem;
    }

    /* Панель ввода к низу viewport — обходит flex/100vh на мобильном Chrome. */
    body.page-chat .message-input-container {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        z-index: 100;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
    }

    body.page-chat .messages-container {
        padding-bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
    }
}

/* ===== СТРАНИЦА НАСТРОЕК ГРУППЫ ===== */
.settings-container {
    max-width: 800px;
    margin: 2rem auto;
    padding: 2rem;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.settings-header {
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e0e0e0;
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.info-section, .participants-section, .danger-zone {
    padding: 1rem;
    background: #f9f9f9;
    border-radius: 5px;
}

.info-section h3, .participants-section h3, .danger-zone h3 {
    margin-bottom: 1rem;
    color: #333;
}

.info-row {
    display: flex;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e0e0e0;
}

.info-row:last-child {
    border-bottom: none;
}

.info-row label {
    width: 100px;
    font-weight: bold;
    color: #666;
}

.mono {
    font-family: monospace;
    font-size: 0.9rem;
    color: #999;
}

.role-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    background: #667eea;
    color: white;
    border-radius: 3px;
    font-size: 0.8rem;
}

.add-participant {
    position: relative;
    margin-bottom: 1rem;
}

.add-participant input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
}

.participant-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem;
    border-bottom: 1px solid #e0e0e0;
}

.participant-item:last-child {
    border-bottom: none;
}

.participant-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.participant-name {
    font-weight: 500;
}

.owner-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
    background: #48bb78;
    color: white;
    border-radius: 3px;
}

.danger-zone {
    border: 1px solid #fc8181;
}

.danger-zone h3 {
    color: #e53e3e;
}

.danger-actions {
    display: flex;
    justify-content: flex-end;
}

/* ===== ВСПОМОГАТЕЛЬНЫЕ КЛАССЫ ===== */
.loading {
    text-align: center;
    color: #999;
    padding: 2rem;
}

.error {
    text-align: center;
    color: #ff4444;
    padding: 2rem;
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 40px;
    font-size: 1.1rem;
}

.empty-chats {
    text-align: center;
    color: #999;
    padding: 2rem;
}

.empty-messages {
    flex-shrink: 0;
    text-align: center;
    color: #999;
    padding: 1.5rem 0.5rem;
    font-size: 1.05rem;
}

.loading-messages {
    text-align: center;
    color: #999;
    padding: 2rem;
}

.info-message {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 5px;
    text-align: center;
}

/* ===== АНИМАЦИИ ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== МЕДИА-ЗАПРОСЫ ===== */
@media (max-width: 768px) {
    .app-container {
        padding: 10px;
    }

    .header {
        padding: 1.5rem 1rem 0.8rem 1rem;
    }

    .chat-item-header {
        flex-wrap: wrap;
    }

    .chat-time {
        width: 100%;
        margin-left: 40px;
    }
}

@media (max-width: 600px) {
    /* Только legacy-шапка .header — не трогать .chat-header .header-right (иконки чата) */
    .header {
        flex-direction: column;
        gap: 0.8rem;
        text-align: center;
    }

    .header > .header-right {
        width: 100%;
        justify-content: center;
        padding-left: 0;
    }

    #welcomeUser {
        margin-right: 0.5rem;
    }

    .tabs {
        gap: 1rem;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .header-left h2 {
        font-size: 1.5rem;
    }

    .tab {
        font-size: 0.9rem;
        padding: 0.4rem 0;
    }

    .chat-last-message {
        margin-left: 30px;
        font-size: 0.8rem;
    }

    .chat-meta {
        margin-left: 30px;
    }
}

/* ===== СТИЛИ ДЛЯ ПОЛЯ ПАРОЛЯ С ГЛАЗИКОМ ===== */
.password-input-container {
    position: relative;
    width: 100%;
}

.password-input-container input {
    width: 100%;
    padding-right: 40px; /* Оставляем место для кнопки */
}

.toggle-password {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px;
    color: #666;
    transition: color 0.2s;
    z-index: 10;
}

.toggle-password:hover {
    color: #667eea;
}

.toggle-password:focus {
    outline: none;
}

/* ===== СТИЛИ ДЛЯ WEBSOCKET ===== */
.typing-indicator {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.9);
    border-top: 1px solid #e0e0e0;
    font-size: 0.9rem;
    color: #666;
    font-style: italic;
    display: none;
    animation: fadeIn 0.3s;
    z-index: 100;
}

/* ===== СТИЛИ ДЛЯ ЗВУКОВЫХ УВЕДОМЛЕНИЙ ===== */
#soundToggleBtn {
    font-size: 1.2rem;
    transition: transform 0.2s;
}

#soundToggleBtn:hover {
    transform: scale(1.1);
}

.sound-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    z-index: 9999;
    font-size: 0.9rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    pointer-events: none;
}

/* ===== СТИЛИ ДЛЯ ЗВУКОВЫХ УВЕДОМЛЕНИЙ ===== */
.sound-toggle {
    font-size: 1.2rem;
    transition: all 0.2s ease;
    cursor: pointer;
    background: none;
    border: none;
    padding: 8px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sound-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.sound-toggle:active {
    transform: scale(0.95);
}

.sound-toggle:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sound-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 10000;
    animation: slideIn 0.3s ease;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    pointer-events: none;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Стили для кнопки в профиле */
.sound-toggle-btn {
    min-width: 100px;
    transition: all 0.2s;
    font-size: 14px;
    padding: 6px 12px;
}

.sound-toggle-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.sound-toggle-btn.btn-enabled {
    background: #667eea;
    color: white;
}

.sound-toggle-btn.btn-disabled {
    background: #e0e0e0;
    color: #666;
}

/* ===== БЕЙДЖИ НЕПРОЧИТАННЫХ СООБЩЕНИЙ ===== */
.unread-badge {
    background: #e53e3e;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    margin-left: 5px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.4);
    }
    70% {
        box-shadow: 0 0 0 5px rgba(229, 62, 62, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(229, 62, 62, 0);
    }
}

/* Статус прочтения в сообщениях */
.read-status {
    font-size: 0.7rem;
    margin-left: 5px;
    color: #48bb78;
    opacity: 0.8;
}

.message.own .read-status {
    color: rgba(255, 255, 255, 0.8);
}

/* ===== ГЛОБАЛЬНЫЙ ИНДИКАТОР ПЕЧАТИ ===== */
.typing-indicator-global {
    font-size: 0.85rem;
    color: #667eea;
    font-style: italic;
    margin-left: 2rem;
    padding: 2px 0;
    animation: pulse 1.5s infinite;
}

.typing-indicator-global::before {
    content: '✏️ ';
    font-size: 0.8rem;
    opacity: 0.7;
}

/* Toast notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 10000;
    max-width: 320px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast-error {
    background: #c62828;
    color: #fff;
}
.toast-success {
    background: #2e7d32;
    color: #fff;
}

.toast-info {
    background: #1565c0;
    color: #fff;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0.6;
    }
}

/* ===== E2E: список действий (стиль «меню», светлая тема приложения) ===== */
.e2e-action-sheet {
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 12px;
    box-shadow: 0 2px 14px rgba(15, 23, 42, 0.08);
    overflow: hidden;
}

.e2e-action-sheet--in-banner {
    margin-top: 0.5rem;
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(99, 102, 241, 0.2);
    box-shadow: 0 2px 12px rgba(79, 70, 229, 0.1);
}

.e2e-action-sheet--modal {
    margin-top: 0.75rem;
}

.modal-content--chat-actions #deleteChatConfirmText {
    margin: 0 0 0.5rem;
    line-height: 1.45;
    color: #334155;
    font-size: 0.95rem;
}

.e2e-action-sheet--profile {
    margin-top: 0.65rem;
}

.e2e-action-divider {
    height: 1px;
    background: rgba(15, 23, 42, 0.08);
    margin: 0;
    border: 0;
}

.e2e-action-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.85rem 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    color: #0f172a;
    text-align: left;
    transition: background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.e2e-action-row:hover {
    background: rgba(15, 23, 42, 0.04);
}

.e2e-action-row:focus {
    outline: none;
}

.e2e-action-row:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: -2px;
    background: rgba(102, 126, 234, 0.06);
}

.e2e-action-row:active {
    background: rgba(15, 23, 42, 0.07);
}

.e2e-action-row__icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
}

.e2e-action-row--accent .e2e-action-row__icon {
    color: #4f46e5;
}

.e2e-action-row--muted .e2e-action-row__icon {
    color: #94a3b8;
}

.e2e-action-row--muted .e2e-action-row__label {
    color: #64748b;
}

.e2e-action-row--danger .e2e-action-row__icon,
.e2e-action-row--danger .e2e-action-row__label {
    color: #c62828;
}

.e2e-action-row--danger:hover {
    background: rgba(198, 40, 40, 0.06);
}

.e2e-action-row--danger:focus-visible {
    outline-color: #c62828;
    background: rgba(198, 40, 40, 0.08);
}

.e2e-action-row__label {
    flex: 1;
    line-height: 1.35;
}

.e2e-action-row__chev {
    flex-shrink: 0;
    font-size: 1.35rem;
    font-weight: 300;
    color: #cbd5e1;
    line-height: 1;
    margin-right: -2px;
}

.e2e-action-svg {
    width: 22px;
    height: 22px;
    display: block;
}

.e2e-profile-device-hint {
    margin: 0.5rem 0 0;
    font-size: 0.82rem;
    color: #64748b;
    line-height: 1.4;
}

/* ===== E2E: подсказка в приватном чате после recovery phrase (второе устройство) ===== */
.e2e-chat-phrase-notice {
    flex-shrink: 0;
    margin: 0 0 12px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #7dd3fc;
    border-radius: 10px;
    color: #0c4a6e;
}

.e2e-chat-phrase-notice-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
}

.e2e-chat-phrase-notice-text {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.45;
}

/* ===== E2E: баннер и восстановление на главной ===== */
.e2e-recovery-banner {
    margin: 0 0 1rem;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    border: 1px solid #c7d2fe;
    border-radius: 10px;
    color: #1e1b4b;
}

.e2e-recovery-banner-text {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    line-height: 1.45;
}

.e2e-phrase-modal-content .e2e-phrase-intro {
    margin: 0 0 1rem;
    line-height: 1.45;
    color: #333;
}

.e2e-recovery-phrase {
    margin: 0 0 0.75rem;
    padding: 1rem 1.1rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
    font-size: 1.05rem;
    line-height: 1.5;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #1a202c;
    background: #f7fafc;
    border: 2px dashed #667eea;
    border-radius: 8px;
    word-break: break-word;
    user-select: text;
    cursor: text;
}

.e2e-phrase-warning {
    margin: 0 0 1rem;
    font-size: 0.85rem;
    color: #744210;
}

.e2e-status-line {
    margin: 0.35rem 0 0;
    font-size: 0.9rem;
    color: #4a5568;
    line-height: 1.4;
}

/* ===== E2E: привязка устройства ===== */
.e2e-pair-modal-content .e2e-pair-hint {
    margin: 0 0 0.75rem;
    line-height: 1.45;
    color: #444;
}

.e2e-pair-qr-wrap {
    display: flex;
    justify-content: center;
    margin: 10px 0;
    min-height: 0;
    align-items: center;
    padding: 12px;
    background: #ffffff;
    border-radius: 12px;
    box-sizing: border-box;
}

.e2e-pair-qr-wrap canvas,
.e2e-pair-qr-wrap img {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    max-width: min(240px, 70vw);
    max-height: min(240px, 38vh);
    width: auto;
    height: auto;
}

.e2e-pair-modal-content.modal-content {
    max-height: min(92dvh, 100vh - 24px);
    overflow-y: auto;
    box-sizing: border-box;
}

.e2e-pair-copy-btn {
    margin-top: 0.75rem;
    width: 100%;
}

.e2e-pair-status {
    min-height: 2.75rem;
    margin: 0.5rem 0 0;
    font-size: 0.9rem;
    color: #2d3748;
    line-height: 1.4;
}

.e2e-pair-close-sheet {
    margin-top: 1rem;
}

.e2e-pair-device-status {
    font-size: 1rem;
    line-height: 1.5;
    color: #2d3748;
}

.e2e-pair-post-modal .e2e-pair-disclaimer-text {
    margin: 0 0 0.75rem;
    line-height: 1.5;
    color: #2d3748;
    font-size: 0.95rem;
}

.e2e-pair-post-modal .e2e-pair-disclaimer-note {
    margin: 0 0 1rem;
    font-size: 0.9rem;
    color: #4a5568;
    line-height: 1.45;
}

.e2e-pair-post-modal .e2e-pair-password-hint {
    margin: 0 0 1rem;
    font-size: 0.95rem;
    color: #4a5568;
    line-height: 1.45;
}

.e2e-pair-post-modal #pairConfirmUsername {
    background: #f7fafc;
    color: #2d3748;
    cursor: default;
}
