@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500&display=swap');

:root {
    --bg-color: #09090b;
    --surface: #18181b;
    --surface-hover: #27272a;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.12);
    --msg-hue: 230;
    --msg-sat: 80%;
    --msg-light: 60%;
    --bg-hue: 230;
    --bg-sat: 20%;
    --bg-light: 10%;
    --accent: hsl(var(--msg-hue), var(--msg-sat), var(--msg-light));
    --accent-hover: hsl(var(--msg-hue), var(--msg-sat), calc(var(--msg-light) - 10%));
    --text-primary: #f8fafc;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --danger: #ef4444;
    
    --msg-mine: #6366f1; /* Solid Indigo */
    --msg-mine-text: #ffffff;
    --msg-other: #27272a;
    --msg-other-text: #f8fafc;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    height: 100dvh; /* Dynamic viewport height для правильной работы с экранными клавиатурами на телефонах */
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.screen { width: 100%; height: 100%; display: flex; animation: fadeIn 0.3s ease; }
.hidden { display: none !important; }

/* ===== AUTH ===== */
#auth-screen { align-items: center; justify-content: center; background: radial-gradient(circle at top, #18181b 0%, var(--bg-color) 100%); }

.auth-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 48px 40px;
    width: 380px;
    box-shadow: 0 24px 48px rgba(0,0,0,0.4);
}

.logo {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 500;
    letter-spacing: -1.5px;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 32px;
}

.logo span {
    color: var(--accent);
}

.auth-box input {
    width: 100%;
    background: #09090b;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 0.95rem;
    margin-bottom: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-box input:focus { 
    outline: none; 
    border-color: var(--accent); 
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15); 
}

.btn {
    width: 100%;
    padding: 14px;
    background: var(--text-primary);
    color: #000;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    margin-top: 8px;
    transition: transform 0.1s, background 0.2s;
}

.btn:hover { background: #e2e8f0; }
.btn:active { transform: scale(0.98); }

.switch-text { font-size: 0.85rem; color: var(--text-secondary); text-align: center; margin-top: 24px; }
.switch-text span { color: var(--text-primary); cursor: pointer; font-weight: 500; transition: color 0.2s; }
.switch-text span:hover { text-decoration: underline; }

.disclaimer-text {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    text-align: center;
    margin: 10px 0;
    line-height: 1.4;
    padding: 0 10px;
}
.disclaimer-text strong {
    color: #f87171;
    font-weight: 500;
}

.error { color: var(--danger); font-size: 0.85rem; text-align: center; margin-top: 16px; font-weight: 500; }

/* ===== MAIN LAYOUT ===== */
#main-screen { display: flex; padding: 16px; gap: 16px; background: #000; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: 340px;
    min-width: 340px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 20px 16px;
}

.logo-small {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    color: var(--text-primary);
    font-weight: 500;
    letter-spacing: -0.5px;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover { color: var(--text-primary); background: var(--surface-hover); }

/* Search */
.search-wrap { padding: 0 20px 16px; position: relative; }
.search-wrap input {
    width: 100%;
    background: #09090b;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    transition: all 0.2s;
}
.search-wrap input:focus { outline: none; border-color: var(--border-light); }

.search-results {
    position: absolute;
    top: calc(100% - 8px);
    left: 20px;
    right: 20px;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    z-index: 100;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    max-height: 300px;
    overflow-y: auto;
    padding: 8px;
}

.search-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    font-size: 0.95rem;
    font-weight: 500;
}
.search-item:hover { background: var(--surface-hover); }
.search-no-result { padding: 16px; font-size: 0.85rem; color: var(--text-secondary); text-align: center;}

/* Chat List */
.chat-list { flex: 1; overflow-y: auto; padding: 0 12px; }
.empty-hint { font-size: 0.9rem; color: var(--text-tertiary); text-align: center; padding: 40px 20px; line-height: 1.5; }

.chat-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    cursor: pointer;
    border-radius: 12px;
    margin-bottom: 2px;
    transition: background 0.2s;
}
.chat-item:hover { background: rgba(255,255,255,0.02); }
.chat-item.active { background: var(--surface-hover); }

.chat-item-info { flex: 1; overflow: hidden; }
.chat-item-nick { font-size: 0.95rem; font-weight: 500; color: var(--text-primary); margin-bottom: 2px; }
.chat-item-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-badge {
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    margin-left: auto;
    align-self: center;
}

