    :root {
      --accent: #5B6CFF;
      --accent-soft: rgba(91, 108, 255, 0.12);
      --accent-gradient: linear-gradient(135deg, #5B6CFF, #8A9CFF);
      --danger: #FF4D4F;
      --warning: #FAAD14;
      --success: #52C41A;
      --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
      --border-radius-card: 20px;
      --border-radius-element: 14px;
      --transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
      --shadow-panel: 0 8px 30px rgba(0,0,0,0.06);
      --shadow-message: 0 2px 8px rgba(0,0,0,0.08);
    }

.btn-voice {
    background: var(--surface-1-solid);
    border: 1px solid var(--stroke-strong);
    color: var(--text);
    transition: var(--transition);
}

.voice-btn.recording {
    background: var(--danger);
    color: white;
    animation: pulseRecord 1s infinite;
    border-color: var(--danger);
}

@keyframes pulseRecord {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

    /* ТЁМНАЯ ТЕМА (по умолчанию, т.к. ты указал data-theme="dark") */
    html[data-theme="dark"] {
      --bg: #0F141E; /* Более глубокий, спокойный фон */
      --surface-1: rgba(28, 36, 51, 0.75); /* Полупрозрачная панель */
      --surface-1-solid: #1C2433; /* Непрозрачный аналог для некоторых элементов */
      --surface-2: rgba(20, 26, 38, 0.6);
      --text: #FFFFFF;
      --text-muted: rgba(255,255,255,0.7);
      --text-faint: rgba(255,255,255,0.5);
      --stroke: rgba(255, 255, 255, 0.06);
      --stroke-strong: rgba(255, 255, 255, 0.12);
      --shadow-1: 0 8px 30px rgba(0,0,0,0.3);
    }

    /* СВЕТЛАЯ ТЕМА */
    html[data-theme="light"] {
      --bg: #F5F7FC;
      --surface-1: rgba(255, 255, 255, 0.75);
      --surface-1-solid: #FFFFFF;
      --surface-2: rgba(255, 255, 255, 0.6);
      --text: #1C1F2E;
      --text-muted: rgba(28,31,46,0.7);
      --text-faint: rgba(28,31,46,0.5);
      --stroke: rgba(0,0,0,0.06);
      --stroke-strong: rgba(0,0,0,0.12);
      --shadow-1: 0 8px 30px rgba(0,0,0,0.08);
    }

    * { box-sizing: border-box; }

    body { 
      font-family: var(--font-family); 
      margin: 0; 
      background: var(--bg); 
      color: var(--text); 
      line-height: 1.5;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }

    /* Аватарка для диалога */
    .conv-avatar {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      background: var(--accent-gradient);
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 600;
      text-transform: uppercase;
      flex-shrink: 0;
    }

    .conv-info {
      flex: 1;
      min-width: 0;
    }

    .conv-header {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      margin-bottom: 4px;
    }

    .conv-time {
      font-size: 11px;
      color: var(--text-faint);
      flex-shrink: 0;
      margin-left: 8px;
    }

    .conv-last-message {
      font-size: 13px;
      color: var(--text-muted);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    /* ГЛОБАЛЬНЫЙ СТИЛЬ ДЛЯ ПРОКРУТКИ */
    ::-webkit-scrollbar { width: 6px; height: 6px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 20px; }
    ::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

    /* БАЗОВЫЙ СТИЛЬ ДЛЯ КАРТОЧЕК/ПАНЕЛЕЙ */
    .panel { 
      background: var(--surface-1); 
      backdrop-filter: blur(14px);
      -webkit-backdrop-filter: blur(14px);
      border: 1px solid var(--stroke); 
      border-radius: var(--border-radius-card); 
      padding: 16px; 
      box-shadow: var(--shadow-panel);
      margin-bottom: 16px;
    }

    * { box-sizing: border-box; }
    body { font-family: system-ui, Arial; margin: 0; background: var(--bg); color: var(--text); }
      header { 
      padding: 12px 24px; 
      background: var(--surface-1);
      backdrop-filter: blur(14px);
      -webkit-backdrop-filter: blur(14px);
      border-bottom: 1px solid var(--stroke); 
      display: flex; 
      justify-content: space-between; 
      align-items: center; 
      flex-wrap: wrap; 
      gap: 16px; 
      box-shadow: var(--shadow-1);
    }
    .header-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
    .header-right { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
        .wrap { display: flex; height: calc(100vh - 68px); }
        .left { 
      width: 340px; 
      min-width: 280px; 
      max-width: 500px; 
      resize: horizontal; 
      overflow: auto; 
      border-right: 1px solid var(--stroke); 
      padding: 16px; 
      background: var(--surface-2);
      backdrop-filter: blur(8px);
      -webkit-backdrop-filter: blur(8px);
      display: flex; 
      flex-direction: column; 
      gap: 16px; 
    }
    
        .right { 
        flex: 1; 
        display: flex; 
        flex-direction: column; 
        min-width: 0; 
        height: calc(100vh - 68px);
        background: var(--bg); 
    }
    
    .panel { background: var(--surface-1); border: 1px solid var(--stroke); border-radius: 10px; padding: 12px; }
        input, button { 
      padding: 12px 16px; 
      border-radius: var(--border-radius-element); 
      border: 1px solid var(--stroke); 
      background: var(--surface-1-solid); 
      color: var(--text); 
      font-family: inherit;
      font-size: 14px;
      transition: var(--transition);
    }
        button { 
      background: var(--surface-1-solid); 
      cursor: pointer; 
      font-weight: 500; 
      border: 1px solid var(--stroke-strong);
    }
    button:hover { background: var(--surface-2); border-color: var(--accent); }
    button:active { transform: scale(0.98); }
    button:disabled { opacity: .4; cursor: not-allowed; transform: none; background: var(--surface-1-solid); border-color: var(--stroke); }
    button:active { transform: scale(0.98); }
    button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
        .btn-primary { 
      background: var(--accent-gradient); 
      border: none; 
      color: white; 
      box-shadow: 0 4px 12px var(--accent-soft);
    }
    .btn-primary:hover { background: var(--accent); }
    .btn-small { padding: 8px 14px; font-size: 13px; border-radius: 30px; }
    .row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
    .row > * { flex: 1; }
    .tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--stroke); margin-bottom: 12px; }
    .tab-btn { background: none; border: none; padding: 6px 12px; cursor: pointer; color: var(--text-muted); }
    .tab-btn.active { color: var(--accent); border-bottom: 2px solid var(--accent); }
    .tab-content { display: none; }
    .tab-content.active { display: flex; flex-direction: column; gap: 8px; }
    .conversations { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow-y: auto; }
    .conv-item { 
      padding: 12px 16px; 
      border-radius: var(--border-radius-element); 
      border: none; 
      background: transparent; 
      cursor: pointer; 
      display: flex; 
      align-items: center; 
      gap: 12px;
      transition: var(--transition);
      margin-bottom: 2px;
    }
    .conv-item:hover { background: var(--surface-3); }
    .conv-item.active { 
      background: var(--accent-soft); 
      border-left: 3px solid var(--accent);
      border-radius: 0 var(--border-radius-element) var(--border-radius-element) 0;
    }
    .conv-item.active { outline: 2px solid var(--accent); }
    .conv-name { 
      font-weight: 600; 
      font-size: 15px;
      overflow: hidden; 
      text-overflow: ellipsis; 
      white-space: nowrap; 
    }
    .conv-badge { 
        background: var(--accent-gradient); 
        border-radius: 30px; 
        padding: 3px 9px; 
        font-size: 11px; 
        font-weight: 600;
        color: white;
        margin-left: 8px;
        box-shadow: 0 2px 8px var(--accent-soft);
        animation: pulse 2s infinite;
    }
    
    @keyframes pulse {
        0%, 100% { opacity: 1; }
        50% { opacity: 0.7; }
    }
    
    .chatTop { 
        padding: 12px 16px; 
        border-bottom: 1px solid var(--stroke); 
        background: var(--surface-2); 
        display: flex; 
        align-items: center; 
        gap: 12px; 
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    .chatTitleWrapper {
        flex: 1;
        text-align: center;
        cursor: pointer;
        transition: opacity 0.2s;
        min-width: 0;
        overflow: hidden;
    }
    
    .chatTitleWrapper:hover {
        opacity: 0.8;
    }
    
    .chatTitleWrapper b {
        display: block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .back-btn { background: none; border: none; font-size: 24px; cursor: pointer; padding: 0 8px; display: none; }
    
    .chat { 
        padding: 16px; 
        overflow-y: auto;
        background: var(--bg); 
        flex: 1;
        min-height: 0;
max-width: 900px;
  margin: 0 auto;
  width: 100%;
    }
    
    .composer { 
        padding: 16px; 
        border-top: 1px solid var(--stroke); 
        background: var(--surface-1);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        display: flex; 
        gap: 12px; 
        flex-shrink: 0;
        align-items: flex-end;
    }
    
.composer textarea {
    flex: 1;
    resize: none;
    min-height: 44px;
    height: auto;
    max-height: 200px;
    padding: 12px 16px;
    border-radius: 24px;
    background: var(--surface-1-solid);
    border: 1px solid var(--stroke-strong);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    color: var(--text);
    overflow-y: auto;
}
    
    .composer textarea:focus {
        border-color: var(--accent);
        box-shadow: 0 4px 12px var(--accent-soft);
        outline: none;
    }
    .msg { 
      max-width: 70%; 
      padding: 12px 16px; 
      border-radius: 18px; 
      margin: 4px 0; 
      position: relative; 
      font-size: 14px;
      line-height: 1.45;
      word-wrap: break-word;
      animation: fadeInUp 0.25s ease;
      box-shadow: var(--shadow-message);
    }
    
    .msg.me { 
      margin-left: auto; 
      background: var(--accent-gradient); 
      color: white; 
      border-bottom-right-radius: 4px;
    }
    
    .msg.them { 
      margin-right: auto; 
      background: var(--surface-1-solid); 
      border: 1px solid var(--stroke);
      border-bottom-left-radius: 4px;
    }    .meta { 
      font-size: 11px; 
      opacity: .7; 
      margin-top: 6px; 
      display: flex; 
      justify-content: flex-end; 
      align-items: center;
      gap: 6px; 
      flex-wrap: wrap; 
    }
    
    .msg.me .meta {
      color: rgba(255,255,255,0.8);
    }
    .reply-bar { 
        background: var(--accent-soft); 
        border-left: 4px solid var(--accent); 
        padding: 10px 14px; 
        margin-bottom: 12px; 
        border-radius: 12px; 
        font-size: 13px;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        animation: fadeInUp 0.2s ease;
    }
    .reply-preview { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .reactions-container { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
     .reaction-badge { 
        background: var(--surface-3); 
        border: 1px solid var(--stroke); 
        border-radius: 30px; 
        padding: 4px 10px; 
        font-size: 13px; 
        cursor: pointer; 
        transition: var(--transition);
        display: inline-flex;
        align-items: center;
        gap: 4px;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
    
    .reaction-badge:hover { 
        transform: scale(1.08); 
        background: var(--surface-2); 
        border-color: var(--accent);
    }
    
    .reaction-badge.active { 
        background: var(--accent-soft); 
        border-color: var(--accent); 
    }
    .reaction-badge.active { background: color-mix(in oklab, var(--accent), transparent 80%); border-color: var(--accent); }
    .reaction-badge:hover { transform: scale(1.05); background: var(--surface-2); }
    .status-icons { display: inline-flex; gap: 3px; margin-left: 8px; }
    .status-icons { display: inline-flex; gap: 2px; margin-left: 4px; align-items: center; }
    /* Статусы сообщений с анимацией */
.status-sent {
    color: rgba(255,255,255,0.6);
    font-size: 12px;
    display: inline-block;
}

.status-delivered {
    color: rgba(255,255,255,0.8);
    font-size: 12px;
    display: inline-block;
    animation: checkmarkAppear 0.2s cubic-bezier(0.2, 0.8, 0.4, 1);
}

.status-read {
    color: #52C41A;
    font-size: 12px;
    display: inline-block;
    animation: checkmarkAppear 0.2s cubic-bezier(0.2, 0.8, 0.4, 1);
}

@keyframes checkmarkAppear {
    from {
        opacity: 0;
        transform: scale(0.3);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
    
/* Анимация отправки */
.status-sending {
    color: #FAAD14;
    font-size: 12px;
    display: inline-block;
    animation: pulseSend 1s ease-in-out infinite;
}

@keyframes pulseSend {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

    /* Для входящих сообщений статусы не показываем */
    .msg.them .status-icons { display: none; }
    .search-panel { 
        background: var(--surface-1); 
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border-bottom: 1px solid var(--stroke); 
        padding: 16px; 
        display: none; 
        animation: slideDown 0.2s ease;
    }
    
    @keyframes slideDown {
        from { opacity: 0; transform: translateY(-10px); }
        to { opacity: 1; transform: translateY(0); }
    }
    .search-panel.active { display: block; }
    .search-results { max-height: 300px; overflow-y: auto; margin-top: 10px; }
    .log { font-size: 12px; white-space: pre-wrap; opacity: .85; max-height: 200px; overflow-y: auto; }
     .modal { 
        display: none; 
        position: fixed; 
        top: 0; 
        left: 0; 
        width: 100%; 
        height: 100%; 
        background: rgba(0,0,0,0.5);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        justify-content: center; 
        align-items: center; 
        z-index: 1000; 
        animation: fadeIn 0.2s ease;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    .modal.active { 
        display: flex; 
    }
    .modal-card { 
        background: var(--surface-1); 
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-radius: 28px; 
        width: 90%; 
        max-width: 480px; 
        padding: 28px; 
        border: 1px solid var(--stroke); 
        box-shadow: 0 20px 40px rgba(0,0,0,0.2);
        animation: slideUp 0.3s ease;
    }
    
    @keyframes slideUp {
        from { 
            opacity: 0; 
            transform: translateY(20px); 
        }
        to { 
            opacity: 1; 
            transform: translateY(0); 
        }
    }
    .step { display: none; }
    .step.active { display: block; }
    .error-msg { color: var(--danger); font-size: 13px; margin-top: 5px; }
    .group-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
    .password-wrapper { position: relative; width: 100%; }
    .password-wrapper input { width: 100%; padding-right: 35px; }
    .toggle-password { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); cursor: pointer; user-select: none; }
    .toastWrap { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; width: min(560px, calc(100% - 24px)); }
    .toast { pointer-events: auto; border: 1px solid var(--stroke); background: var(--surface-1); padding: 10px 12px; border-radius: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
    
    .btn-notification { transition: all 0.2s ease; }
    .btn-notification:active { transform: scale(0.95); }
    .btn-notification.loading { opacity: 0.6; pointer-events: none; }
    .btn-notification.loading::after { content: " ⏳"; animation: spin 1s linear infinite; display: inline-block; }
    @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
    .btn-notification.success { background: var(--success); color: white; border-color: var(--success); }
    .btn-notification.error { background: var(--danger); color: white; border-color: var(--danger); }
    
    .notification-help { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; background: var(--surface-3); border-radius: 50%; font-size: 12px; cursor: pointer; transition: all 0.2s; }
    .notification-help:hover { background: var(--accent); color: white; }
    
    .reaction-picker { background: var(--surface-1); border: 1px solid var(--stroke); border-radius: 30px; padding: 8px 12px; box-shadow: var(--shadow-1); backdrop-filter: blur(8px); z-index: 10000; }
    .reaction-picker button { background: none; border: none; font-size: 24px; cursor: pointer; padding: 6px 10px; transition: transform 0.1s ease; border-radius: 20px; }
    .reaction-picker button:hover { transform: scale(1.3); background: var(--surface-3); }
    
    @media (max-width: 768px) {
      .wrap { flex-direction: column; height: 100vh; }
      .left { width: 100%; resize: none; max-width: none; border-right: none; border-bottom: 1px solid var(--stroke); }
      .right { height: 100vh; }
      .mobile-show-contacts .left { display: flex; }
      .mobile-show-contacts .right { display: none; }
      .mobile-show-chat .left { display: none; }
      .mobile-show-chat .right { display: flex; }
      .back-btn { display: inline-block; }
      body.in-chat header { display: none; }
      body.in-chat .wrap { height: 100vh; }
      .header-right { justify-content: flex-end; }
    }

    /* Индикатор печати */
    .typing-indicator {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 8px 12px;
        background: var(--surface-1-solid);
        border-radius: 18px;
        border-bottom-left-radius: 4px;
        width: fit-content;
        margin: 4px 0;
    }
    
    .typing-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--text-muted);
        animation: typingBounce 1.4s infinite ease-in-out both;
    }
    
    .typing-dot:nth-child(1) { animation-delay: -0.32s; }
    .typing-dot:nth-child(2) { animation-delay: -0.16s; }
    
    @keyframes typingBounce {
        0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
        40% { transform: scale(1); opacity: 1; }
    }

    /* Анимация появления сообщений */
    @keyframes fadeInUp {
      from {
        opacity: 0;
        transform: translateY(8px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
    #sendBtn {
        background: var(--accent-gradient);
        color: white;
        border: none;
        box-shadow: 0 4px 12px var(--accent-soft);
        transition: var(--transition);
        flex-shrink: 0;
    }
    
    #sendBtn:hover:not(:disabled) {
        transform: scale(1.05);
        box-shadow: 0 6px 16px var(--accent-soft);
    }
    
    #sendBtn:disabled {
        opacity: 0.3;
        box-shadow: none;
        background: var(--surface-3);
        color: var(--text-faint);
    }
    /* Цвет плейсхолдера */
    .composer textarea::placeholder {
        color: var(--text-faint);
        opacity: 0.7;
    }
    .modal-card h3 {
        margin: 0 0 20px 0;
        font-size: 22px;
        font-weight: 600;
        color: var(--text);
    }
    
    .modal-card .row {
        display: flex;
        gap: 12px;
        margin-top: 16px;
        flex-wrap: wrap;
    }
    
    .modal-card .row > * {
        flex: 1;
    }
    
    .modal-card hr {
        border: none;
        border-top: 1px solid var(--stroke);
        margin: 20px 0;
    }
    
    /* Кнопка закрытия модалки */
    .modal-close-btn {
        background: transparent;
        border: none;
        font-size: 28px;
        cursor: pointer;
        color: var(--text-muted);
        padding: 0;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: var(--transition);
    }
    
    .modal-close-btn:hover {
        background: var(--surface-3);
        color: var(--text);
    }
    .error-msg { 
        color: var(--danger); 
        font-size: 13px; 
        margin-top: 8px; 
        padding: 8px 12px;
        background: rgba(255,77,79,0.1);
        border-radius: 10px;
        border-left: 3px solid var(--danger);
    }
    #deleteAccountBtn {
        background: transparent;
        border: 1px solid var(--danger);
        color: var(--danger);
        padding: 12px 16px;
        border-radius: var(--border-radius-element);
        font-weight: 500;
        transition: var(--transition);
    }
    
    #deleteAccountBtn:hover {
        background: var(--danger);
        color: white;
    }
    .search-results {
        max-height: 300px; 
        overflow-y: auto; 
        margin-top: 12px;
        border-radius: var(--border-radius-element);
        background: var(--surface-2);
    }
    
    .search-result-item {
        padding: 12px 16px;
        border-bottom: 1px solid var(--stroke);
        cursor: pointer;
        transition: var(--transition);
    }
    
    .search-result-item:hover {
        background: var(--surface-3);
    }
    
    .search-result-item:last-child {
        border-bottom: none;
    }
    .message-menu {
        background: var(--surface-1);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid var(--stroke);
        border-radius: 16px;
        padding: 8px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        min-width: 220px;
        animation: fadeIn 0.15s ease;
    }
    
    .message-menu button {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
        padding: 10px 14px;
        background: transparent;
        border: none;
        border-radius: 10px;
        color: var(--text);
        font-size: 14px;
        text-align: left;
        cursor: pointer;
        transition: var(--transition);
    }
    
    .message-menu button:hover {
        background: var(--surface-3);
    }
    
    .message-menu button.danger {
        color: var(--danger);
    }
    
    .message-menu hr {
        margin: 6px 0;
        border: none;
        border-top: 1px solid var(--stroke);
    }
    * {
        scrollbar-width: thin;
        scrollbar-color: var(--stroke-strong) transparent;
    }
    
    *::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }
    
    *::-webkit-scrollbar-track {
        background: transparent;
    }
    
    *::-webkit-scrollbar-thumb {
        background: var(--stroke-strong);
        border-radius: 20px;
    }
    
    *::-webkit-scrollbar-thumb:hover {
        background: var(--text-faint);
    }
    /* Анимация влёта нового сообщения */
    @keyframes messageIn {
        from {
            opacity: 0;
            transform: translateY(12px) scale(0.96);
        }
        to {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }

    .message.new-message {
        animation: messageIn 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    }
    /* Всплывающая панель реакций */
    .quick-reactions-panel {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding: 6px 4px;
        border-radius: 40px;
        background: var(--surface-1);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border: 1px solid var(--stroke);
        box-shadow: var(--shadow-1);
        
        opacity: 0;
        pointer-events: none;
        transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
        z-index: 100;
    }
    
    /* Для своих сообщений — панель СЛЕВА */
    .msg.me .quick-reactions-panel {
        right: calc(100% + 8px);
        left: auto;
    }
    
    /* Для чужих сообщений — панель СПРАВА */
    .msg.them .quick-reactions-panel {
        left: calc(100% + 8px);
        right: auto;
    }
    
    .msg:hover .quick-reactions-panel {
        opacity: 1;
        pointer-events: auto;
    }
    
    .quick-reactions-panel button {
        background: transparent;
        border: none;
        font-size: 20px;
        padding: 4px 2px;
        cursor: pointer;
        border-radius: 30px;
        transition: transform 0.15s ease;
        line-height: 1;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .quick-reactions-panel button:hover {
        transform: scale(1.2);
        background: var(--surface-3);
    }
    /* Невидимый мостик между сообщением и панелью */
    .msg.me .quick-reactions-panel::before {
        content: "";
        position: absolute;
        top: 0;
        right: -12px;
        width: 12px;
        height: 100%;
        background: transparent;
    }
    
    .msg.them .quick-reactions-panel::before {
        content: "";
        position: absolute;
        top: 0;
        left: -12px;
        width: 12px;
        height: 100%;
        background: transparent;
    }
    /* Адаптивное контекстное меню */
    .message-menu {
        background: var(--surface-1);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid var(--stroke);
        border-radius: 16px;
        padding: 6px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        min-width: 200px;
        max-width: 280px;
        animation: fadeIn 0.15s ease;
    }
    
    .message-menu button {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
        padding: 12px 14px;
        background: transparent;
        border: none;
        border-radius: 10px;
        color: var(--text);
        font-size: 15px;
        text-align: left;
        cursor: pointer;
        transition: var(--transition);
        white-space: nowrap;
    }
    
    .message-menu button:hover {
        background: var(--surface-3);
    }
    
    /* На мобильных устройствах делаем кнопки крупнее */
    @media (max-width: 768px) {
        .message-menu {
            min-width: 220px;
            padding: 8px;
        }
        
        .message-menu button {
            padding: 14px 16px;
            font-size: 16px;
        }
    }
    /* Индикатор "печатает..." */
    .typing-indicator {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 10px 14px;
        background: var(--surface-1-solid);
        border: 1px solid var(--stroke);
        border-radius: 18px;
        border-bottom-left-radius: 4px;
        width: fit-content;
        margin: 4px 0;
        animation: fadeInUp 0.2s ease;
    }
    
    .typing-indicator span {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: var(--text-muted);
        animation: typingBounce 1.4s infinite ease-in-out both;
    }
    
    .typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
    .typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
    .typing-indicator span:nth-child(3) { animation-delay: 0s; }
    
    @keyframes typingBounce {
        0%, 80%, 100% { 
            transform: scale(0.7); 
            opacity: 0.4; 
        }
        40% { 
            transform: scale(1); 
            opacity: 1; 
        }
    }
    
    /* Имя печатающего */
    .typing-header {
        font-size: 12px;
        color: var(--text-muted);
        margin-bottom: 4px;
        display: flex;
        align-items: center;
        gap: 6px;
    }

    /* Скелетоны для загрузки */
    .skeleton {
        background: linear-gradient(
            90deg,
            var(--surface-3) 25%,
            var(--stroke) 50%,
            var(--surface-3) 75%
        );
        background-size: 200% 100%;
        animation: skeletonShimmer 1.5s infinite;
        border-radius: 8px;
    }
    
    @keyframes skeletonShimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    /* Скелетон для элемента списка диалогов */
    .skeleton-conv-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        margin-bottom: 2px;
    }
    
    .skeleton-avatar {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: var(--surface-3);
        animation: skeletonPulse 1.5s infinite;
    }
    
    .skeleton-conv-info {
        flex: 1;
    }
    
    .skeleton-line {
        height: 14px;
        border-radius: 8px;
        background: var(--surface-3);
        animation: skeletonPulse 1.5s infinite;
        margin-bottom: 8px;
    }
    
    .skeleton-line-sm {
        height: 12px;
        width: 60%;
        border-radius: 8px;
        background: var(--surface-3);
        animation: skeletonPulse 1.5s infinite;
    }
    
    @keyframes skeletonPulse {
        0%, 100% { opacity: 0.5; }
        50% { opacity: 0.8; }
    }
    
    /* Скелетон для сообщений в чате */
    .skeleton-message {
        display: flex;
        flex-direction: column;
        margin: 8px 0;
    }
    
    .skeleton-message.me {
        align-items: flex-end;
    }
    
    .skeleton-message.them {
        align-items: flex-start;
    }
    
    .skeleton-bubble {
        max-width: 70%;
        width: 200px;
        height: 50px;
        border-radius: 18px;
        background: var(--surface-3);
        animation: skeletonPulse 1.5s infinite;
    }
    
    .skeleton-bubble.sm {
        width: 120px;
        height: 40px;
    }
    
    .skeleton-bubble.md {
        width: 180px;
        height: 50px;
    }
    
    .skeleton-bubble.lg {
        width: 240px;
        height: 70px;
    }
    
    /* Анимация появления */
    .skeleton-fade-in {
        animation: fadeIn 0.3s ease;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    /* Ripple-эффект для кнопок */
    .ripple {
        position: relative;
        overflow: hidden;
        transform: translate3d(0, 0, 0);
    }
    
    .ripple-effect {
        position: absolute;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.5);
        transform: scale(0);
        animation: rippleAnimation 0.6s ease-out;
        pointer-events: none;
        z-index: 10;
    }
    
    @keyframes rippleAnimation {
        to {
            transform: scale(4);
            opacity: 0;
        }
    }
    
    /* Для тёмной темы — другой цвет ripple */
    html[data-theme="dark"] .ripple-effect {
        background: rgba(255, 255, 255, 0.2);
    }
    
    html[data-theme="light"] .ripple-effect {
        background: rgba(0, 0, 0, 0.1);
    }
    
    /* Для кнопок с градиентом — белый ripple */
    .btn-primary .ripple-effect {
        background: rgba(255, 255, 255, 0.4);
    }

    /* Плашка "Новые сообщения" */
    .new-messages-badge {
        position: sticky;
        bottom: 80px;
        left: 50%;
        transform: translateX(-50%);
        background: var(--accent-gradient);
        color: white;
        padding: 10px 20px;
        border-radius: 40px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        box-shadow: 0 4px 16px var(--accent-soft);
        z-index: 50;
        width: fit-content;
        margin: 0 auto;
        animation: fadeInUp 0.2s ease;
        border: none;
        pointer-events: auto;
    }
    
/* Анимация влёта нового сообщения — усиленная */
@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.new-message {
    animation: messageIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
    
    .chat {
        position: relative;
    }
/* ========== АДАПТИВНАЯ ШТОРКА ========== */
/* На ПК (≥768px) — выезжает СЛЕВА */
/* На телефоне (<768px) — выезжает СНИЗУ */

.app-sheet {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  visibility: hidden;
}

.app-sheet.active {
  visibility: visible;
}

.app-sheet-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.app-sheet.active .app-sheet-overlay {
  opacity: 1;
}

/* По умолчанию (ПК) — выезжает слева */
.app-sheet-content {
  position: absolute;
  top: 0;
  left: 0;
  width: min(320px, 85%);
  height: 100%;
  background: var(--surface-1);
  backdrop-filter: blur(20px);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.4, 1.1);
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--stroke);
}

.app-sheet.active .app-sheet-content {
  transform: translateX(0);
}

/* На телефоне (ширина < 768px) — выезжает снизу */
@media (max-width: 768px) {
  .app-sheet-content {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: 85vh;
    transform: translateY(100%);
    border-right: none;
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
  }
  
  .app-sheet.active .app-sheet-content {
    transform: translateY(0);
  }
}

/* Профиль в шторке */
.sheet-profile {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--stroke);
}

.sheet-avatar {
  width: 56px;
  height: 56px;
  background: var(--accent-gradient);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.sheet-info {
  flex: 1;
}

.sheet-name {
  font-size: 18px;
  font-weight: 600;
}

.sheet-login {
  font-size: 14px;
  opacity: 0.7;
}

/* Пункты меню в шторке */
.sheet-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 12px;
  cursor: pointer;
  border-radius: 12px;
  transition: background 0.2s;
  margin-bottom: 4px;
}

.sheet-item:hover {
  background: var(--surface-2);
}

.sheet-item-left {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 16px;
}

.sheet-value {
  opacity: 0.7;
  font-size: 14px;
}

/* Логи в шторке */
.logs-container {
  margin-top: 8px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 12px;
  max-height: 200px;
  overflow-y: auto;
}

/* Кнопка выхода */
.logout-btn {
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  background: rgba(255, 77, 79, 0.1);
  border: 1px solid var(--danger);
  border-radius: 14px;
  color: var(--danger);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.logout-btn:hover {
  background: var(--danger);
  color: white;
}

/* На мобилке кнопка выхода не прижата к низу */
@media (max-width: 768px) {
  .logout-btn {
    margin-top: 20px;
    margin-bottom: 10px;
  }
}

/* Анимация для статус-точки */
@keyframes pulseStatus {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.9); }
}

#connectionStatusDot {
    transition: all 0.2s ease;
}

.logout-btn:hover {
  background: var(--danger);
  color: white;
}
/* Анимация для статус-точки */
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.9); }
}

