/* ============================================
   СТеплом Messenger — Styles
   ============================================ */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f0f2f5;
    --bg-chat: #e5ddd5;
    --bg-sidebar: #ffffff;
    --bg-header: #2AABEE;
    --bg-input: #ffffff;
    --bg-msg-in: #ffffff;
    --bg-msg-out: #EFFDDE;
    --bg-hover: #f5f5f5;
    --bg-modal: #ffffff;

    --text-primary: #000000;
    --text-secondary: #707579;
    --text-white: #ffffff;
    --text-link: #2AABEE;
    --text-danger: #e53935;

    --accent: #2AABEE;
    --accent-dark: #229ED9;
    --accent-light: #e3f2fd;

    --border: #e0e0e0;
    --shadow: rgba(0,0,0,0.1);

    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --font-size: 16px;
    --msg-radius: 12px;

    --sidebar-width: 380px;
    --header-height: 56px;
    --input-height: 56px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #17212b;
    --bg-secondary: #0e1621;
    --bg-chat: #0e1621;
    --bg-sidebar: #17212b;
    --bg-header: #242f3d;
    --bg-input: #242f3d;
    --bg-msg-in: #182533;
    --bg-msg-out: #2b5278;
    --bg-hover: #202b36;
    --bg-modal: #17212b;

    --text-primary: #f5f5f5;
    --text-secondary: #708499;
    --text-link: #6ab2f2;
    --text-danger: #e53935;

    --accent: #6ab2f2;
    --accent-dark: #5a9fd4;
    --accent-light: #1e3a5f;

    --border: #293a4a;
    --shadow: rgba(0,0,0,0.3);
}

[data-theme="blue"] {
    --bg-primary: #1a237e;
    --bg-secondary: #0d1b4a;
    --bg-chat: #0d1b4a;
    --bg-sidebar: #1a237e;
    --bg-header: #283593;
    --bg-input: #283593;
    --bg-msg-in: #1e3a6e;
    --bg-msg-out: #1565c0;
    --bg-hover: #1e3a6e;
    --bg-modal: #1a237e;

    --text-primary: #e8eaf6;
    --text-secondary: #9fa8da;
    --text-white: #ffffff;
    --text-link: #82b1ff;

    --accent: #448aff;
    --border: #3949ab;
}

[data-theme="green"] {
    --bg-primary: #1b5e20;
    --bg-secondary: #0d3311;
    --bg-chat: #0d3311;
    --bg-sidebar: #1b5e20;
    --bg-header: #2e7d32;
    --bg-input: #2e7d32;
    --bg-msg-in: #1a4a1e;
    --bg-msg-out: #388e3c;
    --bg-hover: #1a4a1e;
    --bg-modal: #1b5e20;

    --text-primary: #e8f5e9;
    --text-secondary: #a5d6a7;
    --text-link: #69f0ae;

    --accent: #4caf50;
    --border: #388e3c;
}

/* ============================================
   RESET & BASE
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size);
    color: var(--text-primary);
    background: var(--bg-secondary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

input, textarea, select, button {
    font-family: inherit;
    font-size: inherit;
}

a { color: var(--text-link); text-decoration: none; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-secondary); border-radius: 3px; }

/* ============================================
   SCREENS
   ============================================ */
.screen {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1;
}

.screen.active {
    display: flex;
}

/* ============================================
   SPLASH SCREEN
   ============================================ */
#splash-screen {
    background: linear-gradient(135deg, #2AABEE, #229ED9);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.splash-content {
    text-align: center;
    color: white;
}

.splash-logo .logo-icon {
    font-size: 80px;
    margin-bottom: 16px;
    animation: pulse 1.5s ease-in-out infinite;
}

.logo-text {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 8px;
}

.logo-subtitle {
    font-size: 16px;
    opacity: 0.8;
}

.splash-loader {
    margin-top: 40px;
    width: 200px;
    height: 3px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    overflow: hidden;
    margin-left: auto;
    margin-right: auto;
}

.loader-bar {
    width: 0%;
    height: 100%;
    background: white;
    border-radius: 2px;
    animation: loading 2s ease-in-out forwards;
}

@keyframes loading {
    0% { width: 0%; }
    100% { width: 100%; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ============================================
   AUTH SCREEN
   ============================================ */
#auth-screen {
    background: var(--bg-primary);
    justify-content: center;
    align-items: center;
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 24px;
    text-align: center;
}

.auth-logo {
    margin-bottom: 32px;
}

.auth-logo .logo-icon {
    font-size: 64px;
    margin-bottom: 8px;
}

.auth-logo h1 {
    font-size: 28px;
    color: var(--accent);
}

.auth-step {
    display: none;
}

.auth-step.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.auth-step h2 {
    font-size: 22px;
    margin-bottom: 8px;
}

.auth-step p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 14px;
}

.phone-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.phone-input-group select {
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
}

.phone-input-group select:focus {
    border-color: var(--accent);
}

.phone-input-group input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 18px;
    outline: none;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.phone-input-group input:focus {
    border-color: var(--accent);
}