/* Avatar */
.avatar {
    width: 46px;
    height: 46px;
    min-width: 46px;
    border-radius: 50%;
    background: #27272a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    text-transform: uppercase;
}
/* Colorful avatars based on some hash could be added later, for now a premium dark grey */

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    display: flex;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 8px 16px 12px;
    gap: 8px;
    z-index: 10;
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.bottom-nav-item:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}
.bottom-nav-item.active {
    color: var(--accent);
}
.bottom-nav-item span {
    font-size: 0.75rem;
    font-weight: 500;
}

/* ===== SIDEBAR VIEWS ===== */
.sidebar-views-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    width: 100%;
}
.sidebar-view {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: absolute;
    top: 0; left: 0;
    background: var(--surface);
}
#sidebar-settings-view {
    overflow: hidden;
    background: #000;
    display: flex;
    flex-direction: column;
}
#sidebar-settings-view .settings-pages-track {
    position: relative;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

/* ===== SIDEBAR VIEWS — transition-based ===== */
/* Both views always in DOM, translate in/out */
.sidebar-view {
    transform: translateX(0);
    transition: transform 0.28s cubic-bezier(0.25, 1, 0.5, 1);
    pointer-events: all;
}
.sidebar-view.sv-off-left  { transform: translateX(-100%); }
.sidebar-view.sv-off-right { transform: translateX(100%); }

/* ===== SETTINGS SUB-PAGES — transition-based ===== */
.settings-view-content {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;          /* own scroll context, not min-height */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 16px 40px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 24px;
    background: #000;
    pointer-events: none;
    transform: translateX(100%);
    transition: transform 0.26s cubic-bezier(0.25, 1, 0.5, 1);
}
.settings-view-content.page-active {
    transform: translateX(0);
    pointer-events: all;
}
.settings-view-content.page-hidden-left {
    transform: translateX(-100%);
}

/* ===== SETTINGS UI ===== */
.settings-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.settings-group-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-left: 12px;
}
.settings-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
}
.settings-row:last-child {
    border-bottom: none;
}
.settings-control {
    display: flex;
    align-items: center;
    gap: 12px;
}
.color-preview {
    width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--border);
}
.hue-slider {
    width: 100px;
}
.grey-slider {
    -webkit-appearance: none;
    width: 100px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    outline: none;
}
.grey-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.hex-input {
    width: 65px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 4px;
    padding: 2px 4px;
    font-size: 0.85rem;
    text-align: center;
    text-transform: uppercase;
    outline: none;
    font-family: monospace;
}
.hex-input:focus {
    border-color: var(--accent);
}

/* Beautiful Toggle Switch */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255,255,255,0.1);
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 24px;
    border: 1px solid var(--border-light);
}
.toggle-switch .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .slider {
    background-color: var(--accent);
    border-color: var(--accent);
}
.toggle-switch input:checked + .slider:before {
    transform: translateX(20px);
}
.toggle-row {
    cursor: pointer;
    user-select: none;
}

/* Profile Card in Settings */
.settings-profile-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: background 0.2s;
}
.settings-profile-card:hover {
    background: var(--surface-hover);
}
.settings-profile-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.settings-nick {
    font-size: 1.1rem;
    font-weight: 600;
}
.settings-status {
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 500;
}

.settings-action-btn {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 16px;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--border-light);
}
.settings-action-btn:last-child {
    border-bottom: none;
}
.settings-action-btn:hover {
    background: rgba(255,255,255,0.03);
}
.settings-action-btn.danger {
    color: var(--danger);
}
.settings-action-btn.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}
.lang-row {
    padding: 4px;
    gap: 4px;
}
.lang-row .btn {
    flex: 1;
    padding: 10px;
    border-radius: 12px;
}

/* ===== CHAT AREA ===== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 1rem;
}

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

.chat-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(24, 24, 27, 0.8);
    backdrop-filter: blur(12px);
    z-index: 10;
}
.chat-nick { font-weight: 600; font-size: 1.05rem; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

/* ===== СООБЩЕНИЯ ===== */
.msg {
    margin-bottom: 8px;
    max-width: 75%;
    display: flex;
    flex-direction: column;
    animation: fadeUp 0.2s ease-out;
    position: relative;
}
.msg.mine {
    align-self: flex-end;
}
.msg.other {
    align-self: flex-start;
}

