/* ────────────────────────────────────────
   THEME
──────────────────────────────────────── */
:root {
    --bg: #0b0b10;
    --surface: rgba(20,20,30,.72);
    --surface2: rgba(255,255,255,.04);

    --border: rgba(255,255,255,.08);

    --accent: #6c63ff;
    --accent2: #5a54ff;

    --text: #f4f4f7;
    --text-muted: #9ca3af;

    --danger: #ff7d7d;

    --radius: 28px;
    --radius-sm: 16px;

    --shadow:
            0 10px 40px rgba(0,0,0,.45),
            inset 0 1px 0 rgba(255,255,255,.04);

    --font-head: 'Space Grotesk', sans-serif;
    --font-body: 'DM Sans', system-ui, sans-serif;

    --transition: .2s ease;
}

/* ────────────────────────────────────────
   RESET
──────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    background: var(--bg);
    color: var(--text);

    font-family: var(--font-body);

    -webkit-font-smoothing: antialiased;
}

body {
    overflow: hidden;
}

.hidden {
    display: none !important;
}

button {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: inherit;
}

input {
    outline: none;
    border: none;
    font-family: inherit;
}

/* ════════════════════════════════════════
   AUTH SCREENS
════════════════════════════════════════ */
#screen-login,
#screen-nickname {
    position: relative;

    min-height: 100dvh;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    padding: 24px;

    background:
            radial-gradient(circle at top left, rgba(108,99,255,.25), transparent 30%),
            radial-gradient(circle at bottom right, rgba(80,120,255,.18), transparent 30%),
            linear-gradient(135deg, #0b0b10 0%, #11111a 100%);
}

/* glow */
#screen-login::before,
#screen-login::after,
#screen-nickname::before,
#screen-nickname::after {
    content: '';

    position: absolute;

    width: 420px;
    height: 420px;

    border-radius: 50%;

    filter: blur(90px);

    opacity: .18;

    pointer-events: none;
}

#screen-login::before,
#screen-nickname::before {
    background: #6c63ff;

    top: -120px;
    left: -100px;
}

#screen-login::after,
#screen-nickname::after {
    background: #4f8cff;

    bottom: -160px;
    right: -120px;
}

.login-main {
    width: 100%;
    display: flex;
    justify-content: center;

    z-index: 2;
}

.login-card,
.nick-card {
    position: relative;

    width: 100%;
    max-width: 430px;

    padding: 44px;

    background: var(--surface);

    border: 1px solid var(--border);

    backdrop-filter: blur(24px);

    border-radius: var(--radius);

    box-shadow: var(--shadow);

    overflow: hidden;

    animation: fadeUp .5s ease;
}

.login-card::before,
.nick-card::before {
    content: '';

    position: absolute;
    inset: 0;

    background:
            linear-gradient(
                    145deg,
                    rgba(255,255,255,.05),
                    transparent 30%
            );

    pointer-events: none;
}

.login-logo {
    position: relative;

    width: 74px;
    height: 74px;

    margin: 0 auto 28px;

    border-radius: 24px;

    background:
            linear-gradient(
                    135deg,
                    #7c74ff,
                    #5a54ff
            );

    display: flex;
    align-items: center;
    justify-content: center;

    box-shadow:
            0 10px 32px rgba(108,99,255,.42);
}

.login-logo::after {
    content: '';

    position: absolute;
    inset: -2px;

    border-radius: inherit;

    border: 1px solid rgba(255,255,255,.12);
}

.login-logo svg {
    width: 34px;
    height: 34px;
}

.login-card h1,
.nick-card h2 {
    font-family: var(--font-head);

    font-size: 2rem;

    letter-spacing: -.04em;

    margin-bottom: 10px;

    text-align: center;
}
.login-card h1 {
    margin-bottom: 28px;
}

.nick-hint {
    display: flex;
    justify-content: center;
    gap: 10px;

    margin-bottom: 26px;

    color: rgba(255,255,255,.38);

    font-size: .78rem;

    letter-spacing: .08em;

    text-transform: uppercase;
}

.empty-state {
    display: flex;
    flex-direction: column;

    align-items: center;
    justify-content: center;

    text-align: center;

    height: 100%;

    padding: 40px;
}

