/* ============================================================== *
 *  VK Мессенджер v2 — стили                                        *
 *  Палитра ориентирована на Telegram (тёмная + светлая темы),      *
 *  динамически подстраивается под tg.themeParams через CSS vars.   *
 * ============================================================== */

:root {
    --bg: #0e1621;
    --bg-elev: #17212b;
    --bg-elev-2: #1f2c39;
    --bg-hover: #202b38;
    --bg-active: #2b5278;
    --bg-bubble-in: #182533;
    --bg-bubble-out: #2b5278;
    --text: #e6edf2;
    --text-muted: #708499;
    --text-faint: #4a5e74;
    --accent: #4a8cd4;
    --accent-strong: #5aa0eb;
    --danger: #ed5e5e;
    --warn: #f0b045;
    --success: #4caf50;
    --border: rgba(255, 255, 255, 0.06);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    --radius: 14px;
    --radius-sm: 10px;
    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --sb-w: 320px;
}

body.theme-light {
    --bg: #f4f7fb;
    --bg-elev: #ffffff;
    --bg-elev-2: #fafbfd;
    --bg-hover: #eef3f8;
    --bg-active: #d5e6f7;
    --bg-bubble-in: #ffffff;
    --bg-bubble-out: #d8eafc;
    --text: #18222c;
    --text-muted: #6f7d8d;
    --text-faint: #98a4b3;
    --accent: #2680e6;
    --accent-strong: #196ec9;
    --border: rgba(20, 30, 45, 0.07);
    --shadow: 0 8px 30px rgba(60, 90, 130, 0.12);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text",
        "Helvetica Neue", "Segoe UI", Roboto, "Inter", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
}

button {
    font-family: inherit;
    color: inherit;
}

input, textarea {
    font-family: inherit;
}

::selection { background: rgba(74, 140, 212, 0.35); }

/* ---------------- Layout ---------------- */

.app {
    display: grid;
    grid-template-columns: var(--sb-w) 1fr;
    height: 100dvh;
    width: 100vw;
    min-height: 0;
}

.sidebar {
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.chat {
    background: var(--bg);
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

/* ---------------- Sidebar header ---------------- */

.sidebar-header {
    height: 56px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 4;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #4d8ad2, #3470b5);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 4px 14px rgba(74, 140, 212, 0.35);
    flex-shrink: 0;
    position: relative;
    overflow: visible;
}

.brand-logo-fallback {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #fff;
}

.brand-logo-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    display: block;
}

/* ---------------- Theme toggle (тумблер) ---------------- */

.theme-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.theme-switch-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

.theme-switch-track {
    position: relative;
    width: 46px;
    height: 24px;
    border-radius: 999px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 5px;
    transition: background 180ms var(--ease), border-color 180ms var(--ease);
}

.theme-switch-icon {
    position: relative;
    z-index: 1;
    color: var(--text-muted);
    transition: color 180ms var(--ease), opacity 180ms var(--ease);
}

.theme-switch-sun  { color: var(--warn); }
.theme-switch-moon { color: var(--accent-strong); }

.theme-switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    transition: transform 220ms var(--ease), background 180ms var(--ease);
    z-index: 2;
}