.msg-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-break: break-word;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Хвостики сообщений (как в iMessage / WhatsApp) */
.msg-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    width: 20px;
    height: 20px;
    z-index: -1;
}

.msg.mine { align-self: flex-end; color: #fff; border-bottom-right-radius: 4px; }
.dark-text-enabled .msg.mine, .dark-text-enabled .msg.mine .msg-content { color: #000 !important; }
.dark-text-enabled .msg.mine .msg-time, .dark-text-enabled .msg.mine .msg-status, .dark-text-enabled .msg.mine .msg-dots { color: rgba(0,0,0,0.6) !important; }
.dark-text-enabled .msg.mine .msg-edited { color: rgba(0,0,0,0.5) !important; }
.dark-text-enabled .msg.mine .reply-quote { background: rgba(0,0,0,0.1) !important; border-left-color: rgba(0,0,0,0.3) !important; color: #000 !important; }
.dark-text-enabled .msg.mine .msg-content a { color: #000 !important; text-decoration: underline; }

.avatar.dark-text, .profile-avatar.dark-text { color: #000 !important; }

.msg.mine .msg-content {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px hsla(var(--msg-hue), 80%, 30%, 0.3);
}
.msg.mine .msg-content::after {
    right: -8px;
    background: var(--accent);
    border-bottom-left-radius: 16px;
    clip-path: polygon(0 100%, 100% 100%, 0 0);
}

.msg.other .msg-content {
    background: #27272a;
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.msg.other .msg-content::after {
    left: -8px;
    background: #27272a;
    border-bottom-right-radius: 16px;
    clip-path: polygon(100% 100%, 0 100%, 100% 0);
}

/* Форматирование Markdown и ссылки внутри сообщений */
.msg-content a {
    color: #93c5fd;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.msg.mine .msg-content a {
    color: #fff;
    font-weight: 500;
}
.msg-content strong {
    font-weight: 600;
}
.msg-content em {
    font-style: italic;
}
.msg-content code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

.msg-quote {
    background: rgba(0,0,0,0.15);
    border-left: 3px solid rgba(255,255,255,0.5);
    padding: 6px 10px;
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: inherit;
    opacity: 0.9;
    cursor: pointer;
}
.msg.mine .msg-quote { border-left-color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.1); }

.msg-footer {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}
.msg.mine .msg-footer {
    justify-content: flex-end;
}

.msg-time { 
    font-size: 0.65rem; 
    color: rgba(255,255,255,0.5); 
    font-weight: 500;
}
.msg.other .msg-time { color: var(--text-tertiary); }

.msg-dots {
    opacity: 0;
    transition: opacity 0.2s;
    cursor: pointer;
    padding: 0 4px;
    color: var(--text-tertiary);
    font-weight: bold;
    user-select: none;
    font-size: 1.1rem;
    line-height: 1;
}
.msg:hover .msg-dots { opacity: 1; }
@media (max-width: 768px) { .msg-dots { opacity: 1; padding: 4px 8px; } }

.msg-status { 
    display: flex; 
    align-items: center; 
    color: rgba(255,255,255,0.7); 
}
.msg-status svg { width: 14px; height: 14px; }

/* Input Bar */
.reply-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px;
    background: rgba(39, 39, 42, 0.8);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}
.reply-banner-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 3px solid var(--accent);
    padding-left: 8px;
}
.reply-label { color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.reply-text { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.input-bar {
    padding: 16px 24px;
    display: flex;
    gap: 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.input-bar input {
    flex: 1;
    background: #09090b;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 14px 20px;
    border-radius: 24px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}
.input-bar input:focus { outline: none; border-color: var(--border-light); }

.btn-send {
    width: 48px;
    height: 48px;
    background: var(--text-primary);
    border: none;
    border-radius: 50%;
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background 0.2s;
    flex-shrink: 0;
}
.btn-send:hover { background: #e2e8f0; }
.btn-send:active { transform: scale(0.95); }
.btn-send svg { width: 20px; height: 20px; margin-left: -2px; } /* Adjust icon visual center if needed */

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-hover); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

@keyframes fadeIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Mobile */
.mobile-only { display: none !important; }

@media (max-width: 768px) {
    #main-screen { padding: 0; gap: 0; }
    .sidebar { width: 100%; min-width: 100%; border-radius: 0; border: none; }
    .chat-area { border-radius: 0; border: none; display: none; }
    
    .sidebar.mobile-hidden { display: none !important; }
    .chat-area.mobile-visible { display: flex !important; width: 100%; height: 100dvh; }
    
    .mobile-only { display: flex !important; }
    
    .msg { max-width: 85%; } /* На телефоне сообщения могут занимать больше места */
}

/* ===== FINGERPRINT & MODAL ===== */
.chat-topbar-info { display: flex; flex-direction: column; gap: 2px; }
.fingerprint-badge {
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding: 0;
    cursor: pointer;
    transition: color 0.2s;
}
.fingerprint-badge:hover { color: var(--text-primary); }

.fp-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.fp-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 24px 48px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.fp-box h3 { font-size: 1.2rem; font-weight: 600; text-align: center; }
.fp-desc { font-size: 0.85rem; color: var(--text-secondary); text-align: center; line-height: 1.5; }

.fp-box input {
    width: 100%;
    background: #09090b;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.fp-box input:focus { 
    outline: none; 
    border-color: var(--accent); 
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15); 
}

.fp-block { display: flex; flex-direction: column; gap: 6px; }
.fp-block label { font-size: 0.75rem; color: var(--text-tertiary); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.fp-block code {
    background: #09090b;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
    word-break: break-all;
    text-align: center;
}

.fp-warn { font-size: 0.8rem; color: var(--text-secondary); background: #09090b; padding: 12px; border-radius: 10px; line-height: 1.4; border: 1px solid var(--border); text-align: center; }
.btn-danger { background: var(--surface-hover); color: var(--danger); border: 1px solid var(--border); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.3); }
.btn-ghost { background: transparent; color: var(--text-primary); }
.btn-ghost:hover { background: var(--surface-hover); }

/* ===== ДАТЫ В ЧАТЕ ===== */
.date-separator {
    display: flex;
    justify-content: center;
    margin: 16px 0;
    position: sticky;
    top: 8px;
    z-index: 5;
}
.date-separator span {
    background: rgba(24, 24, 27, 0.75);
    backdrop-filter: blur(8px);
    color: var(--text-tertiary);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* ===== КНОПКА СКРОЛЛА ВНИЗ ===== */
.btn-scroll-bottom {
    position: absolute;
    bottom: 80px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 20;
    transition: transform 0.2s, opacity 0.2s, background 0.2s;
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    pointer-events: none;
}
.btn-scroll-bottom:not(.hidden) {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.btn-scroll-bottom:hover {
    background: var(--surface-hover);
    transform: translateY(-2px);
}
.btn-scroll-bottom:active {
    transform: translateY(0) scale(0.95);
}

.unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    border: 2px solid var(--surface);
}

/* ===== КОНТЕКСТНОЕ МЕНЮ ===== */
.context-menu {
    position: fixed;
    background: rgba(24, 24, 27, 0.95);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.6);
    padding: 6px;
    min-width: 180px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: fadeIn 0.15s ease-out;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

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

.context-menu-item.danger {
    color: var(--danger);
}
.context-menu-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.msg-reactions { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.reaction-badge { background: var(--surface-hover); padding: 2px 6px; border-radius: 12px; font-size: 0.8rem; border: 1px solid var(--border); }
.context-reactions { display: flex; justify-content: space-around; padding: 6px 8px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.reaction-btn { background: transparent; border: none; font-size: 1.2rem; cursor: pointer; transition: transform 0.2s; }
.reaction-btn:hover { transform: scale(1.2); }

/* ===== Stories Bar ===== */
.stories-bar {
    padding: 10px 12px 4px;
    border-bottom: 1px solid var(--border);
}
.stories-list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
}
.stories-list::-webkit-scrollbar { display: none; }
.story-bubble {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    cursor: pointer;
}
.story-bubble-ring {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    padding: 2px;
    background: conic-gradient(#6366f1, #a855f7, #ec4899, #6366f1);
    transition: transform 0.2s ease;
}
.story-bubble-ring.seen {
    background: #3f3f46;
}
.story-bubble-ring.is-me {
    background: var(--surface-hover);
    border: 2px dashed rgba(255,255,255,0.25);
}
.story-bubble:hover .story-bubble-ring { transform: scale(1.08); }
.story-bubble-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--bg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    font-size: 1.2rem;
    font-weight: 700;
}
.story-bubble-add-icon {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    font-size: 1.5rem;
    color: rgba(255,255,255,0.4);
}
.story-bubble-nick {
    font-size: 0.68rem;
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.7;
    text-align: center;
}

/* ===== Story View Box ===== */
.story-view-box {
    position: relative;
    max-width: 400px;
    width: 90vw;
    min-height: 280px;
    border-radius: 20px;
    padding: 40px 28px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4c1d95 100%);
    color: #fff;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}

/* ===== Sessions Card ===== */
.session-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    transition: background 0.15s;
}
.session-card:last-child { border-bottom: none; }
.session-card-icon {
    width: 38px; height: 38px; border-radius: 10px;
    background: rgba(99,102,241,0.15);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; color: #818cf8;
}
.session-card-info { flex: 1; min-width: 0; }
.session-card-browser { font-size: 0.88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-card-time { font-size: 0.74rem; opacity: 0.5; margin-top: 2px; }
.session-card-current { font-size: 0.7rem; color: #4ade80; font-weight: 600; margin-top: 2px; }
.session-card-kill {
    background: rgba(239,68,68,0.1);
    border: none; cursor: pointer; border-radius: 8px;
    padding: 7px 12px; font-size: 0.78rem; font-weight: 600;
    color: #f87171; transition: background 0.2s;
    white-space: nowrap;
}
.session-card-kill:hover { background: rgba(239,68,68,0.2); }

/* ===== Вкладки чатов ===== */

.chat-tabs {
    display: flex;
    gap: 8px;
    padding: 0 20px 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}
.chat-tabs button {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 0;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.chat-tabs button:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.chat-tabs button.active {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}
#requests-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    border: 2px solid var(--surface);
}

/* ===== Баннеры (Запросы/Заблокированные) ===== */
.chat-banner {
    padding: 16px 24px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
}
.chat-banner p {
    font-size: 0.95rem;
    color: var(--text-primary);
}
.banner-btns {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}
.banner-btns .btn {
    flex: 1;
    padding: 10px;
    font-size: 0.85rem;
    margin: 0;
}
.btn.danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
}
.chat-banner.blocked {
    color: var(--danger);
    font-weight: 500;
    background: rgba(239, 68, 68, 0.05);
}

/* ===== ПРОФИЛЬ ===== */
.profile-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 32px 28px;
    width: 90%;
    max-width: 360px;
    box-shadow: 0 24px 48px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    position: relative;
    animation: fadeIn 0.2s ease;
}

.profile-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    min-width: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 4px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.profile-nick {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.profile-desc-wrap {
    width: 100%;
    min-height: 48px;
}

.profile-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 24px;
}

.profile-desc-edit {
    width: 100%;
    background: #09090b;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-family: 'Inter', sans-serif;
    resize: vertical;
    min-height: 80px;
    max-height: 160px;
    transition: border-color 0.2s;
    line-height: 1.5;
}
.profile-desc-edit:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.profile-desc-counter {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-align: right;
    margin-top: 4px;
}

.profile-actions {
    display: flex;
    gap: 8px;
    width: 100%;
    margin-top: 4px;
}
.profile-actions .btn {
    flex: 1;
    padding: 10px;
    font-size: 0.85rem;
    margin: 0;
}

/* ===== УПОМИНАНИЯ ===== */
.mention {
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    padding: 0 2px;
    transition: background 0.15s, color 0.15s;
}
.mention:hover {
    background: rgba(99,102,241,0.15);
}
.msg.mine .mention {
    color: rgba(255,255,255,0.9);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.msg.mine .mention:hover {
    background: rgba(255,255,255,0.15);
}

/* ===== СТАТУС В ЧАТ-ШАПКЕ ===== */
.chat-status {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    display: block;
    min-height: 14px;
    transition: color 0.3s;
}
.chat-status.online { color: #10b981; font-weight: 500; }
.chat-status.typing { color: var(--accent); font-style: italic; }

/* ===== ЗАКРЕП ===== */
.pinned-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.pinned-bar:hover { background: var(--surface-hover); }
.pinned-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* ===== ПОМЕТКА «изм.» ===== */
.msg-edited {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    margin-left: 4px;
    font-style: italic;
}

/* ===== НАСТРОЙКИ ===== */
.settings-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 32px 28px;
    width: 90%;
    max-width: 380px;
    position: relative;
    animation: fadeIn 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.settings-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    margin: 0;
}
.settings-section { display: flex; flex-direction: column; gap: 10px; }
.settings-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}
.hue-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(to right, 
        hsl(0, 100%, 50%), hsl(60, 100%, 50%), hsl(120, 100%, 50%), 
        hsl(180, 100%, 50%), hsl(240, 100%, 50%), hsl(300, 100%, 50%), hsl(360, 100%, 50%));
    outline: none;
    margin-top: 8px;
}
.hue-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--border);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    transition: transform 0.1s;
}
.hue-slider::-webkit-slider-thumb:active {
    transform: scale(1.1);
}

/* ===== QR КОД ===== */
.profile-qr {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 8px 0;
}
.profile-qr table { border: 8px solid #fff; border-radius: 8px; }
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    color: var(--accent);
}

/* ===== МОБИЛЬНАЯ АДАПТАЦИЯ НОВЫХ ЭЛЕМЕНТОВ ===== */
@media (max-width: 600px) {
    .settings-box { padding: 24px 16px; }
    .pinned-bar { padding: 6px 12px; }
    .chat-status { font-size: 0.68rem; }
}

/* Auth Lang Switch */
.auth-lang-switch {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 15px;
    font-size: 0.8rem;
    opacity: 0.5;
}

.auth-lang-switch span {
    cursor: pointer;
    transition: opacity 0.2s, color 0.2s;
}

.auth-lang-switch span:hover {
    opacity: 1;
    color: var(--accent);
}

/* ===== SERVER WARNING ===== */
.server-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(245, 158, 11, 0.05));
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-left: 4px solid #f59e0b;
    color: #fbbf24;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 0.82rem;
    line-height: 1.5;
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    animation: fadeUp 0.4s ease-out;
    text-align: left;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.server-warning svg {
    flex-shrink: 0;
    margin-top: 2px;
    color: #f59e0b;
    filter: drop-shadow(0 0 5px rgba(245, 158, 11, 0.4));
}

.server-warning span {
    flex: 1;
}

.sidebar-warning {
    margin: 8px 16px 20px;
    font-size: 0.75rem;
    padding: 12px 14px;
    border-radius: 14px;
}

/* ===== BLACK CHAT MODE ===== */
.black-chat-enabled .chat-area, 
.black-chat-enabled .chat-topbar, 
.black-chat-enabled .input-bar, 
.black-chat-enabled .messages {
    background: #000 !important;
}
.black-chat-enabled .chat-area { border-color: #222; }
.black-chat-enabled .chat-topbar, 
.black-chat-enabled .input-bar { border-color: #222; }
.black-chat-enabled .msg.other .msg-content { background: #111; color: #fff; }
.black-chat-enabled .msg.other .msg-content::after { background: #111; }
.black-chat-enabled .msg-time, 
.black-chat-enabled .msg-status { color: rgba(255,255,255,0.6); }
.black-chat-enabled .chat-nick { color: #fff; }
.black-chat-enabled .chat-topbar-info .fingerprint-badge { color: #888; }
.black-chat-enabled .input-bar input { background: #000; border-color: #333; }
.black-chat-enabled .date-separator span { background: #111; border-color: #333; }

/* ===== WHITE STATUS MODE ===== */
body.white-status-enabled .msg.mine .msg-time, 
body.white-status-enabled .msg.mine .msg-status, 
body.white-status-enabled .msg.mine .msg-dots,
body.white-status-enabled .msg.other .msg-time, 
body.white-status-enabled .msg.other .msg-status, 
body.white-status-enabled .msg.other .msg-dots,
body.white-status-enabled .msg-status svg { 
    color: #ffffff !important; 
    stroke: #ffffff !important;
    opacity: 1 !important;
}
body.white-status-enabled .msg-edited {
    color: rgba(255,255,255,0.8) !important;
}