/* Поля ввода на экране входа и в окнах (раньше стиля не было вовсе) */
.input-field {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    margin-bottom: 12px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    outline: none;
    background: var(--bg-primary);
    color: var(--text-primary);
}
.input-field:focus { border-color: var(--accent); }
.input-field.hidden { display: none; }
.auth-step .btn-text.btn-full { width: 100%; margin-top: 12px; }
.modal-small .input-field { margin-top: 4px; }

.code-input-group {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 24px;
}

.code-digit {
    width: 48px;
    height: 56px;
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    border: 2px solid var(--border);
    border-radius: 12px;
    outline: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.code-digit:focus {
    border-color: var(--accent);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-text {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 14px;
    cursor: pointer;
    margin-top: 16px;
    padding: 8px;
}

.btn-danger {
    padding: 10px 24px;
    background: var(--text-danger);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

.resend-timer {
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Profile Setup */
.profile-setup {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.avatar-upload {
    cursor: pointer;
}

.avatar-preview {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    overflow: hidden;
    border: 3px solid var(--accent);
    transition: transform 0.2s;
}

.avatar-preview:hover {
    transform: scale(1.05);
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-setup input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    outline: none;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.profile-setup input:focus {
    border-color: var(--accent);
}

/* ============================================
   APP LAYOUT
   ============================================ */
#app-screen {
    background: var(--bg-secondary);
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    background: var(--bg-primary);
    box-shadow: 0 0 20px var(--shadow);
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    position: relative;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    height: var(--header-height);
    background: var(--bg-header);
    color: var(--text-white);
}

.sidebar-header .btn-icon {
    color: var(--text-white);
}

.search-bar {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 20px;
    padding: 6px 12px;
}

.search-bar svg {
    opacity: 0.7;
    flex-shrink: 0;
}

.search-bar input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: inherit;
    font-size: 14px;
}

.search-bar input::placeholder {
    color: rgba(255,255,255,0.7);
}

.modal-body .search-bar {
    background: var(--bg-secondary);
    margin-bottom: 16px;
    padding: 10px 16px;
}

.modal-body .search-bar input {
    color: var(--text-primary);
}

.modal-body .search-bar input::placeholder {
    color: var(--text-secondary);
}

.modal-body .search-bar svg {
    color: var(--text-secondary);
}

/* Search Results */
.search-results {
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 10;
    overflow-y: auto;
}

/* Chat List */
.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--accent-light);
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: white;
    overflow: hidden;
    position: relative;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #4caf50;
    border-radius: 50%;
    border: 2px solid var(--bg-primary);
}

.chat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-info-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-info-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-last-msg {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-badge {
    background: var(--accent);
    color: white;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
}

/* FAB */
.fab {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(42,171,238,0.4);
    transition: all 0.2s;
    z-index: 5;
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(42,171,238,0.5);
}

/* ============================================
   CHAT VIEW
   ============================================ */
.chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    position: relative;
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.chat-empty .empty-icon {
    font-size: 80px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-empty h3 {
    font-size: 20px;
    margin-bottom: 8px;
}

.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: var(--header-height);
    background: var(--bg-header);
    color: var(--text-white);
    flex-shrink: 0;
}

.btn-back {
    display: none;
}

.chat-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    min-width: 0;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: white;
    overflow: hidden;
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-text {
    min-width: 0;
}

.chat-header-name {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: 13px;
    opacity: 0.8;
}

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

/* Search in Chat */
.chat-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
}

.chat-search-bar input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    outline: none;
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.chat-search-bar span {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Pinned Bar */
.pinned-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.pinned-bar:hover {
    background: var(--bg-hover);
}

.pinned-icon {
    font-size: 16px;
}

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

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background-size: cover;
    background-position: center;
}

/* Message Bubbles */
.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: msgIn 0.2s ease;
}

.message-wrapper.out {
    align-self: flex-end;
}

.message-wrapper.in {
    align-self: flex-start;
}

.message-bubble {
    padding: 8px 12px;
    border-radius: var(--msg-radius);
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
    cursor: default;
}

.message-wrapper.out .message-bubble {
    background: var(--bg-msg-out);
    border-bottom-right-radius: 4px;
}

.message-wrapper.in .message-bubble {
    background: var(--bg-msg-in);
    border-bottom-left-radius: 4px;
}

.message-sender {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 2px;
}

.message-text {
    font-size: var(--font-size);
    color: var(--text-primary);
}

.message-text a {
    color: var(--text-link);
    text-decoration: underline;
}

.message-media {
    max-width: 300px;
    border-radius: 8px;
    overflow: hidden;
    margin: 4px 0;
}

.message-media img {
    width: 100%;
    display: block;
    cursor: pointer;
}

.message-media video {
    width: 100%;
    display: block;
    border-radius: 8px;
    max-height: 400px;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    margin: 4px 0;
    cursor: pointer;
}

.message-file-icon {
    font-size: 32px;
}

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

.message-file-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.message-voice {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
}

.voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.voice-waveform {
    flex: 1;
    height: 30px;
    display: flex;
    align-items: center;
    gap: 2px;
}

.voice-bar {
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    opacity: 0.5;
}

.voice-bar.active {
    opacity: 1;
}

.voice-duration {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.message-sticker {
    width: 150px;
    height: 150px;
}

.message-sticker img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.message-reply {
    padding: 6px 10px;
    border-left: 3px solid var(--accent);
    background: rgba(42,171,238,0.1);
    border-radius: 4px;
    margin-bottom: 4px;
    font-size: 13px;
    cursor: pointer;
}

.message-reply-name {
    font-weight: 600;
    color: var(--accent);
    font-size: 12px;
}

.message-reply-text {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.message-edited {
    font-size: 11px;
    color: var(--text-secondary);
}

.message-status-icon {
    font-size: 14px;
}

.message-pinned-badge {
    font-size: 11px;
    color: var(--accent);
    margin-right: 4px;
}

/* Reactions */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.reaction-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--accent-light);
    border-radius: 12px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.reaction-badge:hover {
    background: var(--accent);
    color: white;
}

.reaction-badge.own {
    background: var(--accent);
    color: white;
}

.reaction-count {
    font-size: 12px;
    font-weight: 500;
}

/* Date Separator */
.date-separator {
    text-align: center;
    margin: 16px 0;
}

.date-separator span {
    background: rgba(0,0,0,0.15);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13px;
}

/* System Message */
.system-message {
    text-align: center;
    margin: 8px 0;
}

.system-message span {
    background: rgba(0,0,0,0.08);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13px;
}

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

/* Reply Bar */
.reply-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
}

.reply-content {
    flex: 1;
    border-left: 3px solid var(--accent);
    padding-left: 8px;
    min-width: 0;
}

.reply-bar .reply-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.reply-bar .reply-text {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Input Area */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 8px 12px;
    background: var(--bg-input);
    border-top: 1px solid var(--border);
    min-height: var(--input-height);
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 4px 8px;
    min-height: 40px;
    position: relative;
}

.message-input {
    flex: 1;
    max-height: 120px;
    overflow-y: auto;
    padding: 8px;
    outline: none;
    font-size: var(--font-size);
    line-height: 1.4;
    color: var(--text-primary);
    word-wrap: break-word;
}

.message-input:empty:before {
    content: attr(placeholder);
    color: var(--text-secondary);
    pointer-events: none;
}

.btn-emoji {
    font-size: 22px;
    padding: 4px;
    flex-shrink: 0;
}

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

.btn-icon:hover {
    background: var(--bg-hover);
}

.chat-header .btn-icon,
.sidebar-header .btn-icon {
    color: var(--text-white);
}

.chat-header .btn-icon:hover,
.sidebar-header .btn-icon:hover {
    background: rgba(255,255,255,0.15);
}

.btn-send {
    background: var(--accent);
    color: white !important;
}

.btn-send:hover {
    background: var(--accent-dark) !important;
}

.btn-voice {
    color: var(--accent) !important;
}

.btn-voice.recording {
    color: var(--text-danger) !important;
    animation: pulse 0.8s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { 
        transform: scale(1); 
        opacity: 1; 
    }
    50% { 
        transform: scale(1.15); 
        opacity: 0.8; 
    }
}
/* ============================================
   MODALS
   ============================================ */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-modal);
    border-radius: 12px;
    overflow: hidden;
    max-height: 90vh;
    max-width: 90vw;
}

