/* ═══════════════════════════════════════════════════════════════
   NEXUS — единая дизайн-система
   Убраны: game-bg, --primary: #00ff9d (Courier New как основной шрифт)
   Добавлено: low-end класс, prefers-reduced-motion, единые переменные
   ═══════════════════════════════════════════════════════════════ */

/* ── Сброс ──────────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* ── Системный шрифт — читаемый на всех устройствах ─────────── */
:root {
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'DM Mono', 'SF Mono', 'Fira Code', 'Courier New', monospace;

    /* Цвета */
    --bg-base:    #09090f;
    --bg-surface: #0f0f1a;
    --bg-raised:  #161623;
    --bg-overlay: rgba(255,255,255,0.05);

    --text:           rgba(255,255,255,0.92);
    --text-secondary: rgba(255,255,255,0.48);
    --text-tertiary:  rgba(255,255,255,0.28);

    --border:       rgba(255,255,255,0.08);
    --border-focus: rgba(88,101,242,0.55);

    --primary:      #5865f2;
    --primary-dark: #4752c4;
    --primary-glow: rgba(88,101,242,0.35);

    --danger:  #ed4245;
    --success: #3ba55c;
    --warning: #faa81a;
    --gold:    #ffd700;

    /* Радиусы */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;

    /* Тени */
    --shadow-sm:  0 2px 8px rgba(0,0,0,0.3);
    --shadow-md:  0 4px 20px rgba(0,0,0,0.4);
    --shadow-lg:  0 8px 40px rgba(0,0,0,0.55);
    --shadow-xl:  0 16px 60px rgba(0,0,0,0.7);

    /* Blur — уменьшен с 50px до разумных значений */
    --blur-sm:  blur(8px);
    --blur-md:  blur(16px);
    --blur-lg:  blur(24px);

    /* Переходы */
    --transition-fast:   0.1s ease;
    --transition-normal: 0.2s ease;
    --transition-slow:   0.35s cubic-bezier(0.22,1,0.36,1);
}

/* ── Low-end устройства: убираем всё тяжёлое ────────────────── */
.low-end * {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    filter: none !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.1ms !important;
    will-change: auto !important;
}
.low-end .sidebar,
.low-end .settings-panel,
.low-end .chat-header,
.low-end .sidebar-header {
    background: var(--bg-surface) !important;
    box-shadow: none !important;
}
.low-end .message-content {
    background: rgba(255,255,255,0.08) !important;
}

/* ── prefers-reduced-motion ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.1ms !important;
    }
}

/* ── Мобилка: убиваем тяжёлые фильтры для 60fps ──────────────
   (дублируется в main.html для надёжности, здесь — master copy) */
@media (max-width: 768px) {
    .sidebar,
    .chat-container,
    .chat-header,
    .sidebar-header,
    .settings-panel,
    .message-input-container,
    .message-input-wrapper,
    .message-content,
    .icon-btn,
    .action-btn,
    .nx-rail,
    .nx-mobile-nav {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        filter: none !important;
    }
}

/* ══════════════════════════════════════════════════════════════
   СТРАНИЦА АВТОРИЗАЦИИ (index.html)
   Изолирована в .nx-auth-page чтобы не конфликтовать с main.html
   ══════════════════════════════════════════════════════════════ */

/* ── Фон страницы авторизации ───────────────────────────────── */
body.nx-auth-page {
    font-family: var(--font-ui);
    background: var(--bg-base);
    min-height: 100dvh;
    color: var(--text);
    overflow-x: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Градиентный фон — лёгкий, без game-эффектов */
body.nx-auth-page::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 70% 50% at 20% 20%, rgba(88,101,242,0.12) 0%, transparent 60%),
        radial-gradient(ellipse 60% 60% at 80% 80%, rgba(88,101,242,0.07) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

/* Анимированные орбы — лёгкая альтернатива звёздам */
body.nx-auth-page::after {
    content: '';
    position: fixed;
    width: 500px; height: 500px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(88,101,242,0.08) 0%, transparent 70%);
    top: -150px; right: -150px;
    pointer-events: none;
    z-index: 0;
    animation: authOrb 8s ease-in-out infinite alternate;
}

