:root {
    --bg-main: #0b0f19;
    --bg-sidebar: #111827;
    --bg-chat: #0e1320;
    --border-color: #1f2937;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --card-bg: rgba(17, 24, 39, 0.7);
    --bubble-in: #1f2937;
    --bubble-out: #4f46e5;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: radial-gradient(circle at 50% 50%, #111827 0%, #080b11 100%);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- ЭКРАН PASSCODE --- */
.passcode-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.passcode-container {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    width: 90%;
    max-width: 380px;
    text-align: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6), 0 0 60px rgba(79, 70, 229, 0.08);
}

.passcode-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 10px;
}

.passcode-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 30px;
}

.passcode-input {
    width: 100%;
    background-color: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: white;
    font-size: 24px;
    letter-spacing: 6px;
    text-align: center;
    padding: 12px;
    border-radius: 12px;
    outline: none;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

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

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

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

.error-text {
    color: #ef4444;
    font-size: 14px;
    margin-top: 12px;
    min-height: 20px;
}

/* --- ОСНОВНОЙ ИНТЕРФЕЙС ПРИЛОЖЕНИЯ --- */
.app-container {
    display: none; /* Скрыто до авторизации */
    width: 100%;
    height: 100%;
    display: flex;
}

/* Боковая панель */
.sidebar {
    width: 320px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 100;
        transition: transform 0.3s ease;
    }
    
    .sidebar.hidden {
        transform: translateX(-100%);
    }
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-title {
    font-size: 18px;
    font-weight: 700;
    color: white;
}

.chats-list {
    flex-grow: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.02);
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-item:hover {
    background-color: rgba(255,255,255,0.02);
}

.chat-item.active {
    background-color: rgba(79, 70, 229, 0.15);
    border-left: 3px solid var(--accent);
}

.avatar {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-details {
    flex-grow: 1;
    min-width: 0;
}

.chat-name-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

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

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

.unread-badge {
    background-color: var(--accent);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

/* Окно переписки */
.chat-window {
    flex-grow: 1;
    background-color: var(--bg-chat);
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    height: 64px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-sidebar);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.messages-container {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message-bubble {
    max-width: 70%;
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.message-bubble.in {
    background-color: var(--bubble-in);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-bubble.out {
    background-color: var(--bubble-out);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-sidebar);
    display: flex;
    gap: 12px;
}

.message-input {
    flex-grow: 1;
    background-color: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    outline: none;
    font-size: 14px;
}

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

.btn-send {
    background-color: var(--accent);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.btn-send:hover {
    background-color: var(--accent-hover);
}

.back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

@media (max-width: 768px) {
    .back-btn {
        display: block;
    }
}

.no-chat-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    gap: 16px;
}

.no-chat-icon {
    font-size: 48px;
}

/* Кнопка подписки на пуши */
.push-status-btn {
    background-color: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.push-status-btn.subscribed {
    background-color: rgba(79, 70, 229, 0.15);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* --- ЭКРАН АВТОРИЗАЦИИ MAX (QR-КОД) --- */
.max-auth-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

.max-auth-container {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    width: 90%;
    max-width: 420px;
    text-align: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.max-auth-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 12px;
    color: white;
}

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

.qr-container {
    background: white;
    padding: 16px;
    border-radius: 16px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.qr-container p {
    color: #111827;
    font-size: 12px;
    margin-bottom: 12px;
    font-weight: 500;
}

.qr-container img {
    width: 220px;
    height: 220px;
    display: block;
}

.btn-secondary {
    background-color: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background-color: rgba(255,255,255,0.1);
    border-color: var(--text-secondary);
}

/* Простой спиннер */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s ease-in-out infinite;
    margin: 20px 0;
}

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

/* Переключатель методов входа */
.auth-method-selector {
    display: flex;
    gap: 10px;
    width: 100%;
}

.auth-method-selector button {
    flex: 1;
    padding: 10px;
    font-size: 13px;
}

.auth-method-selector button.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Выход и профиль пользователя */
.logout-btn {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    background-color: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}

.sidebar-profile {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: rgba(255, 255, 255, 0.01);
}

.profile-avatar {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #10b981, #059669);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 14px;
}

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

.profile-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* --- ДАШБОРД УВЕДОМЛЕНИЙ --- */
.dashboard-container {
    width: 100%;
    max-width: 850px;
    height: 85vh;
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6), 0 0 80px rgba(79, 70, 229, 0.08);
    backdrop-filter: blur(10px);
}

@media (max-width: 768px) {
    .dashboard-container {
        height: 100vh;
        border-radius: 0;
        border: none;
    }
}

.dashboard-header {
    height: 72px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(17, 24, 39, 0.9);
    flex-shrink: 0; /* Prevent the header from shrinking when content overflows */
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-left .sidebar-profile {
    border-top: none;
    padding: 0;
    background: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dashboard-content {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background-color: var(--bg-main);
}

.info-card {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.info-icon {
    font-size: 20px;
}

.info-text {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.loading-chats {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Стилизация тумблера переключателя */
.chat-item .switch-container {
    margin-left: auto;
    flex-shrink: 0;
}

.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #374151;
    transition: .3s;
    border-radius: 26px;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: #f3f4f6;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

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

input:checked + .slider:before {
    transform: translateX(20px);
    background-color: #ffffff;
}

/* Карточка чата */
.chat-item {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    margin-bottom: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: default;
    transition: transform 0.2s, border-color 0.2s, opacity 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.chat-item:hover {
    border-color: rgba(99, 102, 241, 0.4);
    background-color: rgba(255, 255, 255, 0.01);
}

.chat-item.muted {
    opacity: 0.5;
}

/* --- СТИЛИ НАСТРОЕК И УПРАВЛЕНИЯ АККАУНТОМ --- */
.settings-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    margin-top: 16px;
}

.settings-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 12px;
    color: white;
}

.account-details-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.account-details-row strong {
    color: white;
}

.settings-actions {
    display: flex;
    gap: 12px;
}

.btn-danger {
    background-color: #dc2626;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    height: 40px;
}

.btn-danger:hover {
    background-color: #b91c1c;
}

.btn-danger:active {
    transform: scale(0.98);
}

.btn-secondary {
    background-color: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    height: 40px;
}

.btn-secondary:hover {
    background-color: rgba(255,255,255,0.1);
}

.settings-form {
    display: flex;
    flex-direction: column;
}

/* --- СТИЛИ ВКЛАДОК НАВИГАЦИИ (TABS) --- */
.nav-tabs {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tab-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.tab-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

@media (max-width: 768px) {
    .nav-tabs {
        margin-left: 10px !important;
        gap: 4px;
    }
    
    .tab-btn {
        padding: 4px 10px;
        font-size: 12px;
        height: 30px;
    }
}

/* --- СТИЛИ ДЛЯ ИНСТРУКЦИИ iOS --- */
.ios-instruction-card {
    border-left: 4px solid var(--accent) !important;
    background: rgba(79, 70, 229, 0.05) !important;
}

.ios-login-instruction {
    display: none;
    margin-top: 20px;
    padding: 12px;
    background: rgba(79, 70, 229, 0.08);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    text-align: left;
    font-size: 12px;
    line-height: 1.4;
}

@media (max-width: 768px) {
    .dashboard-header {
        height: auto !important;
        min-height: 64px;
        padding: 10px 16px !important;
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        align-items: center !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
    }
    
    .header-left {
        grid-column: 1 / 2;
        gap: 8px !important;
        display: flex !important;
        align-items: center !important;
    }
    
    .app-title {
        display: none !important;
    }
    
    .header-actions {
        grid-column: 2 / 3;
        display: flex !important;
        gap: 8px !important;
        margin-left: auto;
    }
    
    .nav-tabs {
        grid-column: 1 / 3;
        margin-left: 0 !important;
        margin-top: 4px;
        justify-content: flex-start;
        width: 100%;
    }
    
    .push-status-btn, .logout-btn {
        padding: 6px 10px !important;
        font-size: 11px !important;
        white-space: nowrap;
    }
    
    .header-left .sidebar-profile {
        padding: 0 !important;
        gap: 8px !important;
    }
    
    .profile-avatar {
        width: 32px !important;
        height: 32px !important;
        font-size: 12px !important;
    }
    
    .profile-name {
        font-size: 12px !important;
    }
    
    .profile-phone {
        font-size: 10px !important;
    }
    
    .settings-actions {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .settings-actions button {
        width: 100% !important;
        height: 40px !important;
        padding: 0 16px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        white-space: nowrap !important;
        text-align: center !important;
    }
}

/* --- CUSTOM SCROLLBARS --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* --- PREMIUM DESKTOP VIEW STYLING --- */
@media (min-width: 769px) {
    body {
        background: radial-gradient(circle at 50% 50%, #151b2e 0%, #060912 100%);
    }
    .app-container {
        justify-content: center;
        align-items: center;
        background: transparent;
        padding: 20px;
    }
    .dashboard-container {
        max-width: 900px;
        height: 85vh;
        border: 1px solid rgba(255, 255, 255, 0.08);
        background-color: rgba(17, 24, 39, 0.75);
        backdrop-filter: blur(20px) saturate(120%);
        box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6), 0 0 60px rgba(79, 70, 229, 0.12);
        transition: box-shadow 0.3s ease;
    }
    .dashboard-container:hover {
        box-shadow: 0 30px 60px rgba(0, 0, 0, 0.7), 0 0 80px rgba(79, 70, 229, 0.18);
    }
    
    /* Glassmorphism for settings cards */
    .settings-card {
        background: rgba(31, 41, 55, 0.45);
        border: 1px solid rgba(255, 255, 255, 0.05);
        backdrop-filter: blur(10px);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
        transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    }
    .settings-card:hover {
        border-color: rgba(99, 102, 241, 0.25);
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
        transform: translateY(-2px);
    }
    
    /* Form interactive styling */
    .passcode-container {
        border: 1px solid rgba(255, 255, 255, 0.08);
        background: rgba(17, 24, 39, 0.8);
        backdrop-filter: blur(20px) saturate(120%);
        box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6), 0 0 60px rgba(79, 70, 229, 0.1);
        transition: box-shadow 0.3s ease, transform 0.3s ease;
    }
    .passcode-container:hover {
        box-shadow: 0 30px 60px rgba(0, 0, 0, 0.7), 0 0 80px rgba(79, 70, 229, 0.15);
        transform: translateY(-2px);
    }
    
    .passcode-input {
        transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
    }
    .passcode-input:focus {
        border-color: var(--accent);
        box-shadow: 0 0 10px rgba(79, 70, 229, 0.3);
        background-color: rgba(255, 255, 255, 0.08);
    }
    
    /* Buttons and tabs hover transitions */
    .btn-primary, .btn-secondary, .btn-danger, .tab-btn {
        transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .btn-primary:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    }
    .btn-secondary:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(255, 255, 255, 0.05);
    }
    .btn-danger:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4);
    }
    
    /* Switch animation */
    .slider {
        transition: background-color 0.3s, border-color 0.3s;
    }
    .slider:before {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* List items hover effect */
    .chat-item {
        transition: border-color 0.25s, background-color 0.25s, transform 0.2s;
    }
    .chat-item:hover {
        transform: translateX(4px);
    }
}