body.theme-light .theme-switch-thumb { background: #fff; }
body.theme-dark  .theme-switch-thumb { background: #2a3a4d; }

.theme-switch-input:checked ~ .theme-switch-track .theme-switch-thumb {
    transform: translateX(22px);
}

.theme-switch:hover .theme-switch-track {
    background: var(--bg-hover);
}

.theme-switch-input:focus-visible ~ .theme-switch-track {
    box-shadow: 0 0 0 3px rgba(74, 140, 212, 0.35);
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-title {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.15;
}

.brand-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 120ms var(--ease), color 120ms var(--ease),
                transform 100ms var(--ease);
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.ghost:hover { background: var(--bg-hover); }
.icon-btn.is-spinning svg { animation: spin 0.9s linear infinite; }

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

/* ---------------- Search ---------------- */

.search-bar {
    position: relative;
    margin: 8px 12px;
    display: flex;
    align-items: center;
    background: var(--bg-elev-2);
    border-radius: 12px;
    padding: 0 10px 0 36px;
    height: 38px;
    transition: background 160ms var(--ease);
}

.search-bar:focus-within {
    background: var(--bg-hover);
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    display: grid;
    place-items: center;
    pointer-events: none;
}

.search-icon svg {
    display: block;
    overflow: visible;
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    outline: none;
    font-size: 14px;
    height: 100%;
}

.search-input::placeholder { color: var(--text-faint); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-clear {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    margin-left: 4px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--bg-hover);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 140ms var(--ease), color 140ms var(--ease);
}

.search-clear[hidden] { display: none; }

.search-clear:hover {
    background: var(--bg-elev-2);
    color: var(--text);
}

.search-clear svg { display: block; }

/* ---------------- Filter chips ---------------- */

.filter-tabs {
    display: flex;
    gap: 6px;
    padding: 4px 12px 10px;
    overflow-x: auto;
    scrollbar-width: none;
}

.filter-tabs::-webkit-scrollbar { display: none; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--bg-elev-2);
    color: var(--text-muted);
    border: none;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 140ms var(--ease), color 140ms var(--ease),
                transform 140ms var(--ease);
}

.chip:hover { background: var(--bg-hover); color: var(--text); }
.chip:active { transform: scale(0.97); }
.chip.is-active {
    background: var(--accent);
    color: #fff;
}

.chip-count {
    background: rgba(255, 255, 255, 0.18);
    color: inherit;
    padding: 0 6px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 16px;
    min-width: 18px;
    text-align: center;
}

.chip.is-active .chip-count { background: rgba(255, 255, 255, 0.25); }

/* ---------------- Dialog list ---------------- */

.dialog-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-bottom: 12px;
    overscroll-behavior: contain;
    scroll-padding-top: 4px;
}

.dialog-item {
    --avatar: 50px;
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    align-items: center;
    position: relative;
    border-radius: 12px;
    margin: 1px 6px;
    transition: background 120ms var(--ease);
    contain: layout style;
}

.dialog-item:hover { background: var(--bg-hover); }
.dialog-item.is-active { background: var(--bg-active); }
.dialog-item.is-active .dialog-name,
.dialog-item.is-active .dialog-preview { color: #fff; }
.dialog-item.is-active .dialog-time { color: rgba(255, 255, 255, 0.7); }

body.theme-light .dialog-item.is-active .dialog-name,
body.theme-light .dialog-item.is-active .dialog-preview { color: var(--text); }
body.theme-light .dialog-item.is-active .dialog-time { color: var(--text-muted); }

.dialog-avatar-wrap {
    position: relative;
    width: var(--avatar);
    height: var(--avatar);
    flex-shrink: 0;
}

.dialog-avatar {
    width: var(--avatar);
    height: var(--avatar);
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-elev-2);
    display: block;
    aspect-ratio: 1 / 1;
}

.dialog-avatar.is-loading {
    background: linear-gradient(120deg, var(--bg-elev-2), var(--bg-hover), var(--bg-elev-2));
    background-size: 250% 100%;
    animation: shimmer 1.2s linear infinite;
}

.dialog-status-dot {
    position: absolute;
    right: 0;
    top: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-elev);
    background: var(--success);
}

.dialog-item.is-active .dialog-status-dot { border-color: var(--bg-active); }
.dialog-status-dot.is-unread { background: var(--danger); }
.dialog-status-dot.is-unanswered { background: var(--warn); }

.dialog-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.dialog-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dialog-name {
    font-weight: 600;
    font-size: 14.5px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.dialog-time {
    font-size: 11.5px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.dialog-preview-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dialog-preview {
    font-size: 13.5px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.dialog-preview.is-out::before {
    content: "Вы: ";
    color: var(--accent-strong);
}

.dialog-item.is-active .dialog-preview.is-out::before { color: #fff; }
body.theme-light .dialog-item.is-active .dialog-preview.is-out::before { color: var(--accent-strong); }

.dialog-badge {
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    padding: 0 7px;
    line-height: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.dialog-badge.is-unread { background: var(--danger); }

/* Без ответа: тот же размер, что и красный badge непрочитанных. */
.dialog-badge.is-unanswered {
    background: var(--warn);
    height: 18px;
    min-width: 18px;
    padding: 0;
    border-radius: 999px;
    align-self: center;
}

.dialog-item.has-unread .dialog-name { color: var(--text); }

/* пустые состояния списка */
.list-empty {
    padding: 30px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.list-error {
    margin: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    background: rgba(237, 94, 94, 0.12);
    color: var(--danger);
    font-size: 13px;
}

.load-more {
    padding: 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

/* ---------------- Skeleton ---------------- */

.skeleton-list { padding: 4px 0; }
.dialog-skeleton {
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    margin: 1px 6px;
    align-items: center;
}
.sk-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--bg-elev-2);
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
}
.sk-avatar::after,
.sk-line::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg,
        transparent 0%,
        rgba(255, 255, 255, 0.04) 30%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.04) 70%,
        transparent 100%);
    transform: translateX(-100%);
    animation: shimmer-bar 1.4s linear infinite;
}
.sk-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sk-line {
    height: 12px;
    width: 80%;
    background: var(--bg-elev-2);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}
.sk-line.short { width: 50%; height: 11px; }

@keyframes shimmer-bar {
    100% { transform: translateX(100%); }
}
@keyframes shimmer {
    100% { background-position: -250% 0; }
}

/* ---------------- Chat header ---------------- */

.chat-header {
    height: 56px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
    z-index: 3;
}

.back-btn { display: none; }

.chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-elev-2);
    display: none;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
}