.empty-state-icon {
    width: 92px;
    height: 92px;

    border-radius: 28px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin-bottom: 28px;

    background:
            linear-gradient(
                    135deg,
                    rgba(124,116,255,.22),
                    rgba(91,84,255,.10)
            );

    border: 1px solid rgba(255,255,255,.06);

    box-shadow:
            0 10px 40px rgba(108,99,255,.18);

    backdrop-filter: blur(18px);
}

.empty-state-icon svg {
    width: 42px;
    height: 42px;

    color: #b7b4ff;
}

.empty-state h2 {
    font-size: 1.8rem;

    font-family: var(--font-head);

    letter-spacing: -.03em;

    margin-bottom: 12px;
}

/* ════════════════════════════════════════
   CHAT OPEN — добавить в style.css
════════════════════════════════════════ */

/* Открытый чат */
.chat-open {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    height: 64px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    background: rgba(15,15,22,.72);
    backdrop-filter: blur(18px);
    flex-shrink: 0;
    font-weight: 600;
    font-size: 1rem;
}

/* Область сообщений */
.messages-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.08) transparent;
}

/* Drag-over состояние */
.messages-wrap.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -8px;
    background: rgba(108,99,255,.06);
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Пузырьки */
.msg-bubble {
    max-width: 68%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: .92rem;
    line-height: 1.55;
    position: relative;
    word-break: break-word;
    animation: fadeUp .18s ease;
}

.msg-bubble.mine {
    align-self: flex-end;
    background: linear-gradient(135deg, #7c74ff, #5b54ff);
    border-bottom-right-radius: 6px;
    color: #fff;
}

.msg-bubble.theirs {
    align-self: flex-start;
    background: rgba(255,255,255,.07);
    border-bottom-left-radius: 6px;
    color: var(--text);
}

.msg-time {
    display: block;
    font-size: .72rem;
    margin-top: 4px;
    opacity: .55;
    text-align: right;
}

/* Загрузка */
.msg-loading {
    text-align: center;
    color: var(--text-muted);
    font-size: .9rem;
    padding: 20px;
}

/* Изображение в сообщении */
.msg-img {
    max-width: 260px;
    max-height: 260px;
    border-radius: 12px;
    display: block;
    object-fit: cover;
    cursor: pointer;
}

/* Файл (не картинка) */
.msg-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0 6px;
    text-decoration: none;
    color: inherit;
}

.msg-file:hover { opacity: .8; }

.msg-file-info {
    display: flex;
    flex-direction: column;
}

.msg-file-name {
    font-size: .88rem;
    font-weight: 600;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msg-file-size {
    font-size: .75rem;
    opacity: .6;
    margin-top: 2px;
}

/* Прогресс загрузки */
.uploading { opacity: .7; }

.upload-progress {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 160px;
}

.upload-name {
    font-size: .84rem;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-bar {
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,.18);
    overflow: hidden;
}

.upload-bar-fill {
    height: 100%;
    background: white;
    width: 0%;
    transition: width .2s ease;
    border-radius: 2px;
}

/* ── Панель ввода ───────────────────── */
.input-wrap {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-top: 1px solid rgba(255,255,255,.06);
    background: rgba(15,15,22,.72);
    backdrop-filter: blur(18px);
    flex-shrink: 0;
}

.msg-input {
    flex: 1;
    height: 48px;
    padding: 0 16px;
    border-radius: 14px;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.08);
    color: white;
    font-size: .94rem;
    font-family: inherit;
    transition: border-color .2s ease, box-shadow .2s ease;
}

.msg-input::placeholder { color: rgba(255,255,255,.3); }

.msg-input:focus {
    border-color: rgba(108,99,255,.8);
    box-shadow: 0 0 0 4px rgba(108,99,255,.14);
    outline: none;
}

/* Кнопка скрепки */
.btn-attach {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255,255,255,.04);
    color: var(--text-muted);
    border: 1px solid rgba(255,255,255,.07);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s ease, color .2s ease;
    flex-shrink: 0;
}