@keyframes authOrb {
    from { transform: translate(0, 0) scale(1); opacity: 0.6; }
    to   { transform: translate(-30px, 40px) scale(1.1); opacity: 1; }
}

/* Звёзды — CSS-based вместо JS (нет нагрузки на DOM) */
.nx-auth-stars {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}
.nx-auth-stars::before,
.nx-auth-stars::after {
    content: '';
    position: absolute;
    width: 2px; height: 2px;
    border-radius: 50%;
    background: white;
    box-shadow:
        80px 120px 0 rgba(255,255,255,0.15),
        200px 60px 0 rgba(255,255,255,0.1),
        350px 200px 0 rgba(255,255,255,0.2),
        500px 80px 0 rgba(255,255,255,0.12),
        650px 300px 0 rgba(255,255,255,0.08),
        800px 150px 0 rgba(255,255,255,0.18),
        100px 350px 0 rgba(255,255,255,0.1),
        420px 420px 0 rgba(255,255,255,0.15),
        720px 420px 0 rgba(255,255,255,0.1),
        150px 500px 0 rgba(255,255,255,0.12),
        600px 550px 0 rgba(255,255,255,0.08),
        900px 100px 0 rgba(255,255,255,0.14),
        1000px 300px 0 rgba(255,255,255,0.1),
        1100px 200px 0 rgba(255,255,255,0.08),
        1200px 450px 0 rgba(255,255,255,0.12),
        300px 600px 0 rgba(255,255,255,0.1),
        750px 650px 0 rgba(255,255,255,0.08),
        50px 700px 0 rgba(255,255,255,0.15);
    animation: starTwinkle 4s ease-in-out infinite alternate;
}
.nx-auth-stars::after {
    width: 1px; height: 1px;
    box-shadow:
        160px 90px 0 rgba(255,255,255,0.2),
        330px 140px 0 rgba(255,255,255,0.12),
        480px 260px 0 rgba(255,255,255,0.18),
        630px 190px 0 rgba(255,255,255,0.1),
        780px 340px 0 rgba(255,255,255,0.15),
        920px 220px 0 rgba(255,255,255,0.08),
        1050px 380px 0 rgba(255,255,255,0.12),
        250px 460px 0 rgba(255,255,255,0.2),
        560px 510px 0 rgba(255,255,255,0.1),
        870px 570px 0 rgba(255,255,255,0.15);
    animation: starTwinkle 6s ease-in-out infinite alternate-reverse;
}
@keyframes starTwinkle {
    from { opacity: 0.4; }
    to   { opacity: 1; }
}

/* На мобилке — убираем орб-анимации */
@media (max-width: 768px) {
    body.nx-auth-page::after { display: none; }
    @keyframes authOrb { from{} to{} }
}