.chat-title-block {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ---------------- Messages ---------------- */

.messages-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px 14px 12px;
    /* Без scroll-behavior: smooth — иначе при повторном render-е (cache → API)
     * чат заметно «дёргается» при попытке снова прокрутить вниз. */
    background: var(--bg);
    background-image:
        radial-gradient(circle at 10% 10%, rgba(74, 140, 212, 0.06), transparent 40%),
        radial-gradient(circle at 90% 90%, rgba(74, 140, 212, 0.04), transparent 35%);
}

.messages-scroll::-webkit-scrollbar,
.dialog-list::-webkit-scrollbar { width: 6px; }
.messages-scroll::-webkit-scrollbar-thumb,
.dialog-list::-webkit-scrollbar-thumb {
    background: rgba(120, 140, 165, 0.25);
    border-radius: 6px;
}
.messages-scroll::-webkit-scrollbar-thumb:hover,
.dialog-list::-webkit-scrollbar-thumb:hover {
    background: rgba(120, 140, 165, 0.45);
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 100%;
}

.day-divider {
    align-self: center;
    margin: 14px 0 8px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.25);
    color: rgba(255, 255, 255, 0.75);
    font-size: 11.5px;
    font-weight: 500;
    backdrop-filter: blur(6px);
}

body.theme-light .day-divider {
    background: rgba(60, 90, 130, 0.12);
    color: var(--text-muted);
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    animation: bubble-in 220ms var(--ease) both;
    contain: layout style;
}

/* Подавляем анимацию появления для повторного рендера того же диалога
 * (cache → API): уже отрисованные сообщения не должны «подпрыгивать». */
.message.no-anim { animation: none !important; }

.message.out { align-items: flex-end; }
.message.in { align-items: flex-start; }

.message + .message.same-author {
    margin-top: -2px;
}

.bubble {
    max-width: min(72%, 560px);
    padding: 8px 12px;
    border-radius: 16px;
    background: var(--bg-bubble-in);
    color: var(--text);
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.4;
    font-size: 14.5px;
    position: relative;
    transition: background 120ms var(--ease);
}

.message.out .bubble {
    background: var(--bg-bubble-out);
    color: #fff;
}

body.theme-light .message.out .bubble { color: var(--text); }
body.theme-light .message.out .message-meta { color: var(--text-muted); }

/* Облачки больше не имеют «хвостика» — все углы равно скруглены, а
 * подсветка непрочитаных идёт чистым кольцом вокруг прямоугольника. */
.bubble.unread {
    background: var(--bg-bubble-in);
    box-shadow: 0 0 0 1.5px var(--warn);
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--accent-strong);
}

.message-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-text a {
    color: var(--accent-strong);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}

.message-text a:hover { filter: brightness(1.1); }
.message.out .message-text a { color: #cfe6ff; }
body.theme-light .message.out .message-text a { color: var(--accent-strong); }

.message-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-faint);
}

.message.out .message-meta { color: rgba(255, 255, 255, 0.75); }

/* ---------------- Attachments ---------------- */

.attachments {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
}

.attachments:last-child { margin-bottom: 0; }

/* Альбом + текст: фото edge-to-edge сверху, текст с паддингами снизу. */
.bubble.bubble-has-album {
    padding: 0 0 8px;
    overflow: hidden;
}

.bubble.bubble-has-album .message-sender {
    padding: 8px 12px 0;
}

.bubble.bubble-has-album .message-text {
    padding: 8px 12px 0;
}

.bubble.bubble-has-album .message-meta {
    padding: 4px 12px 0;
    margin-top: 2px;
}

.bubble.bubble-has-album .attachments { margin: 0; }

.bubble.bubble-has-album .attachment-sticker {
    margin: 0 12px 4px;
}