#connectionStatusDot {
    transition: all 0.2s ease;
}

.status-sending {
    color: #FAAD14;
    font-size: 12px;
    animation: pulse 1s infinite;
}

.status-error {
    color: #FF4D4F;
    font-size: 12px;
    cursor: pointer;
}

.status-error:hover {
    transform: scale(1.1);
}

/* Статус пользователя в чате */
.status.online {
    color: #52C41A;
}

.status.offline {
    color: var(--text-muted);
}

.composer textarea {
    /* Существующие стили... */
    transition: height 0.1s ease;
    overflow-y: auto;
}

/* Переключатель звука */
.sound-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: var(--border-radius-element);
    transition: var(--transition);
}

.sound-toggle:hover {
    background: var(--surface-3);
}

.sound-toggle input {
    width: 36px;
    height: 20px;
    appearance: none;
    background: var(--stroke-strong);
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    transition: var(--transition);
}

.sound-toggle input:checked {
    background: var(--accent);
}

.sound-toggle input::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: var(--transition);
}

.sound-toggle input:checked::before {
    left: 18px;
}

@keyframes fadeOutUp {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* Индикатор статуса в списке диалогов */
.conv-status {
    display: inline-block;
    font-size: 10px;
    margin-left: 6px;
    vertical-align: middle;
}

.conv-name {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
}
/* ===== ОБНОВЛЁННЫЙ COMPOSER ===== */
.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-1);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--stroke);
  padding: 12px 16px;
  /* === НОВОЕ: центрирование и ограничение ширины === */
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  width: 100%;
}