.modal-fullscreen {
    width: 100%;
    max-width: 420px;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.modal-small {
    width: 320px;
    padding: 24px;
    text-align: center;
    border-radius: 16px;
}

.modal-small h3 {
    margin-bottom: 8px;
}

.modal-small p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    height: var(--header-height);
    background: var(--bg-header);
    color: var(--text-white);
    flex-shrink: 0;
}

.modal-header h3 {
    flex: 1;
    font-size: 18px;
}

.modal-header .btn-icon {
    color: var(--text-white);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* ============================================
   SETTINGS
   ============================================ */
.settings-profile {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.settings-profile:hover {
    background: var(--bg-hover);
}

.settings-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
    color: white;
    overflow: hidden;
    flex-shrink: 0;
}

.settings-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.settings-name {
    font-weight: 600;
    font-size: 17px;
}

.settings-phone {
    font-size: 14px;
    color: var(--text-secondary);
}

.settings-username {
    font-size: 14px;
    color: var(--text-link);
}

.settings-group {
    padding: 8px 0;
    border-bottom: 8px solid var(--bg-secondary);
}

.group-title {
    padding: 12px 16px 8px;
    font-size: 14px;
    color: var(--accent);
    font-weight: 600;
}

.settings-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    cursor: pointer;
    transition: background 0.15s;
}

.settings-item:hover {
    background: var(--bg-hover);
}

.settings-item.danger {
    color: var(--text-danger);
}