/* Только фото — edge-to-edge, время оверлеем. */
.bubble.bubble-media-only {
    padding: 0;
    background: transparent;
    box-shadow: none;
    position: relative;
}

.bubble.bubble-media-only .attachments { margin: 0; }
.bubble.bubble-media-only .message-meta {
    position: absolute;
    right: 8px;
    bottom: 6px;
    padding: 2px 7px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff !important;
    backdrop-filter: blur(4px);
    z-index: 2;
    pointer-events: none;
    margin-top: 0;
}

/* ---------------- Photo album (Telegram-style grid) ---------------- */

.photo-album {
    display: grid;
    gap: 2px;
    overflow: hidden;
    max-width: 100%;
    background: var(--bg-elev-2);
}

.photo-album--1 {
    display: block;
    border-radius: 14px;
    background: transparent;
}

.photo-album--1 .photo-album-cell {
    width: 100%;
    height: 100%;
    border-radius: 14px;
}

.photo-album--1 .photo-album-image {
    object-fit: contain;
}

.photo-album-cell {
    position: relative;
    display: block;
    padding: 0;
    margin: 0;
    border: none;
    background: var(--bg-elev-2);
    overflow: hidden;
    cursor: zoom-in;
    min-width: 0;
    min-height: 0;
}

.photo-album-cell:hover { filter: brightness(1.04); }

.photo-album-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    opacity: 0;
    transition: opacity 220ms var(--ease);
}

.photo-album-cell.is-ready .photo-album-image { opacity: 1; }

.photo-album-cell.is-failed {
    background: rgba(237, 94, 94, 0.12);
}

.photo-album-cell::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg,
        var(--bg-elev-2) 0%,
        var(--bg-hover) 50%,
        var(--bg-elev-2) 100%);
    background-size: 250% 100%;
    animation: shimmer 1.2s linear infinite;
    opacity: 1;
    transition: opacity 220ms var(--ease);
    pointer-events: none;
    z-index: 0;
}

.photo-album-cell.is-ready::before { opacity: 0; }

.photo-album-overflow {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 22px;
    font-weight: 600;
    z-index: 1;
    pointer-events: none;
}

/* Фото в чате (legacy одиночное). */
.attachment-photo {
    position: relative;
    display: block;
    padding: 0;
    margin: 0;
    border: none;
    background: var(--bg-elev-2);
    border-radius: 14px;
    overflow: hidden;
    cursor: zoom-in;
    max-width: 100%;
    contain: layout paint;
    transition: transform 120ms var(--ease), filter 120ms var(--ease);
}

.attachment-photo:hover { filter: brightness(1.04); }
.attachment-photo:active { transform: scale(0.98); }

.attachment-photo .attachment-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;       /* aspect-ratio контейнера уже совпадает с фото */
    opacity: 0;
    transition: opacity 240ms var(--ease);
}

.attachment-photo.is-ready .attachment-image { opacity: 1; }
.attachment-photo.is-failed { background: rgba(237, 94, 94, 0.15); }
.attachment-photo.is-failed::after {
    content: "Не удалось загрузить";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--danger);
    font-size: 12px;
}

.attachment-photo::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg,
        var(--bg-elev-2) 0%,
        var(--bg-hover) 50%,
        var(--bg-elev-2) 100%);
    background-size: 250% 100%;
    animation: shimmer 1.2s linear infinite;
    opacity: 1;
    transition: opacity 240ms var(--ease);
    pointer-events: none;
}

.attachment-photo.is-ready::before { opacity: 0; }

/* Стикеры: всегда квадрат, прозрачный фон, текст-заглушка если что-то пошло не так.
 * Сидят в обычном облачке — поэтому само облачко получает чуть больший
 * радиус под квадратную картинку. */
.attachment-sticker {
    position: relative;
    display: block;
    width: min(170px, 50vw);
    aspect-ratio: 1 / 1;
    background: transparent;
    border-radius: 0;
}

/* В облачке стикер не должен иметь крупный нижний отступ — время уйдёт
 * под ним и так. */
.bubble:has(.attachment-sticker) .attachments {
    margin-bottom: 2px;
}

.attachment-sticker .attachment-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    opacity: 0;
    transition: opacity 220ms var(--ease);
}

.attachment-sticker.is-ready .attachment-image { opacity: 1; }

/* В тёмной теме стикеры (PNG с прозрачностью) теряются на тёмном фоне
 * облачка — добавляем белую обводку той же толщины, что у непрочитанных
 * сообщений (1.5px). drop-shadow повторяем, чтобы контур был ровным. */