/* Для мобильных устройств отступы по 1 см (примерно 16px) */
@media (max-width: 768px) {
  .composer {
    padding: 12px 16px;
    max-width: 100%;
    /* Дополнительно можно добавить отступы от краёв экрана */
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-1-solid);
  border: 1px solid var(--stroke-strong);
  font-size: 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.input-wrapper {
  flex: 1;
  position: relative;
}

#textInput {
  width: 100%;
  min-height: 40px;
  max-height: 140px;
  padding: 10px 48px 10px 16px;
  border-radius: 24px;
  background: var(--surface-1-solid);
  border: 1px solid var(--stroke-strong);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
  color: var(--text);
}

.char-counter {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 11px;
  opacity: 0.6;
  pointer-events: none;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-gradient);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Reply bar внутри composer */
.reply-bar {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.reply-cancel {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
}

/* Превью голосового */
.voice-preview {
  background: var(--surface-1-solid);
  border-radius: 20px;
  padding: 12px;
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  animation: fadeInUp 0.2s ease;
}

.voice-preview-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.voice-preview-actions {
  display: flex;
  gap: 8px;
}

.voice-preview-actions button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
}

#waveformCanvas {
  background: var(--surface-2);
  border-radius: 4px;
}
@media (max-width: 768px) {
    .composer {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}
.msg + .msg.same-author {
    margin-top: 2px;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}
/* Голосовые сообщения – кастомный плеер */
.voice-msg {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 200px;
}

.voice-play {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}
.voice-play:active {
    transform: scale(0.95);
}

.voice-body {
    flex: 1;
}

.voice-meta {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
}

.voice-speed {
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 12px;
    background: var(--surface-2);
}
.voice-speed:active {
    background: var(--accent-soft);
}

.waveform-container {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 30px;
}
/* Record Lock UI */
.record-lock {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 200;
}

.lock-track {
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0.7;
  font-size: 12px;
}

.lock-icon {
  font-size: 20px;
  margin-bottom: 4px;
}

.locked-panel {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--surface-1);
  backdrop-filter: blur(20px);
  padding: 8px 14px;
  border-radius: 30px;
  margin-top: 8px;
  pointer-events: auto;
  box-shadow: var(--shadow-1);
}