.btn-attach:hover {
    background: rgba(255,255,255,.08);
    color: white;
}

/* Кнопка отправки */
.btn-send {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, #7c74ff, #5b54ff);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(108,99,255,.32);
    flex-shrink: 0;
    transition: transform .18s ease, box-shadow .18s ease;
}

.btn-send:hover  { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(108,99,255,.42); }
.btn-send:active { transform: scale(.94); }

/* ── Поиск — выпадающий список ──────── */
.search-results {
    position: absolute;
    left: 18px;
    right: 18px;
    top: 76px;
    z-index: 100;
    background: rgba(22,22,34,.96);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 16px;
    box-shadow: 0 12px 36px rgba(0,0,0,.5);
    backdrop-filter: blur(18px);
    overflow: hidden;
}

.search-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: .9rem;
    transition: background .15s ease;
}

.search-item:hover  { background: rgba(108,99,255,.14); }

.search-empty {
    padding: 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: .88rem;
}

/* ── Диалог — элемент списка ────────── */
.dialog-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.dialog-nick {
    font-weight: 600;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dialog-preview {
    font-size: .8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.dialogs-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: .86rem;
    padding: 28px 16px;
}

/* ── Аватар маленький ───────────────── */
.avatar-sm {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #7c74ff, #5a54ff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .76rem;
    font-weight: 700;
    color: white;
}

/* ── Toast ──────────────────────────── */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: rgba(30,30,44,.96);
    border: 1px solid rgba(255,255,255,.1);
    color: white;
    padding: 12px 22px;
    border-radius: 14px;
    font-size: .9rem;
    backdrop-filter: blur(18px);
    box-shadow: 0 8px 28px rgba(0,0,0,.4);
    opacity: 0;
    transition: opacity .25s ease, transform .25s ease;
    z-index: 9999;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Sidebar: позиция для выпадайки ─── */
.search-wrap { position: relative; }

/* ── Mobile ─────────────────────────── */
@media (max-width: 700px) {
    .chat-open { width: 100%; }
    .msg-bubble { max-width: 85%; }
    .msg-img { max-width: 200px; }
}

.empty-state p {
    max-width: 340px;

    color: rgba(255,255,255,.46);

    line-height: 1.7;

    font-size: .96rem;
}

.login-card p,
.nick-card p {
    text-align: center;

    color: var(--text-muted);

    line-height: 1.6;

    font-size: .95rem;

    margin-bottom: 34px;
}

/* ────────────────────────────────────────
   BUTTONS
──────────────────────────────────────── */
.btn-google-fallback,
.btn-primary {
    position: relative;

    width: 100%;

    height: 56px;

    border-radius: 18px;

    font-size: .96rem;
    font-weight: 600;

    transition:
            transform .18s ease,
            opacity .18s ease,
            box-shadow .18s ease;

    overflow: hidden;
}

.btn-google-fallback {
    background: white;

    color: #111827;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;

    box-shadow:
            0 8px 24px rgba(255,255,255,.12);
}

.btn-primary {
    margin-top: 22px;

    color: white;

    background:
            linear-gradient(
                    135deg,
                    #7c74ff,
                    #5b54ff
            );

    box-shadow:
            0 12px 30px rgba(108,99,255,.35);
}

.btn-google-fallback:hover,
.btn-primary:hover {
    transform: translateY(-2px);
}

.btn-google-fallback:active,
.btn-primary:active {
    transform: scale(.985);
}

/* ────────────────────────────────────────
   INPUT
──────────────────────────────────────── */
.field-input {
    width: 100%;

    height: 58px;

    padding: 0 18px;

    border-radius: 18px;

    background: rgba(255,255,255,.04);

    border: 1px solid rgba(255,255,255,.08);

    color: white;

    font-size: .96rem;

    transition:
            border-color .2s ease,
            background .2s ease,
            box-shadow .2s ease;
}

.field-input::placeholder {
    color: rgba(255,255,255,.32);
}

.field-input:focus {
    border-color: rgba(108,99,255,.85);

    background: rgba(255,255,255,.06);

    box-shadow:
            0 0 0 4px rgba(108,99,255,.15);
}

.field-input.error {
    border-color: var(--danger);
}

.field-error {
    min-height: 20px;

    margin-top: 10px;

    color: var(--danger);

    font-size: .82rem;
}

/* ────────────────────────────────────────
   FOOTER
──────────────────────────────────────── */
.login-footer {
    position: absolute;

    bottom: 24px;
    left: 0;
    right: 0;

    text-align: center;

    z-index: 2;

    font-size: .84rem;

    color: var(--text-muted);
}

.login-footer a {
    color: inherit;

    text-decoration: none;

    transition: opacity .2s ease;
}

.login-footer a:hover {
    opacity: .7;
}

/* ════════════════════════════════════════
   MESSENGER
════════════════════════════════════════ */
#screen-messenger {
    height: 100dvh;

    display: flex;
    flex-direction: column;

    background:
            linear-gradient(135deg, #0d0d14 0%, #11111b 100%);
}

/* TOPBAR */
.topbar {
    height: 68px;

    padding: 0 22px;

    display: flex;
    align-items: center;
    gap: 14px;

    border-bottom: 1px solid rgba(255,255,255,.05);

    background:
            rgba(15,15,22,.72);

    backdrop-filter: blur(18px);

    flex-shrink: 0;
}

.topbar-brand {
    flex: 1;

    font-family: var(--font-head);

    font-size: 1.3rem;

    letter-spacing: -.03em;
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 38px;
    height: 38px;

    border-radius: 14px;

    background:
            linear-gradient(
                    135deg,
                    #7c74ff,
                    #5a54ff
            );

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: .82rem;
    font-weight: 700;

    color: white;

    box-shadow:
            0 6px 18px rgba(108,99,255,.35);
}

.user-name {
    font-size: .92rem;
    font-weight: 500;
}

.btn-logout {
    height: 38px;

    padding: 0 14px;

    border-radius: 12px;

    background: rgba(255,255,255,.04);

    color: var(--text-muted);

    transition:
            background .2s ease,
            color .2s ease;
}

.btn-logout:hover {
    background: rgba(255,255,255,.08);

    color: #ff7d7d;
}

/* BODY */
.messenger-body {
    flex: 1;

    display: flex;

    overflow: hidden;
}

/* SIDEBAR */
.sidebar {
    width: 310px;

    background:
            rgba(18,18,28,.72);

    border-right: 1px solid rgba(255,255,255,.05);

    backdrop-filter: blur(18px);

    display: flex;
    flex-direction: column;

    overflow: hidden;
}

.search-wrap {
    padding: 18px;
}

.search-input {
    width: 100%;

    height: 48px;

    padding: 0 16px;

    border-radius: 14px;

    background: rgba(255,255,255,.04);

    color: white;

    border: 1px solid rgba(255,255,255,.06);
}

.sidebar-section-label {
    padding: 0 18px 10px;

    font-size: .75rem;
    font-weight: 600;

    letter-spacing: .08em;
    text-transform: uppercase;

    color: var(--text-muted);
}

.chat-list {
    flex: 1;

    overflow-y: auto;

    padding: 0 10px 16px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;

    padding: 12px;

    border-radius: 18px;

    transition:
            background .18s ease,
            transform .18s ease;
}

.chat-item:hover {
    background: rgba(255,255,255,.04);

    transform: translateY(-1px);
}

.chat-item.active {
    background:
            linear-gradient(
                    135deg,
                    rgba(108,99,255,.22),
                    rgba(108,99,255,.12)
            );
}

/* CHAT AREA */
.chat-area {
    flex: 1;

    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;

    text-align: center;

    color: var(--text-muted);
}

.chat-area h3 {
    margin-top: 14px;

    font-size: 1.4rem;

    color: white;
}

/* ────────────────────────────────────────
   MOBILE
──────────────────────────────────────── */
@media (max-width: 700px) {

    .login-card,
    .nick-card {
        padding: 34px 24px;
    }

    .sidebar {
        width: 100%;
    }

    .chat-area {
        display: none;
    }

    .messenger-body {
        flex-direction: column;
    }
}

/* ────────────────────────────────────────
   ANIMATIONS
──────────────────────────────────────── */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(18px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}