.settings-icon {
    font-size: 22px;
    width: 28px;
    text-align: center;
}

.settings-label {
    flex: 1;
    font-size: 15px;
}

.settings-arrow {
    font-size: 20px;
    color: var(--text-secondary);
}

.settings-footer {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Switch */
.switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border);
    border-radius: 12px;
    transition: 0.3s;
}

.slider:before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.switch input:checked + .slider {
    background: var(--accent);
}

.switch input:checked + .slider:before {
    transform: translateX(20px);
}

/* Theme Grid */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 12px 16px;
}

.theme-option {
    text-align: center;
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.theme-option:hover {
    border-color: var(--accent);
}

.theme-option.active {
    border-color: var(--accent);
    background: var(--accent-light);
}

.theme-preview {
    width: 100%;
    aspect-ratio: 3/4;
    border-radius: 8px;
    margin-bottom: 6px;
}

.light-preview { background: linear-gradient(180deg, #2AABEE 30%, #e5ddd5 30%); }
.dark-preview { background: linear-gradient(180deg, #242f3d 30%, #0e1621 30%); }
.blue-preview { background: linear-gradient(180deg, #283593 30%, #0d1b4a 30%); }
.green-preview { background: linear-gradient(180deg, #2e7d32 30%, #0d3311 30%); }

.theme-option span {
    font-size: 13px;
}

/* Color Pickers */
.color-picker-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
}

.color-picker-row label {
    font-size: 14px;
}

.color-picker-row input[type="color"] {
    width: 40px;
    height: 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: none;
}

/* BG Options */
.bg-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
}

.bg-option {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.bg-option:hover {
    background: var(--accent);
    color: white;
}

/* Font Select */
#font-select {
    width: calc(100% - 32px);
    margin: 8px 16px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

/* Font Size Slider */
.font-size-slider {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
}

.font-size-slider input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}

/* QR */
.qr-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 16px !important;
    gap: 16px;
}

#qr-canvas {
    border-radius: 12px;
    box-shadow: 0 4px 12px var(--shadow);
}

.qr-hint {
    color: var(--text-secondary);
    font-size: 14px;
}

.qr-divider {
    color: var(--text-secondary);
    font-size: 14px;
    position: relative;
    width: 100%;
    text-align: center;
}

.qr-divider::before,
.qr-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}

.qr-divider::before { left: 0; }
.qr-divider::after { right: 0; }

#qr-scanner-container {
    width: 100%;
    max-width: 300px;
    border-radius: 12px;
    overflow: hidden;
}

#qr-video {
    width: 100%;
    display: block;
}

/* Profile Edit */
.profile-edit-avatar {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 24px auto;
    cursor: pointer;
}

.avatar-large {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 600;
    color: white;
    overflow: hidden;
}

.avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-edit-overlay {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    border: 2px solid var(--bg-primary);
}

.form-group {
    padding: 8px 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 4px;
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 0;
    border: none;
    border-bottom: 2px solid var(--border);
    outline: none;
    font-size: 16px;
    background: transparent;
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    border-bottom-color: var(--accent);
}

.form-group textarea {
    resize: none;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 15px !important;
    color: var(--text-primary) !important;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

/* User List */
.user-list {
    padding: 0;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
}

.user-item:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: white;
    overflow: hidden;
    flex-shrink: 0;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.user-name {
    font-weight: 500;
    font-size: 15px;
}

.user-username {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Devices */
.current-device {
    padding: 16px;
}

.current-device h4 {
    font-size: 14px;
    color: var(--accent);
    margin-bottom: 12px;
}

.device-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    background: var(--bg-secondary);
}

.device-item.current {
    border: 2px solid var(--accent);
}

.device-icon {
    font-size: 28px;
}

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

.device-detail {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ============================================
   DROPDOWN MENUS
   ============================================ */
.dropdown-menu {
    position: fixed;
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 4px 16px var(--shadow);
    min-width: 200px;
    z-index: 200;
    overflow: hidden;
    animation: scaleIn 0.15s ease;
}

.menu-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.menu-item:hover {
    background: var(--bg-hover);
}

.menu-item.danger {
    color: var(--text-danger);
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* Attach Menu */
.attach-menu {
    bottom: 70px;
    left: 12px;
}

/* ============================================
   EMOJI PICKER
   ============================================ */
.emoji-picker {
    position: absolute;
    bottom: 60px;
    right: 12px;
    width: 320px;
    height: 300px;
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 4px 16px var(--shadow);
    z-index: 50;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: scaleIn 0.15s ease;
}

.emoji-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.emoji-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 20px;
    transition: background 0.15s;
}

.emoji-tab.active {
    background: var(--accent-light);
}

.emoji-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    align-content: flex-start;
}

.emoji-item {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
}

.emoji-item:hover {
    background: var(--bg-hover);
}

.sticker-item {
    width: 80px;
    height: 80px;
    padding: 4px;
    cursor: pointer;
    border-radius: 8px;
    transition: transform 0.15s;
}

.sticker-item:hover {
    transform: scale(1.1);
}

.sticker-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Reaction Picker */
.reaction-picker {
    position: fixed;
    background: var(--bg-primary);
    border-radius: 24px;
    box-shadow: 0 4px 16px var(--shadow);
    padding: 6px 8px;
    display: flex;
    gap: 4px;
    z-index: 200;
    animation: scaleIn 0.15s ease;
}

.reaction-picker span {
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: transform 0.15s;
}

.reaction-picker span:hover {
    transform: scale(1.3);
}

/* ============================================
   IMAGE VIEWER
   ============================================ */
.image-viewer {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.viewer-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 12px;
    z-index: 1;
}

.viewer-header .btn-icon {
    color: white;
    background: rgba(255,255,255,0.1);
}

.viewer-actions {
    display: flex;
    gap: 8px;
}

#viewer-image {
    max-width: 90%;
    max-height: 85%;
    object-fit: contain;
    border-radius: 4px;
}

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 500;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================
   LOADING
   ============================================ */
.loading-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.3);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   UTILITIES
   ============================================ */
.hidden { display: none !important; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Avatar Colors */
.avatar-color-0 { background: #e91e63; }
.avatar-color-1 { background: #9c27b0; }
.avatar-color-2 { background: #673ab7; }
.avatar-color-3 { background: #3f51b5; }
.avatar-color-4 { background: #2196f3; }
.avatar-color-5 { background: #009688; }
.avatar-color-6 { background: #4caf50; }
.avatar-color-7 { background: #ff9800; }

/* Recording indicator */
.recording-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    color: var(--text-danger);
    font-size: 14px;
}

.recording-dot {
    width: 10px;
    height: 10px;
    background: var(--text-danger);
    border-radius: 50%;
    animation: pulse 1s ease-in-out infinite;
}

/* Highlight search result */
.search-highlight {
    background: yellow;
    color: black;
    border-radius: 2px;
    padding: 0 2px;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        z-index: 10;
    }

    .chat-view {
        position: absolute;
        z-index: 5;
        width: 100%;
    }

    .sidebar.chat-open {
        display: none;
    }

    .chat-view.chat-open {
        z-index: 15;
    }

    .btn-back {
        display: flex !important;
    }

    .chat-empty {
        display: none !important;
    }

    .modal-fullscreen {
        max-width: 100%;
    }

    .emoji-picker {
        width: 100%;
        right: 0;
        bottom: 56px;
        border-radius: 12px 12px 0 0;
    }

    .theme-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 400px) {
    .code-digit {
        width: 40px;
        height: 48px;
        font-size: 20px;
    }
}
/* Стили для формы Email */
.btn-email, .btn-phone {
    width: 100%;
    padding: 14px 20px;
    margin: 10px 0;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-email {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-phone {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.btn-email:hover, .btn-phone:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

.auth-input-full {
    width: 100%;
    padding: 14px 20px;
    margin: 15px 0;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 16px;
    transition: border-color 0.2s;
}

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

.auth-divider {
    text-align: center;
    margin: 20px 0;
    color: #999;
    font-size: 14px;
    position: relative;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: #e0e0e0;
}

.auth-divider::before {
    left: 0;
}

.auth-divider::after {
    right: 0;
}
.badge {
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    margin-left: 8px;
    display: inline-block;
}

.badge.hidden {
    display: none;
}
/* === Статусы сообщений (галочки) === */
.message-status {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 14px;
    margin-left: 4px;
    color: var(--text-secondary);
    transition: color 0.2s;
}
.status-sent::before { content: '✓'; color: var(--text-secondary); }
.status-delivered::before { content: '✓✓'; color: var(--text-secondary); }
.status-read::before {
    content: '✓✓';
    color: #2AABEE; /* 🔵 Синий цвет для прочитанных */
    font-weight: 600;
}
@keyframes checkPop {
    0% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}
.status-read { animation: checkPop 0.3s ease; }
/* ============================================
   v1.1 — аватары, профили, группы, медиа
   ============================================ */

/* Аватар: инициалы под картинкой — если фото не загрузилось, видны инициалы */
.chat-avatar, .chat-header-avatar, .user-avatar, .avatar-large, .settings-avatar, .message-avatar {
    position: relative;
}
.chat-avatar > img, .chat-header-avatar > img, .user-avatar > img,
.avatar-large > img, .settings-avatar > img, .message-avatar > img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.avatar-saved {
    background: linear-gradient(135deg, #f59e0b, #ef4444) !important;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 22px;
}
.user-avatar.avatar-saved { width: 42px; height: 42px; flex-shrink: 0; }

.muted-icon { font-size: 12px; opacity: .7; }
.chat-badge.muted { background: var(--text-secondary); }

.chat-header-status.online { color: var(--accent); }
.chat-header-status.typing { color: var(--accent); font-style: italic; }
.typing-text { color: var(--accent); }

.list-section-title {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
}
.user-item { position: relative; }
.user-item.selected { background: var(--accent-light); }
.user-check {
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    color: transparent;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}
.user-item.selected .user-check { background: var(--accent); border-color: var(--accent); color: #fff; }

.group-create { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.group-selected { display: flex; flex-wrap: wrap; gap: 6px; min-height: 24px; }
.group-chip {
    background: var(--accent-light);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 13px;
    cursor: pointer;
}
.role-badge {
    font-size: 11px;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0 5px;
    margin-left: 4px;
}
.hint { color: var(--text-secondary); font-size: 12px; }
.settings-value { margin-left: auto; color: var(--text-secondary); font-size: 14px; }
.settings-item .settings-label small { font-weight: normal; }

/* Профиль собеседника */
.profile-card { text-align: center; padding: 28px 16px 16px; }
.profile-card .avatar-large { width: 110px; height: 110px; font-size: 40px; margin: 0 auto 14px; }
.profile-card h2 { margin-bottom: 4px; font-size: 20px; color: var(--text-primary); }
.profile-status { color: var(--text-secondary); font-size: 14px; }
.profile-status.online { color: var(--accent); }

.shared-media {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 0 16px 12px;
}
.media-tile {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--bg-secondary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-direction: column;
    font-size: 26px;
}
.media-tile img, .media-tile video { width: 100%; height: 100%; object-fit: cover; }
.media-tile > span { position: absolute; color: #fff; font-size: 22px; text-shadow: 0 0 6px #000; }
.media-tile small { font-size: 11px; color: var(--text-secondary); margin-top: 4px; padding: 0 4px; text-align: center; }

/* Лента сообщений */
.messages-loading, .messages-empty {
    margin: auto;
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}
.messages-empty p {
    background: rgba(0,0,0,.25);
    color: #fff;
    padding: 8px 14px;
    border-radius: 14px;
    font-size: 14px;
}
.load-older {
    align-self: center;
    background: rgba(0,0,0,.25);
    color: #fff;
    font-size: 13px;
    padding: 4px 12px;
    border-radius: 12px;
    cursor: pointer;
    margin-bottom: 8px;
}
.message-wrapper.in:has(.message-avatar) {
    display: grid;
    grid-template-columns: 34px 1fr;
    column-gap: 6px;
    align-items: end;
}
.message-wrapper.in:has(.message-avatar) .message-reactions { grid-column: 2; }
.message-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    overflow: hidden;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    grid-row: 1 / span 2;
    align-self: end;
}
.message-sender[class*="avatar-color-"] { background: none; }
.avatar-color-0-text { color: #e91e63; } .avatar-color-1-text { color: #9c27b0; }
.avatar-color-2-text { color: #673ab7; } .avatar-color-3-text { color: #3f51b5; }
.avatar-color-4-text { color: #2196f3; } .avatar-color-5-text { color: #009688; }
.avatar-color-6-text { color: #4caf50; } .avatar-color-7-text { color: #ff9800; }

.message-forwarded { font-size: 13px; color: var(--accent); margin-bottom: 4px; }
.message-text { white-space: pre-wrap; }
.message-text.emoji-only { font-size: 40px; line-height: 1.2; }
.message-bubble.bare { background: transparent !important; padding: 0; }
.message-bubble.bare .message-meta {
    background: rgba(0,0,0,.35);
    color: #fff;
    border-radius: 10px;
    padding: 1px 6px;
    width: fit-content;
    margin-left: auto;
}
.message-bubble.bare .message-meta .message-time,
.message-bubble.bare .message-meta .message-status { color: #fff; }
.message-sticker { width: auto; height: auto; font-size: 96px; line-height: 1.1; }
.message-file { color: inherit; text-decoration: none; }
.message-wrapper.highlight .message-bubble { box-shadow: 0 0 0 3px var(--accent); transition: box-shadow .3s; }
.message-status { margin-left: 2px; }

/* Видеосообщения-кружки */
.video-note {
    position: relative;
    width: 220px; height: 220px;
    border-radius: 50%;
    overflow: hidden;
    background: #000;
    cursor: pointer;
}
.video-note video { width: 100%; height: 100%; object-fit: cover; }
.video-note-play {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 40px;
    text-shadow: 0 0 10px rgba(0,0,0,.6);
    pointer-events: none;
}
.video-note.playing .video-note-play { display: none; }
.video-note-recorder {
    position: absolute;
    left: 50%; bottom: 90px;
    transform: translateX(-50%);
    width: 240px; height: 240px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--accent);
    z-index: 60;
    box-shadow: 0 10px 40px rgba(0,0,0,.35);
    background: #000;
}
.video-note-recorder video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.video-indicator {
    position: absolute; left: 50%; bottom: 14px;
    transform: translateX(-50%);
    background: rgba(0,0,0,.55);
    color: #fff;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 13px;
    display: flex; align-items: center; gap: 6px;
}
.video-dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: pulse 1s infinite; }
.chat-active { position: relative; }
.btn-video.recording { color: var(--text-danger); }

/* Запись голосового — индикатор поверх поля, текст в поле не теряется */
.input-wrapper.is-recording > :not(.recording-indicator) { visibility: hidden; }
.input-wrapper .recording-indicator {
    position: absolute; inset: 0;
    padding: 0 14px;
}
.recording-hint { color: var(--text-secondary); font-size: 12px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-hold { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

.reply-bar.editing { border-left-color: var(--accent); }
.blocked-bar {
    display: flex; justify-content: center;
    padding: 12px;
    background: var(--bg-input);
    border-top: 1px solid var(--border);
}

/* QR */
.qr-code-box {
    background: #fff;
    padding: 12px;
    border-radius: 16px;
    width: fit-content;
    margin: 12px auto;
}
.qr-code-box img, .qr-code-box canvas { display: block; }
.qr-link {
    font-size: 12px;
    color: var(--text-secondary);
    word-break: break-all;
    margin: 4px 0 12px;
    text-align: center;
}

/* Тост-уведомление о сообщении */
.toast-notification { display: flex; align-items: center; gap: 10px; cursor: pointer; max-width: 80vw; }

/* Экран код-пароля */
.lock-screen {
    position: fixed; inset: 0;
    z-index: 2000;
    background: var(--bg-primary);
    display: flex; align-items: center; justify-content: center;
}
.lock-box {
    display: flex; flex-direction: column; align-items: center; gap: 14px;
    width: min(320px, 90vw);
    color: var(--text-primary);
}
.lock-box input {
    width: 100%;
    font-size: 24px;
    letter-spacing: 8px;
    text-align: center;
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.shake { animation: shake .35s; border-color: var(--text-danger) !important; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* Лента не должна растягивать экран: без min-height:0 при большом числе
   сообщений поле ввода уезжало за нижний край */
.app-container, .chat-view, .chat-active { min-height: 0; overflow: hidden; }
.messages-area { min-height: 0; }
.sidebar { min-height: 0; }
.chat-list { min-height: 0; overflow-y: auto; flex: 1; }

@media (max-width: 768px) {
    /* без явной высоты абсолютный .chat-view рос вместе с перепиской,
       и поле ввода на телефоне уезжало за нижний край экрана */
    .sidebar, .chat-view { top: 0; bottom: 0; height: 100%; }
    .chat-input-area { padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
    .message-wrapper { max-width: 85%; }
    .video-note { width: 180px; height: 180px; }
    .recording-hint { display: none; }
}

/* ============================================
   v1.2 — плееры, реакции, «замок» записи, управление группой
   ============================================ */

/* Голосовые: волна (тап = перемотка), длительность и скорость */
.voice-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.voice-waveform { cursor: pointer; padding: 4px 0; }
.voice-info { display: flex; align-items: center; gap: 8px; }
.speed-btn {
    border: none;
    background: rgba(0,0,0,.08);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    cursor: pointer;
    line-height: 16px;
}
.message-wrapper.out .speed-btn { background: rgba(0,0,0,.06); }

/* Кружки: кольцо прогресса, время, скорость, на весь экран */
.video-note { position: relative; user-select: none; -webkit-user-select: none; }
.vn-ring {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    transform: rotate(-90deg);
    pointer-events: none;
}
.vn-ring circle { fill: none; stroke-width: 6; }
.vn-ring-bg { stroke: rgba(255,255,255,.18); }
.vn-ring-fill { stroke: #fff; stroke-linecap: round; transition: stroke-dashoffset .2s linear; }
.video-note:not(.playing) .vn-ring { opacity: 0; }
.vn-time {
    position: absolute; left: 50%; bottom: 10px;
    transform: translateX(-50%);
    background: rgba(0,0,0,.45);
    color: #fff;
    font-size: 12px;
    padding: 1px 8px;
    border-radius: 10px;
    pointer-events: none;
}
.vn-btn {
    position: absolute;
    width: 30px; height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,.5);
    color: #fff;
    font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    padding: 0;
}
.vn-full { top: 8px; right: 8px; }
.vn-speed { top: 8px; left: 8px; font-size: 10px; color: #fff; }
.video-note:not(.playing) .vn-speed { display: none; }

.video-viewer {
    position: fixed; inset: 0;
    z-index: 320;
    background: rgba(0,0,0,.92);
    display: flex; align-items: center; justify-content: center;
}
.video-viewer video { max-width: 100vw; max-height: 85vh; border-radius: 12px; background: #000; }
.video-viewer .viewer-header { position: absolute; top: 0; left: 0; right: 0; }
.video-viewer .speed-btn { background: rgba(255,255,255,.15); color: #fff; font-size: 13px; padding: 4px 10px; }

/* Реакции в контекстном меню (как в Telegram) */
.ctx-reactions {
    display: flex;
    gap: 2px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}
.ctx-reactions span {
    font-size: 22px;
    cursor: pointer;
    border-radius: 50%;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    transition: transform .1s;
}
.ctx-reactions span:hover { transform: scale(1.25); background: var(--bg-hover); }
.ctx-reactions span.own { background: var(--accent-light); }
.ctx-reactions span.more { font-size: 18px; color: var(--text-secondary); }

.reaction-picker {
    flex-wrap: wrap;
    max-width: min(340px, calc(100vw - 16px));
    max-height: 260px;
    overflow-y: auto;
    border-radius: 16px;
    justify-content: center;
}

/* Запись с «замком» */
.lock-hint {
    position: fixed;
    z-index: 70;
    width: 40px;
    padding: 8px 0;
    border-radius: 20px;
    background: var(--bg-primary);
    box-shadow: 0 4px 16px var(--shadow);
    display: flex; flex-direction: column; align-items: center;
    font-size: 16px;
    pointer-events: none;
}
.lock-hint span { color: var(--text-secondary); font-size: 14px; animation: lockUp 1s ease-in-out infinite; }
@keyframes lockUp { 0%, 100% { transform: translateY(2px); } 50% { transform: translateY(-3px); } }
.chat-input-area { position: relative; }
.record-lock-bar {
    position: absolute; inset: 0;
    z-index: 65;
    background: var(--bg-input);
    display: flex; align-items: center; gap: 8px;
    padding: 0 12px;
}
.record-lock-bar .lock-status { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--text-danger); font-size: 15px; }
.record-lock-bar .lock-cancel { font-size: 20px; }
.record-lock-bar .lock-send {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 18px;
}

/* Участники группы: действия админа */
.member-actions { display: flex; gap: 2px; margin-left: auto; }
.member-actions .btn-icon { width: 32px; height: 32px; font-size: 15px; }
.member-actions .danger { color: var(--text-danger); }
.user-username.online { color: var(--accent); }
/* кнопки внутри круга (угол квадрата обрезается маской) */
.vn-full { top: 17%; right: 17%; }
.vn-speed { top: 17%; left: 17%; }
/* «в сети» / «печатает…» в синей шапке: акцентный цвет совпадал с фоном и текст пропадал */
.chat-header .chat-header-status.online,
.chat-header .chat-header-status.typing { color: #fff; opacity: 1; font-weight: 500; }
/* Сохранение профиля: заметная кнопка внизу и яркая ✓ в шапке */
.profile-save-btn { display: block; width: calc(100% - 32px); margin: 8px 16px 24px; padding: 12px; font-size: 16px; }
#profile-edit-modal .modal-header .btn-icon:last-child { color: #fff; font-size: 24px; font-weight: 700; }

/* v1.3: без системной подсветки нажатий (на Android давала цветные рамки) */
* { -webkit-tap-highlight-color: transparent; }
button:focus, button:focus-visible { outline: none; }
.ico { display: block; }
.voice-play-btn { background: var(--accent); color: #fff; }
.voice-play-btn .ico { width: 18px; height: 18px; }
.video-note-play .ico { width: 44px; height: 44px; filter: drop-shadow(0 0 6px rgba(0,0,0,.5)); }
.media-tile > span .ico { width: 30px; height: 30px; filter: drop-shadow(0 0 4px rgba(0,0,0,.6)); }
.preview-media { color: var(--accent); }
#viewer-image { transform-origin: center center; will-change: transform; user-select: none; -webkit-user-select: none; cursor: zoom-in; }

/* Поиск в чате: список результатов как в Telegram */
.chat-active { position: relative; }
.chat-search-results {
    position: absolute;
    left: 0; right: 0;
    top: calc(var(--header-height) + 48px);
    bottom: 0;
    z-index: 40;
    background: var(--bg-primary);
    overflow-y: auto;
    border-top: 1px solid var(--border);
}
.search-result { display: flex; gap: 10px; padding: 10px 14px; cursor: pointer; align-items: center; }
.search-result:hover, .search-result.active { background: var(--bg-hover); }
.search-result .user-avatar { width: 42px; height: 42px; flex-shrink: 0; }
.search-result-body { min-width: 0; flex: 1; }
.search-result-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--text-primary); }
.search-result-top span { color: var(--text-secondary); font-size: 12px; white-space: nowrap; }
.search-result-text { font-size: 14px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-text mark { background: none; color: var(--accent); font-weight: 600; }
.search-empty { padding: 40px 16px; text-align: center; color: var(--text-secondary); }
#chat-search-count { min-width: 44px; text-align: center; font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
#chat-search-input::-webkit-search-cancel-button { display: none; }
/* строка поиска в чате помещается на экране телефона */
.chat-search-bar { display: flex; align-items: center; gap: 2px; padding: 6px 8px; }
.chat-search-bar input { flex: 1; min-width: 0; width: auto; }
.chat-search-bar .btn-icon { width: 34px; height: 34px; flex-shrink: 0; padding: 0; font-size: 17px; }
#chat-search-count { min-width: 34px; flex-shrink: 0; }

/* iPhone с «чёлкой»: в приложении с экрана «Домой» контент не уходит под вырезы */
@supports (padding: env(safe-area-inset-left)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    .sidebar { padding-bottom: env(safe-area-inset-bottom); }
}