/* ── Центральный контейнер авторизации ──────────────────────── */
.nx-auth-wrap {
    position: relative;
    z-index: 1;
    width: 100%;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

/* ── Карточка формы ─────────────────────────────────────────── */
.nx-auth-card {
    width: 100%;
    max-width: 400px;
    background: rgba(15,15,26,0.85);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: var(--radius-xl);
    padding: 40px 36px 36px;
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(88,101,242,0.08);
    backdrop-filter: var(--blur-md);
    -webkit-backdrop-filter: var(--blur-md);
    animation: authFadeIn 0.4s cubic-bezier(0.22,1,0.36,1);
}

@keyframes authFadeIn {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes authShake {
    0%,100% { transform: translateX(0); }
    15%,45%,75% { transform: translateX(-6px); }
    30%,60%,90% { transform: translateX(6px); }
}

/* На мобилке — карточка занимает весь экран снизу */
@media (max-width: 480px) {
    .nx-auth-wrap {
        align-items: flex-end;
        padding: 0;
    }
    .nx-auth-card {
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
        max-width: 100%;
        border-bottom: none;
        background: rgba(13,13,22,0.98);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        animation: authSlideUp 0.35s cubic-bezier(0.22,1,0.36,1);
    }
    @keyframes authSlideUp {
        from { transform: translateY(100%); opacity: 0.8; }
        to   { transform: translateY(0); opacity: 1; }
    }
    body.nx-auth-page::before {
        display: none;
    }
}

/* ── Логотип ──────────────────────────────────────────────────── */
.nx-auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.nx-auth-logo-icon {
    width: 72px; height: 72px;
    border-radius: 22px;
    overflow: hidden;
    margin: 0 auto 16px;
    box-shadow: 0 8px 32px rgba(88,101,242,0.35);
}

.nx-auth-logo-icon img {
    width: 100%; height: 100%;
    display: block;
}

.nx-auth-logo h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
    margin-bottom: 4px;
    font-family: var(--font-ui);
}

.nx-auth-logo p {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ── Поля ввода ──────────────────────────────────────────────── */
.nx-auth-field {
    margin-bottom: 12px;
}

.nx-auth-field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 6px;
    padding-left: 2px;
}

.nx-auth-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.nx-auth-input {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font-ui);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.nx-auth-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(88,101,242,0.12);
}

.nx-auth-input::placeholder {
    color: var(--text-tertiary);
}

/* Кнопка показать/скрыть пароль */
.nx-auth-eye {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    line-height: 1;
    transition: color 0.15s;
}
.nx-auth-eye:hover { color: var(--text); }

/* ── Уведомление первого пользователя ───────────────────────── */
.nx-auth-first-notice {
    display: none;
    background: rgba(255,215,0,0.08);
    border: 1px solid rgba(255,215,0,0.25);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    margin: 4px 0 12px;
    font-size: 12.5px;
    color: rgba(255,215,0,0.85);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: goldPulse 2s ease-in-out infinite;
}
@keyframes goldPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(255,215,0,0); }
    50%      { box-shadow: 0 0 12px rgba(255,215,0,0.2); }
}

/* ── Ошибка ──────────────────────────────────────────────────── */
.nx-auth-error {
    display: none;
    color: #ff6b6b;
    font-size: 13px;
    padding: 10px 14px;
    background: rgba(237,66,69,0.08);
    border: 1px solid rgba(237,66,69,0.2);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    animation: authFadeIn 0.2s ease;
}

/* ── Кнопка отправки ─────────────────────────────────────────── */
.nx-auth-btn {
    width: 100%;
    padding: 13px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    margin-top: 4px;
    box-shadow: 0 4px 16px rgba(88,101,242,0.4);
}

.nx-auth-btn:hover {
    background: var(--primary-dark);
    box-shadow: 0 6px 20px rgba(88,101,242,0.5);
    transform: translateY(-1px);
}

.nx-auth-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 8px rgba(88,101,242,0.3);
}

.nx-auth-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ── Переключатель режима ────────────────────────────────────── */
.nx-auth-toggle {
    text-align: center;
    margin-top: 20px;
    font-size: 13.5px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s;
    user-select: none;
    -webkit-user-select: none;
}

.nx-auth-toggle:hover { color: var(--primary); }

/* ── PWA Install Banner ─────────────────────────────────────── */
#pwa-banner {
    display: none;
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(88,101,242,0.12);
    border: 1px solid rgba(88,101,242,0.3);
    backdrop-filter: var(--blur-sm);
    -webkit-backdrop-filter: var(--blur-sm);
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    z-index: 9999;
    align-items: center;
    gap: 12px;
    max-width: 340px;
    width: calc(100% - 40px);
    box-shadow: var(--shadow-md);
    animation: authFadeIn 0.3s ease;
}

#pwa-banner span {
    color: var(--text);
    font-size: 14px;
    flex: 1;
    line-height: 1.3;
    font-family: var(--font-ui);
}

#pwa-install-btn {
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    font-family: var(--font-ui);
}

#pwa-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

/* ══════════════════════════════════════════════════════════════
   СКРОЛЛБАРЫ (глобально)
   ══════════════════════════════════════════════════════════════ */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