.locked-panel button {
  width: 32px;
  height: 32px;
  font-size: 14px;
}
/* Telegram-like composer – улучшения */
.tg-counter {
  position: absolute;
  right: 12px;
  bottom: 6px;
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.tg-counter.visible {
  opacity: 0.5;
}

#sendBtn {
  transition: transform 0.2s, opacity 0.2s;
  transform: scale(0.9);
  opacity: 0;
}

#sendBtn.visible {
  transform: scale(1);
  opacity: 1;
}

#voiceBtn {
  transition: opacity 0.2s, transform 0.1s;
}

#voiceBtn.hide {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}
/* Умный счётчик и переключение кнопок (Telegram-like) */
.tg-counter {
  position: absolute;
  right: 12px;
  bottom: 6px;
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.tg-counter.visible {
  opacity: 0.5;
}
#sendBtn {
  transition: transform 0.2s, opacity 0.2s;
  transform: scale(0.9);
  opacity: 0;
}
#sendBtn.visible {
  transform: scale(1);
  opacity: 1;
}
#voiceBtn {
  transition: opacity 0.2s, transform 0.1s;
}
#voiceBtn.hide {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}
#charCounter {
  display: none !important;
}
.voice-level {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 8px;
    height: 20px;
}
.voice-level .bar {
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    transition: height 0.05s linear;
}
.waveform-container.playing .wave-bar {
    animation: wavePlay 0.6s infinite alternate;
}
@keyframes wavePlay {
    from { opacity: 0.3; transform: scaleY(0.8); }
    to { opacity: 1; transform: scaleY(1.2); }
}