body.theme-dark .attachment-sticker.is-ready .attachment-image.is-loaded {
    filter:
        drop-shadow(0 0 0.6px rgba(255, 255, 255, 0.95))
        drop-shadow(0 0 0.6px rgba(255, 255, 255, 0.95))
        drop-shadow(0 0 0.6px rgba(255, 255, 255, 0.95))
        drop-shadow(0 0 0.6px rgba(255, 255, 255, 0.95));
}

.attachment-sticker.is-failed {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    display: grid;
    place-items: center;
}
.attachment-sticker-fallback {
    font-size: 56px;
    line-height: 1;
    opacity: 0.6;
}

/* ---------------- Empty / footer / toast ---------------- */

.messages-empty {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px;
    gap: 8px;
    height: 100%;
}

.empty-illustration { margin-bottom: 6px; opacity: 0.85; }
.empty-title { font-size: 17px; font-weight: 600; }
.empty-subtitle { color: var(--text-muted); max-width: 340px; font-size: 13.5px; }

.chat-toast {
    position: absolute;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%) translateY(20px);
    padding: 9px 14px;
    border-radius: 999px;
    background: rgba(20, 30, 45, 0.9);
    color: #fff;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms var(--ease), transform 180ms var(--ease);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
    z-index: 10;
    backdrop-filter: blur(6px);
}

.chat-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------------- Auth error ---------------- */

.auth-error {
    position: fixed;
    inset: 0;
    background: var(--bg);
    color: var(--text);
    display: grid;
    place-items: center;
    padding: 24px;
    z-index: 99;
}

.auth-error-card {
    max-width: 340px;
    text-align: center;
    background: var(--bg-elev);
    padding: 28px 26px;
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.auth-error-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: rgba(237, 94, 94, 0.12);
    color: var(--danger);
    display: grid;
    place-items: center;
    margin: 0 auto 14px;
}

.auth-error h1 {
    font-size: 18px;
    margin: 0 0 8px;
}
.auth-error p {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0;
    line-height: 1.5;
}

/* ---------------- Animations ---------------- */

@keyframes bubble-in {
    0% { opacity: 0; transform: translateY(8px) scale(0.96); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in { animation: fade-in 200ms var(--ease) both; }

/* ---------------- Responsive ---------------- */

@media (max-width: 820px) {
    .app {
        grid-template-columns: 100vw 100vw;
        width: 200vw;
        transform: translateX(0);
        transition: transform 280ms var(--ease);
        will-change: transform;
    }

    .app.show-chat { transform: translateX(-100vw); }

    .sidebar { width: 100vw; min-width: 100vw; max-width: 100vw; }
    .chat    { width: 100vw; min-width: 100vw; max-width: 100vw; }

    .back-btn { display: grid; }
    .chat-avatar { display: block; }

    .bubble { max-width: 82%; font-size: 15px; }

    .attachment-sticker { width: min(50vw, 220px); }

    .dialog-item { margin: 1px 4px; }
}

/* ---------------- Lightbox (просмотр фото) ---------------- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 200ms var(--ease), background 200ms var(--ease);
    overscroll-behavior: contain;
    touch-action: none;
}

.lightbox.is-visible {
    opacity: 1;
    background: rgba(0, 0, 0, 0.92);
}

.lightbox[hidden] { display: none; }

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    cursor: zoom-out;
}

.lightbox-stage {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 56px 24px;
    cursor: zoom-out;
    z-index: 1;
}

.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 220ms var(--ease), transform 220ms var(--ease);
    border-radius: 4px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
    user-select: none;
    pointer-events: auto;
    cursor: default;
}

.lightbox-image.is-loaded {
    opacity: 1;
    transform: scale(1);
}

.lightbox-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.18);
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    pointer-events: none;
    z-index: 2;
}

.lightbox-close,
.lightbox-open-external {
    position: absolute;
    top: env(safe-area-inset-top, 12px);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border: none;
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 3;
    backdrop-filter: blur(6px);
    transition: background 140ms var(--ease), transform 100ms var(--ease);
    text-decoration: none;
}

.lightbox-close { right: 14px; }
.lightbox-open-external { right: 64px; }

.lightbox-close:hover,
.lightbox-open-external:hover {
    background: rgba(255, 255, 255, 0.18);
}
.lightbox-close:active,
.lightbox-open-external:active { transform: scale(0.94); }

body.lightbox-open {
    overflow: hidden;
}

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