﻿    :root {
    --font: system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
    --bg-page: #fff;
    --text-main: #22263a;
    --text-muted: #7a8199;
    --accent-1: #cfeff1;
    --accent-1-strong: #9ed9de;
    --accent-2: #fadce6;
    --accent-2-strong: #f7c2d4;
    --card-bg: #fff;
    --card-border: #e8ecf2;
    --btn-primary: var(--accent-1-strong);
    --btn-primary-hover: var(--accent-1);
    --input-bg: #fff;
    --input-fg: #22263a;
    --input-border: #d7dde8;
    --focus-ring: 0 0 0 3px rgba(158,217,222,.35);
    --msg-in-bg: #fff;
    --msg-in-border: #eaeef6;
    --msg-out-bg: #e9f7f8;
    --msg-out-border: #cdebee;
    --shadow-sm: 0 2px 8px rgba(0,0,0,.05);
    --pane-bg: var(--card-bg);
    --pane-bg-weak: #f7fbfc;
    --border-soft: var(--card-border);
    --brand-dark: #17242a;
    --avatar-size: 40px;
    --avatar-size-lg: 48px;
    --avatar-size-xl: 96px;
    --avatar-bg: var(--accent-2-strong);
    --avatar-fg: #3b2a30;
    --hover-bg: rgba(34,38,58,0.06);
    --scroll-thumb: rgba(34,38,58,0.18);
    --scroll-track: rgba(34,38,58,0.06);
    --menu-item-bg: rgba(0,0,0,.04);
    --menu-item-hover: rgba(0,0,0,.07);
    --notice-overlay-bg: rgba(255,255,255,.72);
    --notice-card-bg: rgba(255,255,255,.80);
    --notice-card-border: rgba(0,0,0,.08);
    --spoiler-bg: rgba(0,0,0,.10);
    --spoiler-bd: rgba(0,0,0,.14);
    --vvh: 100vh;
    --vvw: 100vw;
    --vv-top: 0px;
    --vv-left: 0px;
    --topbar-bg: #ffffff;
    --topbar-fg: var(--text-main);
    --btn-danger: #ef4444;
    --btn-danger-hover: #f87171;
    --file-chip-bg: #f8fbff;
    --file-chip-border: #dbe5f1;
    --file-chip-fg: var(--text-main);
    --file-chip-meta: var(--text-muted);
    --file-chip-hover-bg: rgba(34,38,58,0.05);
    --stroke: var(--card-border);
    --accent: var(--btn-primary);
    --text-subtle: var(--text-muted);
}

:root[data-theme="dark"] {
    --bg-page: #0b0f14;
    --pane-bg: #0f172a;
    --pane-bg-weak: #0b1220;
    --card-bg: #0f172a;
    --card-border: #1f2a44;
    --text-main: #e6edf3;
    --text-muted: #94a3b8;
    --text-invert: #0b0f14;
    /* базовые акценты (больше никаких кислотных розовых) */
    --accent-1: #243244;
    --accent-1-strong: #2d3b52;
    --accent-2: #0b1220;
    --accent-2-strong: #111827;
    /* сообщения */
    --msg-in-bg: #0f172a;
    --msg-in-border: #1e293b;
    --msg-out-bg: #0b2a33;
    --msg-out-border: #134e4a;
    /* кнопки */
    --btn-primary: #38bdf8;
    --btn-primary-hover: #0ea5e9;
    --btn-danger: #ef4444;
    --btn-danger-hover: #f87171;
    /* инпуты */
    --input-bg: #0b1220;
    --input-fg: #e6edf3;
    --input-border: #1f2a44;
    --focus-ring: 0 0 0 3px rgba(56,189,248,0.35);
    --shadow: 0 10px 25px rgba(0,0,0,0.55);
    --shadow-sm: 0 4px 16px rgba(0,0,0,0.55);
    /* hover */
    --hover-bg: rgba(148,163,184,0.08);
    /* topbar */
    --topbar-bg: #0b1220;
    --topbar-fg: var(--text-main);
    /* файлы/вложения — чтобы НЕ сливались */
    --file-chip-bg: #0b1e2d;
    --file-chip-border: #1f3b4d;
    --file-chip-fg: var(--text-main);
    --file-chip-meta: var(--text-muted);
    --file-chip-hover-bg: rgba(56,189,248,0.12);
    /* аватарки */
    --avatar-bg: #1f2a44;
    --avatar-fg: #e6edf3;
    --scroll-thumb: rgba(148,163,184,0.38);
    --scroll-track: rgba(148,163,184,0.10);
    --menu-item-bg: rgba(255,255,255,.06);
    --menu-item-hover: rgba(255,255,255,.10);
    --notice-overlay-bg: rgba(0,0,0,.35);
    --notice-card-bg: rgba(255,255,255,.06);
    --notice-card-border: rgba(255,255,255,.10);
    --spoiler-bg: rgba(255,255,255,.14);
    --spoiler-bd: rgba(255,255,255,.18);
}


/* ===== Базовая раскладка ===== */
html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg-page);
    color: var(--text-main);
    min-height: 100%;
    overscroll-behavior: none;
}

.layout {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    height: var(--vvh, 100vh);
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

/* ===== Шапка в сайдбаре ===== */
.topbar {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--topbar-bg);
    color: var(--topbar-fg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
}

    .topbar .brand {
        font-weight: 800;
        font-size: 18px
    }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px
}

#themeToggle {
    width:36px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid var(--input-border);
    background:var(--card-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
/* маленькая аватарка в топбаре */
.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-2-strong);
    border: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #3b2a30;
    cursor: pointer;
    background: var(--avatar-bg);
    color: var(--avatar-fg);
}

/* ===== Сайдбар ===== */
.sidebar {
    background: var(--card-bg);
    border-right: 1px solid var(--card-border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
}

    .sidebar h3 {
        margin:0;
        padding: 8px 0;
        font-size: 16px;
        font-weight: 700;
        border-top: 1px solid var(--card-border);
    }

/* 4 быстрых кнопки */
.quick-actions {
    display: block;
    margin: 2px 0 6px;
}

.qa-create {
    width: 100%;
    min-height: 44px;
    border-radius: 14px;
    padding: 0 14px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
}

.qa-btn {
    width:48px;
    height: 48px;
    border-radius: 999px;
    background: var(--accent-2);
    border:1px solid var(--accent-2-strong);
    color: #3b2a30;
    font-weight: 700;
    cursor: pointer;
    transition: .2s;
}

    .qa-btn:hover {
        filter: brightness(1.03)
    }

/* Поиск + действия */
.actions {
    display: flex;
    flex-direction: column;
    gap: 16px
}

.search.row {
    display: flex;
    gap: 8px
}

    .search.row input {
        flex: 1;
        height: 40px
    }

    .search.row button {
        width: 120px;
        height: 40px
    }

.chats-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
}

    .chats-scroll .list {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .chats-scroll .chat-item {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        border: 1px solid var(--card-border);
        background: var(--card-bg);
        cursor: pointer;
        border-radius: 10px;
        min-height: 56px;
        font-size: 0.9em;
        overflow: hidden;
        box-sizing: border-box;
        width: 100%;
    }

    .chat-item:hover {
        background: var(--hover-bg);
    }

.chats-scroll .chat-item .subtext {
    font-size: 0.8em;
    max-width: 100%;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}


.chat-notices.hidden {
    display: none;
}

.chat-notices {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px 8px 12px;
    background: linear-gradient(to bottom, var(--notice-overlay-bg) 0%, rgba(0,0,0,0) 100%);
    backdrop-filter: blur(10px);
}

/* когда внутри chat-notices — убираем марджины из html inline */
#chatNotices #pinnedBanner {
    margin: 0 !important;
}

#chatNotices #readOnlyBanner {
    margin: 0 !important;
}

/* карточки внутри */
#chatNotices #pinnedBanner,
#chatNotices #readOnlyBanner {
    border-radius: 12px;
    border: 1px solid var(--notice-card-border);
    background: var(--notice-card-bg);
}

.pinned {
    margin: 8px 16px 0;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255,255,255,0.06);
    cursor: pointer;
}

.pinned-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.pinned-title {
    font-weight: 600;
}

.pinned-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
}


.flash {
    outline: 2px solid rgba(255,255,255,0.25);
    border-radius: 12px;
}

.reactions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.rx {
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.07);
    border: 0;
    cursor: pointer;
}

    .rx.mine {
        background: rgba(255,255,255,0.14);
    }

.avatar {
    /* квадрат и круг */
    width: var(--avatar-size);
    height: var(--avatar-size);
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    overflow: hidden;
    /* чтобы flex-верстка не тянула/сжимала */
    flex: 0 0 var(--avatar-size);
    min-width: var(--avatar-size);
    /* фон и буква, если нет картинки */
    background: rgba(0,0,0,.06);
    color: #555;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    text-transform: uppercase;
    user-select: none;
}

.avatar-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover; /* не даст сплющить/растянуть */
    border-radius: 50%;
}

.avatar img {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
    display: block;
}

/* размеры в разных местах интерфейса (если нужно крупнее) */
#chatAvatar.avatar,
#profileAvatar.avatar {
    --avatar-size: var(--avatar-size-lg);
}

#profilePanel .avatar,
#profileAvatarImgWrap.avatar {
    --avatar-size: var(--avatar-size-xl);
}

/* В шапке чата иконка чуть больше */
.chat-header .avatar-img {
    width: 40px;
    height: 40px;
}

.chat-title {
    font-weight: 700
}

.chat-last {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

    .chat-last * {
        white-space: nowrap;
    }

.unread {
    margin-left:auto;
    background: var(--accent-1);
    border: 1px solid var(--accent-1-strong);
    padding:2px 8px;
    border-radius: 999px;
    font-size: 12px;
}

/* ===== Правая область ===== */
.main {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: radial-gradient(1200px 600px at -10% -10%, var(--accent-1) 0%, transparent 50%) no-repeat, radial-gradient(1200px 600px at 110% 120%, var(--accent-2) 0%, transparent 50%) no-repeat, var(--bg-page);
}

.chat-header {
    padding:12px 16px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
}

    .chat-header .chat-title {
        font-size: 16px
    }

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

.messages {
    flex: 1;
    padding: 18px;
    padding-top: 0;
    padding-bottom: calc(18px + var(--keyboard-inset, 0px));
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: auto;
    background: transparent;
    min-height: 0;
}

.msg-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
}

.msg {
    overflow: hidden;
}

.msg .atts {
    min-width: 0;
}

    .msg .atts > * {
        min-width: 0;
    }

.msg .att-img {
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 220px;
    object-fit: cover;
}

.msg .atts audio {
    width: 100%;
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
}

.msg .atts video:not(.att-video):not(.att-video--note) {
    width: 100%;
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
}


.msg {
    background:var(--msg-in-bg);
    border: 1px solid var(--msg-in-border);
    border-radius: 14px;
    padding: 8px 12px;
    max-width:72%;
    box-shadow: var(--shadow-sm);
}

    .msg.mine {
        align-self: flex-end;
        background: var(--msg-out-bg);
        border-color: var(--msg-out-border)
    }

.msg-reply {
    margin: 6px 0 8px;
    padding: 6px 10px;
    border-left: 3px solid rgba(255,255,255,0.25);
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    cursor: pointer;
    user-select: none;
}

    .msg-reply .r-from {
        font-size: 12px;
        font-weight: 600;
        opacity: 0.9;
    }

    .msg-reply .r-prev {
        font-size: 12px;
        opacity: 0.75;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

.meta-views {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    vertical-align: middle;
}

    .meta-views svg {
        width: 12px;
        height: 12px;
        fill: currentColor;
        opacity: .75;
        display: block;
    }

.meta-views-count,
.meta-time,
.meta-status,
.meta-sender,
.edited {
    color: var(--text-muted);
}

.spoiler {
    position: relative;
    border-radius: 6px;
    padding: 0 6px;
    background: var(--spoiler-bg);
    border: 1px dashed var(--spoiler-bd);
    color: transparent;
    cursor: pointer;
}

    .spoiler:not(.revealed)::after {
        content: "";
        color: var(--text-muted);
    }

    .spoiler.revealed {
        color: inherit;
    }

    .spoiler::selection {
        color: transparent;
    }


.meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px
}

/* предпросмотр выбранных файлов */
.att-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 16px 0
}

.att-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    font-size: 12px;
    background: var(--file-chip-bg);
    border: 1px solid var(--file-chip-border);
    color: var(--file-chip-fg);
    border-radius: 8px;
    box-shadow: var(--shadow-sm)
}

    .att-chip .x {
        cursor: pointer;
        opacity: .7;
        user-select: none
    }

        .att-chip .x:hover {
            background: var(--file-chip-hover-bg);  
            opacity: 1
        }

/* вложения в сообщении */
.msg .atts {
    display: grid;
    grid-template-columns: repeat(auto-fill,minmax(120px,1fr));
    gap: 6px;
    margin-top: 6px
}

.msg .att-img {
    display: block;
    max-width: 220px;
    max-height: 220px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background:var(--card-bg);
    object-fit: cover;
    box-shadow: var(--shadow-sm)
}

.msg .att-file {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid var(--file-chip-border);
    border-radius: 8px;
    background: var(--file-chip-bg);
    font-size: 13px;
    text-decoration: none;
    color: var(--file-chip-fg);
    box-shadow: var(--shadow-sm);
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
}

    .msg .att-file:hover {
        background: var(--file-chip-hover-bg);
        filter: brightness(1.03)
    }

.msg .att-caption {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px
}

#messageInput {
    height: 42px;
    min-height: 42px;
    max-height: calc(1.35em * 10 + 24px);
    resize: none;
    overflow-y: hidden;
    padding: 10px 12px;
    line-height: 1.35;
    box-sizing: border-box;
}

#messageInput {
    height: auto;
    min-height: 42px; 
    max-height: 240px;
    resize: none;
    overflow-y: auto;
}

.menu {
    position: absolute;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 6px
}

    .menu.hidden {
        display: none
    }

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 12px;
    box-shadow: var(--shadow-sm)
}

.muted {
    color: var(--text-muted)
}

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

.col {
    display: flex;
    flex-direction: column;
    gap: 6px
}

.grow {
    flex: 1
}

/* ==== Auth – компактные и ровные поля ==== */
*, *::before, *::after {
    box-sizing: border-box;
}
/* чтобы ширина считалась честно */

.auth-container {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background: var(--bg-page);
}

.auth-box {
    width: 100%;
    max-width: 360px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden; /* <— не даём контенту вылезать за скругления */
    display: grid;
    gap: 12px;
}

    .auth-box .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .auth-box .logo {
        font-weight: 900;
        font-size: 20px;
        padding: 6px 10px;
        background: var(--accent-2);
        border-radius: 10px;
    }

#themeToggle {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid var(--input-border);
    background: var(--card-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.auth-box input {
    display: block;
    width: 100%;
    height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--input-fg);
    margin: 4px 0; /* небольшой внутренний «воздух» */
    -webkit-appearance: none;
    appearance: none;
}

    .auth-box input:focus {
        outline: none;
        box-shadow: var(--focus-ring);
    }

.auth-box .row {
    display: flex;
    gap: 10px;
}

.auth-box button {
    flex: 1;
    height: 42px;
    border-radius: 12px;
    border: 1px solid var(--input-border);
    background: var(--btn-primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

    .auth-box button:hover {
        background: var(--btn-primary-hover);
    }

/* iOS: предотвратить авто-зум при фокусе */
@supports (-webkit-touch-callout: none) {
    .auth-box input {
        font-size: 16px;
    }
}

/* helper — прячет элемент гарантированно */
.hidden {
    display: none !important;
}

/* ===== PROFILE SHEET (overlay) ===== */
.profile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

    .profile-overlay.hidden {
        display: none !important;
    }

.profile-card {
    width: min(860px, 96vw);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    position: relative;
}

.profile-cover {
    position: relative;
    height: 180px;
    background: radial-gradient(600px 300px at -10% -20%, var(--accent-1) 0%, transparent 55%) no-repeat, radial-gradient(600px 300px at 110% 120%, var(--accent-2) 0%, transparent 55%) no-repeat, var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
}

.p-back {
    position: absolute;
    top: 10px;
    left: 10px;
    border-radius: 10px;
    padding: 6px 10px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    /*cursor:pointer;*/
}

.avatar-wrap {
    margin-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.p-avatar {
    width: 110px;
    height: 110px;
    border-radius: 999px;
    object-fit: cover;
    border: 1px solid var(--card-border);
    background: var(--accent-1);
}

.p-ghost.small {
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid var(--input-border);
    background: var(--accent-1);
}

.p-reactions {
    position: absolute;
    right: 14px;
    top: 14px;
    display: flex;
    gap: 8px;
}

.p-reaction {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    font-weight: 600;
    cursor: pointer;
}

    .p-reaction.active {
        outline: 2px solid rgba(0,0,0,.06);
    }

    .p-reaction .cnt {
        font-size: 12px;
        color: var(--text-muted);
    }

.profile-body {
    padding: 14px 16px 16px;
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 16px;
}

@media (max-width: 720px) {
    .profile-body {
        grid-template-columns: 1fr;
    }
}

/* единый "вторичный" стиль кнопок */
.secondary {
    border: 1px solid var(--input-border);
    background: var(--pane-bg);
    color: var(--text-main);
    border-radius: 12px;
    padding: 8px 14px;
    font-weight: 700;
    cursor: pointer;
}

    .secondary:hover {
        background: var(--hover-bg);
    }

/* поиск и поле сообщения — чтобы не были белыми в dark */
#universalSearchQuery,
#messageInput {
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--input-fg);
}

    #universalSearchQuery::placeholder,
    #messageInput::placeholder {
        color: var(--text-muted);
    }

    #universalSearchQuery:focus,
    #messageInput:focus {
        outline: none;
        box-shadow: var(--focus-ring);
    }

/* кнопка отправки — компактная, “иконка-кнопка” */
#btnSend.primary.send {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* чтобы кнопки/иконки в панелях не уходили в "тёмный текст" */
.p-ghost, .p-ghost.small, #btnAttach {
    color: var(--text-main);
}


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

/* имя не должно выдавливать кнопки */
.p-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* блок с ⋯ прижимаем к правому краю строки */
.name-row .p-more {
    margin-left: auto;
}

.p-more {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative; /* ВАЖНО: якорь для меню */
}

.p-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 10px);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 6px;
    width: 168px; /* уже */
    max-width: min(200px, calc(100vw - 28px));
    box-shadow: var(--shadow-sm);
    z-index: 50;
}

    .p-menu::after {
        content: "";
        position: absolute;
        right: 16px;
        bottom: -6px;
        width: 10px;
        height: 10px;
        background: var(--card-bg);
        border-right: 1px solid var(--card-border);
        border-bottom: 1px solid var(--card-border);
        transform: rotate(45deg);
    }

    .p-menu button {
        width: 100%;
        text-align: left;
        border: 0;
        background: transparent;
        color: var(--text-main);
        padding: 12px 12px; /* выше */
        border-radius: 12px;
        cursor: pointer;
        font-weight: 700;
        font-size: 14px;
        line-height: 1.15;
        /* КЛЮЧЕВОЕ: разрешаем перенос, чтобы меню было уже, но выше */
        white-space: normal;
        word-break: break-word;
    }

        .p-menu button:hover {
            background: var(--hover-bg);
        }

        .p-menu button.danger {
            color: var(--btn-danger, #ef4444);
        }

    .p-menu.hidden {
        display: none;
    }


.username-row {
    margin-top: 6px;
    margin-bottom: 8px;
    font-size: 14px;
}

.p-emoji-editor {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 6px;
    box-shadow: var(--shadow-sm);
}

    .p-emoji-editor input {
        width: 56px;
        text-align: center;
        font-size: 20px;
        border-radius: 8px;
        border: 1px solid var(--input-border);
        padding: 6px 8px;
    }

.emoji-pop {
    position: fixed;
    z-index: 3000;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    padding: 6px;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
}

    .emoji-pop .e {
        font-size: 18px;
        padding: 6px;
        border: none;
        background: transparent;
        cursor: pointer;
        line-height: 1;
    }

        .emoji-pop .e:hover {
            filter: brightness(1.05);
        }

/* ==== CREATE WIZARD (overlay sheet) ==== */
.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 1001;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
}

    .sheet-overlay.hidden {
        display: none !important;
    }

.sheet-card {
    width: min(640px, 94vw);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
}

.sheet-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--card-border);
    background: radial-gradient(400px 200px at -10% -20%, var(--accent-1) 0%, transparent 55%) no-repeat, radial-gradient(400px 200px at 110% 120%, var(--accent-2) 0%, transparent 55%) no-repeat, var(--card-bg);
}

.sheet-body {
    padding: 16px;
    min-height: 220px;
}

.sheet-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid var(--card-border);
    background: var(--card-bg);
}

.wizard-step.hidden {
    display: none;
}

.choice-grid {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 12px;
    margin-top: 8px;
}

@media (max-width:560px) {
    .choice-grid {
        grid-template-columns: 1fr;
    }
}

.choice {
    text-align: left;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid var(--card-border);
    background: var(--pane-bg);
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 10px;
    align-items: center;
    transition: transform .08s ease, filter .12s ease;
}

    .choice:hover {
        filter: brightness(1.02);
    }

    .choice:active {
        transform: scale(.995);
    }

.choice-emoji {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--accent-1);
    font-size: 22px;
}

.choice-title {
    font-weight: 700;
}

.choice-sub {
    font-size: 12px;
}

.cw-input, .cw-textarea {
    width: 100%;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--input-fg);
    border-radius: 12px;
    padding: 12px;
    outline: none;
}

    .cw-input:focus, .cw-textarea:focus {
        box-shadow: var(--focus-ring);
    }

.cw-textarea {
    min-height: 120px;
    resize: vertical;
}

.p-ghost {
    border: 1px solid var(--input-border);
    background: var(--accent-1);
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
}

/* ==== Modern icon buttons (chat / … / ✕) ==== */
.p-icon {
    -webkit-appearance: none;
    appearance: none;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 12px;
    border: 1px solid var(--input-border);
    background: var(--pane-bg);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background .14s ease, transform .08s ease, filter .14s ease;
    line-height: 1;
    font-size: 18px;
}

    .p-icon:hover {
        background: var(--hover-bg);
    }

    .p-icon:active {
        transform: translateY(1px);
    }

    .p-icon:focus-visible {
        outline: none;
        box-shadow: var(--focus-ring);
    }


.primary {
    border: 1px solid var(--input-border);
    background: var(--btn-primary);
    color: #fff;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 700;
    cursor: pointer;
}

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

.spinner {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 3px solid var(--card-border);
    border-top-color: var(--accent-2-strong);
    animation: spin .8s linear infinite;
    margin: 8px 0;
}

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

/* ===== Device helpers ===== */
.only-mobile {
    display: none;
}

/* Глобально: честная высота + отключаем прокрутку body */
html, body {
    height: 100%;
    margin: 0;
    overscroll-behavior: none; /* без резинового прокрута */
    overflow: hidden; /* скроллим только внутренние области */
}

/* Каркас занимает реальную высоту экрана на мобиле */
.layout {
    height: 100svh;
}

/* Когда открыт мобильный ящик — фиксируем body */
.no-scroll {
    overflow: hidden;
}

/* Полям ввода — 16px, чтобы не было авто-зума на фокусе */
@media (max-width: 900px) {
    input, textarea, button, select {
        font-size: 16px;
    }

    #messageInput {
        font-size: 16px;
    }

    #universalSearchQuery {
        font-size: 16px;
    }

    .cw-input, .cw-textarea {
        font-size: 16px;
    }
}

/* ===== Responsive layout: desktop vs mobile ===== */
@media (max-width: 1180px) {
    html, body {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    body {
        position: fixed;
        inset: 0;
    }

    .layout {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        max-width: 100vw;
        grid-template-columns: minmax(0, 1fr);
        overflow: hidden;
    }

    .main {
        width: 100vw;
        max-width: 100vw;
        min-width: 0;
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(88vw, 360px);
        max-width: 360px;
        transform: translateX(-100%);
        transition: transform .22s ease;
        z-index: 50;
        border-right: 1px solid var(--card-border);
    }

    :root.drawer-open .sidebar {
        transform: translateX(0);
    }

    .messages {
        min-width: 0;
        padding-left: 12px;
        padding-right: 12px;
    }

    .msg {
        max-width: min(100%, calc(100vw - 32px));
    }

}

@media (min-width: 1181px) {
    .drawer-backdrop {
        display: none !important;
    }
}

/* ===== Extra: очень большие экраны — чутка шире чат ===== */
@media (min-width: 1400px) {
    .messages {
        padding-left: 24px;
        padding-right: 24px;
    }

    .msg {
        max-width: 68%;
    }
}

@media (min-width: 1181px) {
    body {
        font-size: clamp(14px, 0.18vw + 13px, 17px);
    }

    .layout {
        grid-template-columns: clamp(320px, 24vw, 420px) minmax(0, 1fr);
    }

    .main {
        min-width: 0;
    }

    .messages {
        padding-left: clamp(16px, 2vw, 32px);
        padding-right: clamp(16px, 2vw, 32px);
    }

    .msg {
        max-width: min(820px, calc(100% - 32px));
    }
}

/* ===== Textarea autosize comfort ===== */
#messageInput {
    max-height: 40vh;
    overflow: auto; /* покажем скролл, если совсем длинно */
}

/* более гибкая ширина пикера на телефоне */
@media (max-width: 900px) {
    .emoji-picker {
        max-width: 92vw;
    }
}

/* Панель чата: список участников */
.member-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 0;
    border-bottom: 1px solid var(--card-border);
}

.member-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 240px;
    min-width: 0;
}

    .member-left > div {
        min-width: 0;
    }

.member-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.member-name {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-username {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rt-big {
    font-size: 1.25em;
    font-weight: 700;
    line-height: 1.25;
}

.format-toolbar {
    position: fixed;
    z-index: 80;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    border-radius: 14px;
    background: var(--pane-bg);
    border: 1px solid var(--card-border);
    box-shadow: 0 10px 30px rgba(0,0,0,.18);
    max-width: min(360px, calc(100vw - 16px));
}

    .format-toolbar.hidden {
        display: none;
    }

    .format-toolbar button {
        border: 0;
        border-radius: 10px;
        padding: 6px 10px;
        cursor: pointer;
        background: rgba(0,0,0,.04);
        color: var(--text-main);
    }

        .format-toolbar button:hover {
            background: var(--menu-item-hover);
        }

[data-theme="dark"] .format-toolbar button {
    background: rgba(255,255,255,.06);
}

@media (max-width: 600px) {
    .format-toolbar {
        flex-direction: column;
        width: min(220px, calc(100vw - 16px));
        max-width: calc(100vw - 16px);
    }

        .format-toolbar button {
            width: 100%;
            text-align: left;
            margin: 0;
        }
}


/* room members scroll */
#roomMembers {
    max-height: min(52vh, 420px);
    overflow-y: auto;
    padding-right: 6px;
}

.btn-danger {
    white-space: nowrap;
}


.role-select {
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--input-fg);
    padding: 0 8px;
}

.btn-danger {
    border: 1px solid var(--input-border);
    background: var(--btn-danger, #ff6b6b);
    color: #fff;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    white-space: nowrap;
}

    .btn-danger:hover {
        background: var(--btn-danger-hover, #ff8080);
    }

/* ===== Scrollbars (dark/light) ===== */
* {
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

    *::-webkit-scrollbar {
        width: 10px;
        height: 10px;
    }

    *::-webkit-scrollbar-track {
        background: var(--scroll-track);
        border-radius: 999px;
    }

    *::-webkit-scrollbar-thumb {
        background: var(--scroll-thumb);
        border-radius: 999px;
        border: 2px solid var(--scroll-track);
    }

        *::-webkit-scrollbar-thumb:hover {
            filter: brightness(1.12);
        }

.composer-meta.hidden, .msg-menu.hidden {
    display: none;
}

.composer-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--pane-bg);
    margin: 0 12px 8px 12px;
}

.cm-left {
    flex: 1;
    min-width: 0;
}

.cm-title {
    font-weight: 600;
    font-size: 12px;
    opacity: .9;
}

.cm-text {
    font-size: 12px;
    opacity: .75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cm-close {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    opacity: .8;
}

.msg-menu {
    position: fixed;
    z-index: 9999;
    min-width: 200px;
    padding: 10px;
    border-radius: 14px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    box-shadow: 0 12px 36px rgba(0,0,0,.30);
    backdrop-filter: blur(10px);
    color: var(--text-main);
}

.msg-link {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-word;
}

.mm-reactions, .mm-actions {
    background: transparent;
    border: 0;
    padding: 0;
}

    .mm-reactions button,
    .mm-actions button {
        background: transparent;
        border: 1px solid transparent;
        color: var(--text-main);
    }

        .mm-reactions button:hover,
        .mm-actions button:hover {
            background: var(--hover-bg);
            border-color: var(--card-border);
        }

/* критично: у реакций на сообщениях текст/счётчик не должен быть “чёрным” */
.rx {
    color: var(--text-main);
}

    .rx.mine {
        border-color: rgba(255,255,255,.30);
    }


/* ===== Room panel: fit on mobile (smaller + inner scroll) ===== */
@media (max-width: 900px) {

    /* сам оверлей: даём отступы, чтобы карточка не упиралась в края */
    #roomPanel.profile-overlay {
        padding: 12px;
        align-items: flex-start; /* чтобы карточка "прилипала" к верху и не вылезала вниз */
    }

    /* карточка: ограничиваем высоту экраном */
    #roomPanel .profile-card {
        width: 100%;
        max-height: calc(100svh - 24px); /* главное */
        max-height: calc(100vh - 24px); /* fallback */
        display: flex;
        flex-direction: column;
        overflow: hidden; /* скролл будет внутри body */
    }

    /* шапка (cover) делаем ниже */
    #roomPanel .profile-cover {
        height: 96px; /* было 120px */
        flex: 0 0 auto;
        align-items: center;
    }

    #roomPanel .avatar-wrap {
        margin-left: 12px; /* было 20px */
        flex-direction: row; /* было column */
        align-items: center;
        gap: 12px;
    }

    #roomPanel .p-avatar {
        width: 72px; /* было 110px */
        height: 72px;
    }

    #roomPanel .p-ghost.small {
        height: 36px;
        padding: 0 12px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 12px;
        background: var(--pane-bg);
    }

        #roomPanel .p-ghost.small:hover {
            background: var(--hover-bg);
        }

    /* ВАЖНО: на мобиле убираем вложенный скролл у участников,
       скроллим всю body панели, иначе кажется что "уходит за кнопки" */
    #roomPanel #roomMembers {
        max-height: none; /* переопределяем твой max-height */
        overflow: visible;
        padding-right: 0;
    }

    #roomPanel .profile-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow: auto;
        padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px)) 12px;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* чуть компактнее кнопки/инпуты в панели комнаты */
    #roomPanel .p-ghost,
    #roomPanel .btn-danger,
    #roomPanel .primary {
        padding: 7px 10px;
        border-radius: 10px;
    }

    #roomPanel .cw-input,
    #roomPanel .cw-textarea {
        padding: 10px;
        border-radius: 12px;
    }
}

/* FIX overflow вправо */
.layout {
    grid-template-columns: 360px minmax(0, 1fr);
    overflow-x: hidden;
}

.sidebar, .main {
    min-width: 0;
}

/* FIX узких сообщений */
.msg-row {
    display: flex;
    width: 100%;
    padding: 6px 18px;
    box-sizing: border-box;
}

    .msg-row.mine {
        justify-content: flex-end;
    }

    .msg-row.theirs {
        justify-content: flex-start;
    }

.msg {
    width: fit-content;
    max-width: min(720px, calc(100% - 40px));
    min-width: 0;
    box-sizing: border-box;
    overflow-wrap: anywhere;
}

#messageInput {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    max-height: calc(1.35em * 10 + 24px);
    padding: 10px 12px;
    line-height: 1.35;
    resize: none;
    overflow-y: auto;
    box-sizing: border-box;
    border-radius: 16px !important;
    align-self: stretch;
}

.send-original-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 12px;
    user-select: none;
}

    .send-original-toggle input {
        margin: 0;
    }

@media (max-width: 1180px) {

    #btnAttach {
        grid-area: attach;
    }

    #messageInput {
        grid-area: input;
    }

    #btnSend {
        grid-area: send;
    }

    .send-original-toggle {
        grid-area: toggle;
        margin-top: 2px;
        font-size: 11px;
    }
}

.pinned {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

    .pinned .pinned-row {
        background: transparent;
        border: none;
        padding: 6px 2px;
    }

.msg-menu .mm-actions {
    display: flex;
    flex-direction: column !important;
    align-items: stretch;
    gap: 6px;
    margin-top: 10px;
}

    .msg-menu .mm-actions button {
        width: 100%;
        justify-content: flex-start;
        padding: 10px 12px;
        border-radius: 12px;
        text-align: left;
    }

        .msg-menu .mm-actions button.danger {
            color: #ff4d4d;
        }

body[data-theme="dark"] .createWizard,
body[data-theme="dark"] .createWizard * {
    color: var(--text-main);
}

    body[data-theme="dark"] .createWizard .muted,
    body[data-theme="dark"] .createWizard .choice-sub,
    body[data-theme="dark"] .createWizard .hint {
        color: var(--text-subtle) !important;
    }

/* Унификация кнопок в шитах/карточках (добавление участников и т.п.) */
.sheet .sheetActions,
.sheet .sheet-actions,
.modal .modalActions,
.modal .modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

    .sheet .sheetActions button,
    .sheet .sheet-actions button,
    .modal .modalActions button,
    .modal .modal-actions button {
        height: 40px;
        padding: 0 14px;
        border-radius: 12px;
        border: 1px solid var(--stroke);
        background: var(--card-bg);
        color: var(--text-main);
        font-weight: 600;
        cursor: pointer;
    }

        .sheet .sheetActions button.primary,
        .sheet .sheet-actions button.primary,
        .modal .modalActions button.primary,
        .modal .modal-actions button.primary {
            border-color: transparent;
            background: var(--accent);
            color: white;
        }

        .sheet .sheetActions button:hover,
        .sheet .sheet-actions button:hover,
        .modal .modalActions button:hover,
        .modal .modal-actions button:hover {
            filter: brightness(1.02);
        }

/* Wizard create group/channel: гарантируем корректные цвета в обеих темах */
#createWizard .sheet-card {
    color: var(--text-main);
}

#createWizard h3,
#createWizard .choice-title {
    color: var(--text-main);
}

#createWizard .choice-sub,
#createWizard .muted {
    color: var(--text-muted) !important;
}

#createWizard .cw-input,
#createWizard .cw-textarea {
    color: var(--input-fg);
}

    #createWizard .cw-input::placeholder,
    #createWizard .cw-textarea::placeholder {
        color: var(--text-muted);
    }

/* AddMembers sheet */
.am-results {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 280px;
    overflow: auto;
}

.am-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: var(--pane-bg-weak);
}

    .am-row:hover {
        background: var(--hover-bg);
    }

    .am-row .am-left {
        min-width: 0;
    }

    .am-row .am-name {
        font-weight: 700;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .am-row .am-user {
        color: var(--text-muted);
        font-size: 12px;
    }

.am-selected {
    margin-top: 10px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.am-chip {
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    color: var(--text-main);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
}

.am-error {
    margin-top: 10px;
    color: var(--btn-danger);
}

@media (max-width:900px) {
    /* чат реально во всю ширину */
    .messages {
        padding: 0;
    }

    /* немного воздуха внутри сообщений */
    .msg-row {
        padding: 6px 10px;
    }

    /* меньше левый/правый зазор у bubble на мобиле */
    .msg {
        max-width: calc(100% - 20px);
    }

    /* где поддерживается — убираем “проскачку” выше/ниже */
    .messages {
        overscroll-behavior: none;
    }

    body {
        overscroll-behavior: none;
    }
}

.push-prompt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 12px 0 12px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: var(--pane-bg);
    box-shadow: var(--shadow-sm);
}

    .push-prompt.hidden {
        display: none;
    }

.push-prompt__text {
    min-width: 0;
    color: var(--text-main);
}

.push-prompt__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.att-video-wrap {
    position: relative;
    display: inline-flex;
    align-items: stretch;
    width: fit-content;
    max-width: 100%;
    justify-self: start;
}

.att-video {
    width: 100%;
    max-width: 100%;
    border-radius: 8px;
}

.att-open-media {
    position: absolute;
    right: 8px;
    top: 8px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 999px;
    background: rgba(0,0,0,.52);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
}

.media-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0,0,0,.84);
}

    .media-modal.hidden {
        display: none;
    }

.media-stage {
    width: min(96vw, 1200px);
    height: min(88vh, 900px);
    display: flex;
    align-items: center;
    justify-content: center;
}

    .media-stage img,
    .media-stage video {
        max-width: 100%;
        max-height: 100%;
        border-radius: 14px;
        box-shadow: 0 16px 48px rgba(0,0,0,.35);
        background: #000;
    }

.media-close,
.media-prev,
.media-next {
    position: fixed;
    z-index: 2001;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.media-close {
    top: 16px;
    right: 16px;
    font-size: 20px;
}

.media-prev,
.media-next {
    top: 50%;
    transform: translateY(-50%);
    font-size: 28px;
}

.media-prev {
    left: 16px;
}

.media-next {
    right: 16px;
}

    .media-prev.is-disabled,
    .media-next.is-disabled,
    .media-prev:disabled,
    .media-next:disabled {
        opacity: .35;
        cursor: default;
    }

.media-counter {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    z-index: 2001;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    color: #fff;
    backdrop-filter: blur(10px);
    font-size: 12px;
}

@media (max-width: 900px) {
    .push-prompt {
        flex-direction: column;
        align-items: stretch;
    }

    .push-prompt__actions {
        width: 100%;
        justify-content: stretch;
    }

        .push-prompt__actions > button {
            flex: 1 1 auto;
        }

    .media-modal {
        padding: 12px;
    }

    .media-stage {
        width: 100%;
        height: min(82vh, 82svh);
    }

    .media-prev,
    .media-next {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }

    .media-prev {
        left: 8px;
    }

    .media-next {
        right: 8px;
    }

    .media-close {
        top: 8px;
        right: 8px;
    }
}

/* ===== Поиск: более мягкий и аккуратный вид ===== */
.search.row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
    border: 1px solid var(--card-border);
    border-radius: 16px;
    background: var(--pane-bg-weak);
    box-shadow: var(--shadow-sm);
}

#universalSearchQuery {
    flex: 1;
    min-width: 0;
    height: 42px;
    padding: 0 12px;
    border: 0 !important;
    outline: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--input-fg);
    box-shadow: none !important;
}

    #universalSearchQuery::placeholder {
        color: var(--text-muted);
    }

    #universalSearchQuery:focus {
        outline: none;
        box-shadow: none !important;
    }

#btnUniversalSearch {
    width: auto !important;
    min-width: 88px;
    height: 36px !important;
    padding: 0 14px;
    border-radius: 12px;
    flex: 0 0 auto;
}

#universalSearchResults {
    margin-top: 8px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

    #universalSearchResults:empty {
        display: none;
    }

@media (max-width: 1180px) {
    .search.row {
        border-radius: 14px;
    }

    #btnUniversalSearch {
        min-width: 76px;
        padding: 0 12px;
    }
}

/* ===== Composer options / upload state ===== */

.send-original-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text-muted);
    font-size: 12px;
    user-select: none;
}

    .send-original-toggle input {
        margin: 0;
    }

.upload-busy {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: var(--pane-bg-weak);
    color: var(--text-muted);
    font-size: 12px;
}

    .upload-busy.hidden {
        display: none;
    }

.upload-spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-right-color: transparent;
    animation: upload-spin .8s linear infinite;
    opacity: .8;
}

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

#messageInput {
    grid-area: auto;
}

/* ===== Pending attachments ===== */
.att-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px 0;
}

.att-chip {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    max-width: 320px;
    padding: 8px 34px 8px 8px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--file-chip-bg, var(--card-bg));
    color: var(--file-chip-fg, var(--text-main));
    box-shadow: var(--shadow-sm);
}

.att-chip--image {
    min-width: 220px;
}

.att-thumb-wrap {
    width: 56px;
    height: 56px;
    flex: 0 0 56px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--pane-bg-weak);
}

.att-thumb {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.att-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.att-name {
    max-width: 220px;
    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.att-sub {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--file-chip-meta, var(--text-muted));
}

.att-ext {
    font-weight: 700;
    letter-spacing: .02em;
}

.att-dot {
    opacity: .7;
}

.att-chip .x {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

    .att-chip .x:hover {
        background: var(--hover-bg);
        color: var(--text-main);
    }

@media (max-width: 1180px) {

    .upload-busy {
        align-self: flex-start;
    }

    .att-previews {
        padding: 8px 12px 0;
    }

    .att-chip {
        width: 100%;
        max-width: 100%;
    }

    .att-name {
        max-width: none;
    }

    #btnAttach {
        grid-area: attach;
    }

    #messageInput {
        grid-area: input;
    }

    #btnSend {
        grid-area: send;
    }
}

/* ===== Live preview в composer ===== */

.composer-preview {
    display: none;
    position: absolute;
    inset: 0;
    overflow: hidden;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    color: var(--input-fg);
    pointer-events: none;
    z-index: 1;
}

.has-live-preview .composer-preview {
    display: block;
}

.has-live-preview #messageInput {
    position: relative;
    z-index: 2;
    background: transparent !important;
    color: transparent;
    caret-color: var(--input-fg);
}

    .has-live-preview #messageInput::selection {
        background: rgba(158, 217, 222, .35);
        color: transparent;
    }

    .has-live-preview #messageInput::placeholder {
        color: var(--text-muted);
    }

.rt-big {
    font-weight: 700;
    line-height: 1.25;
}

.rt-big-1 {
    font-size: 1.08em;
}

.rt-big-2 {
    font-size: 1.22em;
}

.rt-big-3 {
    font-size: 1.36em;
}

.meta-time {
    cursor: default;
}

.meta-time-hint {
    position: fixed;
    z-index: 120;
    padding: 8px 12px;
    border-radius: 12px;
    background: var(--pane-bg);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
    font-size: 12px;
    pointer-events: none;
    max-width: min(260px, calc(100vw - 16px));
    white-space: nowrap;
}

    .meta-time-hint.hidden {
        display: none;
    }

.date-sep {
    align-self: center;
    margin: 12px auto 4px;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--pane-bg);
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1;
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 1;
}

.search.row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
    border: 1px solid var(--card-border);
    border-radius: 16px;
    background: var(--pane-bg-weak);
    box-shadow: var(--shadow-sm);
}

#universalSearchQuery {
    flex: 1;
    min-width: 0;
    height: 42px;
    padding: 0 12px;
    border: 0 !important;
    background: transparent;
    box-shadow: none !important;
    border-radius: 12px;
}

    #universalSearchQuery:focus {
        outline: none;
        box-shadow: none !important;
    }

#btnUniversalSearch.secondary {
    height: 36px;
    min-width: 88px;
    padding: 0 14px;
    border-radius: 12px;
}

.msg {
    border-radius: 16px;
    padding: 10px 12px;
}

.meta {
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}

.msg-text {
    line-height: 1.45;
}

.reactions {
    margin-top: 8px;
}

.date-sep {
    backdrop-filter: blur(6px);
}

.profile-card {
    backdrop-filter: blur(10px);
}

.profile-body {
    align-items: start;
}

.profile-aside .card {
    border-radius: 14px;
}

.room-section {
    margin-top: 10px;
}

.room-title-edit {
    max-width: 420px;
}

.room-actions-row {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.room-readonly-info {
    margin-top: 8px;
}

.error-text {
    color: var(--btn-danger);
}

.emoji-edit-hint {
    margin-top: 4px;
}

.banner-slot {
    margin: 8px 16px 0;
}

.topbar {
    box-shadow: var(--shadow-sm);
}

.sidebar {
    gap: 14px;
}

    .sidebar h3 {
        opacity: .92;
        letter-spacing: 0.01em;
    }

.chats-scroll {
    background: color-mix(in srgb, var(--card-bg) 94%, transparent);
}

.p-more {
    gap: 6px;
}

.btn-danger,
.p-ghost.small,
.primary,
.secondary {
    min-height: 38px;
}

.room-actions-row .primary,
.room-actions-row .p-ghost,
.p-more .p-ghost.small,
.p-more .btn-danger {
    box-shadow: var(--shadow-sm);
}

.msg {
    backdrop-filter: blur(6px);
}

    .msg.mine {
        box-shadow: 0 4px 16px rgba(0,0,0,.06);
    }

.meta {
    opacity: .92;
}

/* ===== Auth page: визуально ближе к чату ===== */
body.auth {
    min-height: 100vh;
    background: radial-gradient(900px 420px at -10% -10%, var(--accent-1) 0%, transparent 55%) no-repeat, radial-gradient(900px 420px at 110% 115%, var(--accent-2) 0%, transparent 55%) no-repeat, var(--bg-page);
}

.auth-container {
    padding: 28px;
}

.auth-box--chatlike {
    max-width: 420px;
    gap: 14px;
    padding: 18px;
    border-radius: 20px;
    box-shadow: 0 14px 40px rgba(0,0,0,.08);
    backdrop-filter: blur(10px);
}

.auth-brand {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.auth-box .logo {
    margin: 0;
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 36px;
    padding: 0 12px;
    border-radius: 12px;
    background: var(--accent-2);
    font-size: 20px;
    font-weight: 900;
}

.auth-subtitle {
    font-size: 12px;
    line-height: 1.35;
    color: var(--text-muted);
    max-width: 280px;
}

.auth-hero {
    padding: 14px;
    border: 1px solid var(--card-border);
    border-radius: 16px;
    background: color-mix(in srgb, var(--pane-bg-weak) 86%, transparent);
    box-shadow: var(--shadow-sm);
}

.auth-hero__badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--accent-1);
    color: var(--text-main);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-hero__text {
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-main);
}

.auth-form {
    display: grid;
    gap: 10px;
}

    .auth-form input {
        margin: 0;
    }

.auth-actions {
    margin-top: 2px;
}

.auth-btn-secondary {
    background: var(--pane-bg) !important;
    color: var(--text-main) !important;
}

.auth-btn-primary {
    background: var(--btn-primary) !important;
    color: #fff !important;
}

.auth-status {
    min-height: 20px;
    font-size: 12px;
    line-height: 1.35;
    padding-top: 2px;
}

@media (max-width: 560px) {
    .auth-container {
        padding: 16px;
    }

    .auth-box--chatlike {
        max-width: 100%;
        padding: 16px;
        border-radius: 18px;
    }

    .auth-subtitle {
        max-width: none;
    }

    .auth-actions {
        display: flex;
        flex-direction: row;
        gap: 10px;
        align-items: stretch;
    }

        .auth-actions button {
            flex: 1 1 0;
            width: auto;
            min-height: 44px;
            border-radius: 12px;
        }
}

.policy-overlay {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(6px);
}

    .policy-overlay.hidden {
        display: none;
    }

.policy-card {
    width: min(860px, 100%);
    max-height: min(84vh, 860px);
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    gap: 14px;
    padding: 18px;
    border-radius: 18px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-sm);
}

.policy-title {
    font-size: 18px;
    font-weight: 800;
}

.policy-text {
    overflow: auto;
    white-space: pre-wrap;
    line-height: 1.5;
    padding: 14px;
    border-radius: 14px;
    border: 1px solid var(--card-border);
    background: var(--pane-bg-weak);
    font-size: 14px;
}

.policy-accept-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.policy-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ===== final attach button ===== */
#btnAttach.attach-btn {
    grid-area: attach;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 12px;
    border: 1px solid var(--input-border);
    background: var(--pane-bg);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    appearance: none;
    -webkit-appearance: none;
    font-size: 0;
    line-height: 1;
}

    #btnAttach.attach-btn:hover {
        background: var(--hover-bg);
    }

    #btnAttach.attach-btn:focus-visible {
        outline: none;
        box-shadow: var(--focus-ring);
    }

    #btnAttach.attach-btn svg {
        width: 20px;
        height: 20px;
        stroke: currentColor;
        fill: none;
        stroke-width: 1.9;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

.atts .att-audio-card audio::-webkit-media-controls-panel {
    background: color-mix(in srgb, var(--card-bg) 92%, transparent);
}

.msg-reply .r-media {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.msg-reply .r-thumb {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    object-fit: cover;
    flex: 0 0 34px;
    border: 1px solid var(--card-border);
}

.msg-reply .r-text-wrap {
    min-width: 0;
    flex: 1 1 auto;
}

/* ===== SINGLE FINAL COMPOSER ===== */
.chat-input {
    position: relative;
    display: grid;
    grid-template-columns: 36px 36px minmax(0, 1fr) 44px;
    grid-template-areas: "attach record input send";
    align-items: end;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--card-border);
    background: color-mix(in srgb, var(--card-bg) 92%, transparent);
    backdrop-filter: blur(10px);
    min-width: 0;
    overflow: visible;
}

#btnAttach {
    grid-area: attach;
}

#btnRecord {
    grid-area: record;
}

#btnSend {
    grid-area: send;
}

.composer-stack {
    grid-area: input;
    position: relative;
    min-width: 0;
    border: 1px solid var(--input-border);
    border-radius: 20px;
    background: var(--input-bg);
    overflow: hidden;
}

#btnAttach.attach-btn,
.record-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 10px;
    border: 1px solid var(--input-border);
    background: var(--pane-bg);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    appearance: none;
    -webkit-appearance: none;
}

    #btnAttach.attach-btn:hover,
    .record-btn:hover {
        background: var(--hover-bg);
    }

    #btnAttach.attach-btn svg,
    .record-btn svg {
        width: 19px;
        height: 19px;
        stroke: currentColor;
        fill: none;
        stroke-width: 1.9;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

#btnSend.primary.send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.composer-toggle {
    position: absolute;
    left: 53px;
    top: -10px;
    transform: translateX(-50%);
    z-index: 6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 0;
    padding: 4px 8px;
    min-width: 84px;
    border-radius: 999px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    font-size: 10.5px;
    line-height: 1;
    white-space: nowrap;
}

    .composer-toggle input {
        margin: 0;
    }

.composer-preview,
#messageInput {
    display: block;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    margin: 0;
    padding: 12px 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    font: inherit;
}

#messageInput {
    min-height: 46px;
    max-height: calc(1.4em * 10 + 28px);
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--input-fg);
    resize: none;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: 2;
}

.composer-preview {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    color: var(--input-fg);
    overflow: hidden;
}

.has-live-preview .composer-preview {
    display: block;
}

.has-live-preview #messageInput {
    color: transparent !important;
    -webkit-text-fill-color: transparent;
    caret-color: var(--input-fg);
    text-shadow: none;
}

    .has-live-preview #messageInput::selection {
        color: transparent;
        -webkit-text-fill-color: transparent;
        background: rgba(158, 217, 222, .35);
    }

    .has-live-preview #messageInput::placeholder {
        color: var(--text-muted);
        -webkit-text-fill-color: var(--text-muted);
    }

.record-badge {
    position: absolute;
    left: 53px;
    right: auto;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    z-index: 7;
    padding: 7px 10px;
    border-radius: 999px;
    background: var(--pane-bg);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-sm);
    font-size: 12px;
    color: var(--text-main);
    white-space: nowrap;
}

.record-draft {
    margin: 0 16px 10px;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid var(--card-border);
    background: color-mix(in srgb, var(--pane-bg) 92%, transparent);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

    .record-draft.hidden {
        display: none !important;
    }

@media (max-width: 1180px) {
    .chat-input {
        gap: 7px;
        padding: 26px 10px calc(10px + env(safe-area-inset-bottom));
    }

    #btnAttach.attach-btn,
    .record-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
    }

    #btnSend.primary.send {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }

    .composer-toggle {
        left: 8px;
        top: 6px;
        width: 74px;
        font-size: 10px;
        padding: 4px 7px;
    }

    .composer-preview,
    #messageInput {
        padding: 11px 12px;
    }

    .record-badge {
        right: 46px;
        bottom: 46px;
        font-size: 11px;
    }

    .record-draft {
        margin: 0 10px 8px;
        padding: 10px;
    }
}

.att-file-missing {
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px dashed var(--card-border);
    color: var(--text-muted);
    background: color-mix(in srgb, var(--pane-bg) 92%, transparent);
}

.search-section-title {
    margin: 4px 2px 2px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
}

.search-user-card {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

    .search-user-card:hover {
        background: var(--hover-bg);
    }

.search-user-card__avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
}

.search-user-card__meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.search-user-card__title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-user-card__sub {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-user-card__action {
    min-width: 88px;
}

@media (max-width: 1180px) {
    .search-user-card {
        grid-template-columns: 44px minmax(0, 1fr) auto;
        gap: 10px;
    }

    .search-user-card__avatar {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    .search-user-card__action {
        min-width: 76px;
    }
}

/* ===== FINAL RECORD / AUDIO LOOK ===== */
.record-draft {
    max-width: min(420px, calc(100% - 32px));
}

.record-draft__preview {
    display: flex;
    justify-content: center;
}

    .record-draft__preview video {
        width: min(280px, 100%);
        max-height: 220px;
        object-fit: cover;
        border-radius: 14px;
    }

    .record-draft__preview audio {
        width: min(320px, 100%);
    }

.att-audio-card {
    width: fit-content !important;
    max-width: min(360px, 100%) !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    gap: 6px !important;
}

.msg .att-audio-card,
.msg.mine .att-audio-card {
    width: fit-content !important;
    max-width: min(360px, 100%) !important;
    min-width: 0 !important;
}

.att-audio-meta {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.att-audio-title {
    font-size: 12px !important;
    font-weight: 700;
}

.att-audio-sub {
    font-size: 11px !important;
    color: var(--text-muted);
    white-space: nowrap;
}

.att-audio-player {
    width: min(340px, 100%) !important;
    height: 36px !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: transparent !important;
    box-shadow: none !important;
}

.msg .atts audio,
.msg .atts .att-audio-player {
    background: transparent !important;
    border: 0 !important;
}

/* ===== THEME PANEL ===== */
.theme-card {
    width: min(520px, 94vw);
    max-width: 520px;
    overflow: hidden;
}

.theme-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--card-border);
    background: radial-gradient(520px 220px at -10% -30%, var(--accent-1) 0%, transparent 60%) no-repeat, radial-gradient(520px 220px at 110% 120%, var(--accent-2) 0%, transparent 60%) no-repeat, var(--card-bg);
}

.theme-panel__title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-main);
}

.theme-panel__body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.theme-option {
    width: 100%;
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) 20px;
    align-items: center;
    gap: 12px;
    padding: 14px 14px;
    border-radius: 16px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
    box-shadow: var(--shadow-sm);
    transition: background .12s ease, border-color .12s ease, transform .12s ease;
}

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

    .theme-option:active {
        transform: scale(.995);
    }

.theme-option__emoji {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.theme-option__text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.theme-option__name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
}

.theme-option__sub {
    font-size: 12px;
    line-height: 1.25;
}

.theme-option__check {
    opacity: 0;
    color: var(--btn-primary);
    font-weight: 800;
    font-size: 16px;
    justify-self: end;
}

.theme-option.is-active {
    border-color: var(--btn-primary);
    background: color-mix(in srgb, var(--btn-primary) 10%, var(--card-bg));
}

    .theme-option.is-active .theme-option__check {
        opacity: 1;
    }

@media (max-width: 720px) {
    .theme-card {
        width: min(100%, 96vw);
        max-width: none;
    }

    .theme-panel__head {
        padding: 14px 14px;
    }

    .theme-panel__title {
        font-size: 18px;
    }

    .theme-panel__body {
        padding: 10px;
    }

    .theme-option {
        padding: 12px 12px;
        border-radius: 14px;
    }
}

.brand-btn {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.about-card {
    width: min(620px, 94vw);
}

.about-card__text {
    padding: 2px 2px 10px;
    white-space: pre-wrap;
    line-height: 1.45;
    color: var(--text-main);
}

.about-link-card {
    width: 100%;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--card-bg);
    color: var(--text-main);
    text-align: left;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

    .about-link-card:hover {
        background: var(--hover-bg);
    }

.about-link-card__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-1);
    font-size: 20px;
}

.about-link-card__meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 4px;
}

.about-link-card__title {
    font-size: 14px;
    font-weight: 700;
}

.about-link-card__sub {
    font-size: 12px;
}

.room-title-edit,
#roomDescEdit.room-editing {
    border-color: var(--btn-primary) !important;
    box-shadow: inset 0 -1px 0 var(--btn-primary);
}

.profile-about {
    margin-top: 8px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

#profileAboutText {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.4;
}

.profile-featured {
    margin-bottom: 10px;
}

.profile-featured__card {
    cursor: pointer;
}

.profile-badges-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    font-size: 12px;
    line-height: 1;
    cursor: default;
}

    .user-badge.compact {
        min-width: 20px;
        height: 20px;
        padding: 0 6px;
        font-size: 11px;
    }

.profile-channel-actions {
    margin-top: 8px;
}

.badge-panel-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.badge-panel-item {
    width: 100%;
    display: grid;
    grid-template-columns: 28px minmax(0,1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

    .badge-panel-item.is-active {
        border-color: var(--btn-primary);
        background: color-mix(in srgb, var(--btn-primary) 10%, var(--card-bg));
    }

.badge-panel-item__icon {
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.badge-panel-item__title {
    font-weight: 700;
    min-width: 0;
}

.badge-panel-item__check {
    font-weight: 800;
    opacity: 0;
}

.badge-panel-item.is-active .badge-panel-item__check {
    opacity: 1;
}

.chat-title-row,
.member-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    width: 100%;
}

.chat-title,
.member-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-badges,
.chat-title-badges,
.member-badges {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    flex: 0 0 auto;
}

.chat-title-text {
    min-width: 0;
}

.att-video-wrap {
    position: relative;
    display: inline-block;
    width: fit-content;
    max-width: min(320px, 100%);
    align-self: flex-start;
}

.msg.me .att-video-wrap {
    align-self: flex-end;
}

.att-video {
    display: block;
    width: auto;
    max-width: min(320px, 100%);
    max-height: 360px;
    border-radius: 14px;
    background: #000;
}

.att-open-media {
    position: absolute;
    right: 8px;
    top: 8px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 999px;
    background: rgba(0,0,0,.45);
    color: #fff;
    cursor: pointer;
}

.chat-input {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
    padding: 10px 12px;
    border-top: 1px solid var(--card-border);
    background: var(--card-bg);
}

.composer-side {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    flex: 0 0 auto;
}

.composer-side--right {
    flex-direction: row;
    align-items: end;
}

.attach-btn,
.record-btn,
#btnSend.primary.send {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

    .attach-btn svg,
    .record-btn svg {
        width: 20px;
        height: 20px;
    }

.send-original-toggle.composer-toggle {
    font-size: 12px;
    line-height: 1;
    padding: 6px 8px;
    border-radius: 10px;
    max-width: 92px;
    text-align: center;
}

.composer-stack {
    position: relative;
    min-width: 0;
}

#messageInput,
#composerPreview {
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
    max-height: calc(1.4em * 10 + 24px);
    padding: 12px 14px;
    border-radius: 14px;
    line-height: 1.4;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#messageInput {
    resize: none;
    overflow-y: auto;
    background: transparent;
    color: transparent;
    caret-color: var(--input-fg);
    position: relative;
    z-index: 2;
}

#composerPreview {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    color: var(--input-fg);
    white-space: pre-wrap;
}

@media (max-width: 600px) {
    .chat-input {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 8px;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    }

    .composer-side {
        gap: 6px;
    }

    .send-original-toggle.composer-toggle {
        font-size: 11px;
        max-width: 84px;
    }
}

.composer-stack,
#messageInput,
#composerPreview {
    min-width: 0;
}

#messageInput,
#composerPreview {
    overflow: hidden;
}

    #messageInput::placeholder {
        color: var(--text-muted);
    }

.att-audio-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: min(320px, 100%);
    max-width: min(420px, 100%);
    padding: 10px 12px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--card-bg);
    box-sizing: border-box;
}

    .att-audio-card.is-voice {
        padding: 8px 0 0;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

.att-audio-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
}

.att-audio-title {
    font-weight: 700;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.att-audio-sub {
    flex: 0 0 auto;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 12px;
}

.att-audio-player {
    width: 100%;
    min-width: 260px;
    max-width: 100%;
    display: block;
}

@media (max-width: 600px) {
    .att-audio-card {
        min-width: 100%;
        max-width: 100%;
    }

    .att-audio-player {
        min-width: 0;
    }
}

.att-audio-card audio::-webkit-media-controls-panel {
    background-color: var(--card-bg);
}

[data-theme="dark"] .att-audio-card.is-voice audio::-webkit-media-controls-panel {
    background-color: #0f172a;
}

.profile-overlay .profile-card,
.profile-overlay .theme-card {
    width: min(760px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
}

.p-menu {
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
}

@media (max-width: 480px) {
    .profile-overlay .profile-card,
    .profile-overlay .theme-card {
        width: calc(100vw - 12px);
        max-width: calc(100vw - 12px);
        border-radius: 14px;
    }

    .profile-body,
    .room-section,
    .profile-about,
    .profile-featured,
    .profile-channel-actions {
        min-width: 0;
    }

    .name-row,
    .username-row,
    .member-actions {
        gap: 6px;
        flex-wrap: wrap;
    }

    .p-menu {
        right: 0;
        left: auto;
        max-width: calc(100vw - 16px);
    }
}

.profile-featured {
    display: flex;
    justify-content: flex-start;
}

.profile-featured__card,
.about-link-card {
    width: fit-content;
    max-width: min(420px, 100%);
}

    .profile-featured__card .about-link-card__meta,
    .about-link-card__meta {
        min-width: 0;
    }

#profilePanel .profile-card {
    width: min(680px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
}

#profilePanel .profile-body {
    max-width: 100%;
}

#profilePanel .profile-aside {
    max-width: 240px;
}

#profileSetFeaturedChannelBtn {
    width: fit-content;
    max-width: 100%;
}

.profile-channel-actions {
    display: flex;
    justify-content: flex-start;
}

.profile-featured__card {
    padding-right: 12px;
}

#profileBadgesBtn,
#profileEditDisplayName,
#profileEditUsername,
#profileEditAbout {
    border: 0;
    background: transparent;
    box-shadow: none;
    padding: 2px 4px;
    width: auto;
    height: auto;
    min-width: 0;
    min-height: 0;
}

.username-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-wrap: nowrap;
}

#profileUsername {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.name-row .p-name {
    flex: 0 1 auto;
}

.name-row .p-more {
    flex: 0 0 auto;
}

.featured-channel-item {
    width: 100%;
    display: grid;
    grid-template-columns: 32px minmax(0,1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    cursor: pointer;
}

    .featured-channel-item.is-active {
        border-color: var(--btn-primary);
        background: color-mix(in srgb, var(--btn-primary) 10%, var(--card-bg));
    }

[data-theme="dark"] .att-audio-card.is-voice {
    background: transparent;
    border: 0;
    box-shadow: none;
}

    [data-theme="dark"] .att-audio-card.is-voice .att-audio-title {
        color: var(--text-main);
    }

    [data-theme="dark"] .att-audio-card.is-voice .att-audio-sub {
        color: var(--text-muted);
    }

.sidebar {
    position: relative;
    z-index: 1000;
}

/* ===== FINAL MOBILE LAYOUT OVERRIDE ===== */
@media (max-width: 1180px) {
    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .layout {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        max-width: 100vw;
        grid-template-columns: minmax(0, 1fr);
        overflow: hidden;
    }

    .main {
        width: 100vw;
        max-width: 100vw;
        min-width: 0;
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(88vw, 360px);
        max-width: 360px;
        transform: translateX(-100%);
        transition: transform .22s ease;
        z-index: 1002;
        border-right: 1px solid var(--card-border);
        overflow-y: auto;
        overflow-x: hidden;
    }

    :root.drawer-open .sidebar {
        transform: translateX(0);
    }

    .drawer-backdrop {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: min(88vw, 360px);
        z-index: 1001;
        background: rgba(0,0,0,.10);
        backdrop-filter: none;
    }

    .messages {
        min-width: 0;
        padding-left: 12px;
        padding-right: 12px;
    }

    .msg {
        max-width: min(100%, calc(100vw - 32px));
    }
}

@media (min-width: 1181px) {
    .drawer-backdrop {
        display: none !important;
    }
}

/* ===== FINAL VOICE META ALIGN ===== */
.att-audio-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
}

.att-audio-title {
    min-width: 0;
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.att-audio-sub {
    flex: 0 0 auto;
    white-space: nowrap;
    text-align: right;
}

.policy-card {
    position: relative;
    z-index: 10051;
}

/* ===== audio attachments: stack vertically ===== */
.msg .atts .att-audio-card {
    grid-column: 1 / -1;
    justify-self: start;
    display: flex;
    flex-direction: column;
}

.msg .atts {
    align-items: start;
}

/* ===== mobile drawer interaction safety ===== */
@media (max-width: 1180px) {
    .sidebar {
        z-index: 1002 !important;
        pointer-events: auto;
    }

    .drawer-backdrop {
        z-index: 1001 !important;
    }
}

/* ===== audio cards: always vertical stack ===== */
.msg .atts .att-audio-card {
    grid-column: 1 / -1;
    justify-self: start;
    display: flex;
    flex-direction: column;
}

.msg .atts {
    align-items: start;
}

/* ===== drawer interaction safety ===== */
@media (max-width: 1180px) {
    .sidebar {
        z-index: 1002 !important;
        pointer-events: auto;
    }

    .drawer-backdrop {
        z-index: 1001 !important;
    }
}

/* ===== video notes: no empty right area ===== */
.att-video {
    width: min(320px, 100%);
    max-width: 100%;
    height: auto;
    border-radius: 12px;
}

.att-video-wrap--note,
.msg .att-video-wrap--note,
.msg.mine .att-video-wrap--note,
.msg.me .att-video-wrap--note {
    width: fit-content !important;
    max-width: min(280px, 100%) !important;
    justify-self: start;
}

    .att-video-wrap--note .att-video,
    .att-video--note {
        width: min(280px, 100%) !important;
        max-width: 100% !important;
        background: transparent !important;
    }

/* ===== ALL PROFILE/ROOM/THEME PANELS: mobile safe scroll ===== */
@media (max-width: 900px) {
    .profile-overlay {
        padding: 12px;
        align-items: flex-start;
        justify-content: center;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

        .profile-overlay .profile-card,
        .profile-overlay .theme-card,
        .profile-overlay .about-card {
            width: 100%;
            max-width: 100%;
            max-height: calc(100dvh - 24px);
            display: flex;
            flex-direction: column;
            overflow: hidden;
            border-radius: 14px;
        }

        .profile-overlay .profile-body,
        .profile-overlay .theme-panel__body {
            overflow-y: auto;
            min-height: 0;
            -webkit-overflow-scrolling: touch;
        }

    #roomPanel .profile-body,
    #profilePanel .profile-body {
        overflow-y: auto;
    }
}

/* ===== SINGLE CANONICAL COMPOSER LAYOUT ===== */
.chat-input {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) 44px;
    align-items: end;
    gap: 10px;
    margin: 10px 16px 16px;
    padding: 12px;
    border: 1px solid var(--card-border);
    border-radius: 18px;
    background: color-mix(in srgb, var(--pane-bg) 94%, transparent);
    box-shadow: var(--shadow-sm);
    min-width: 0;
    overflow: visible;
}

.composer-left {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 86px;
    padding-top: 18px;
    flex: 0 0 86px;
}

.composer-left-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.composer-right {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
}

.composer-stack {
    position: relative;
    min-width: 0;
    border: 1px solid var(--input-border);
    border-radius: 18px;
    background: var(--input-bg);
    overflow: hidden;
}

.composer-toggle {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translate(-50%, -50%);
    z-index: 4;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    font-size: 10.5px;
    line-height: 1;
    white-space: nowrap;
}

    .composer-toggle input {
        margin: 0;
    }

#btnAttach,
#btnRecord {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    margin: 0;
    border-radius: 10px;
    border: 1px solid var(--input-border);
    background: var(--pane-bg);
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
    flex: 0 0 34px;
}

    #btnAttach:hover,
    #btnRecord:hover {
        background: var(--hover-bg);
    }

    #btnAttach svg,
    #btnRecord svg {
        width: 20px;
        height: 20px;
        stroke: currentColor;
        fill: none;
        stroke-width: 1.9;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

#btnSend {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    margin: 0;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--btn-primary);
}

    #btnSend:hover {
        background: var(--hover-bg) !important;
    }

.composer-preview,
#messageInput {
    display: block;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    margin: 0;
    padding: 12px 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    font: inherit;
}

#messageInput {
    min-height: 44px;
    max-height: calc(1.4em * 10 + 28px);
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--input-fg);
    resize: none;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: 2;
}

.composer-preview {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    color: var(--input-fg);
    overflow: hidden;
}

.record-badge {
    right: 52px;
    bottom: 52px;
}

@media (max-width: 1180px) {
    .chat-input {
        margin: 8px 10px 12px;
        padding: 10px;
        gap: 8px;
        border-radius: 16px;
    }

    .composer-left {
        min-width: 78px;
        flex-basis: 78px;
        gap: 7px;
        padding-top: 16px;
    }

    .composer-left-buttons {
        gap: 7px;
    }

    #btnAttach,
    #btnRecord {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        flex-basis: 32px;
    }

    #btnSend {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }

    .composer-toggle {
        left: 49px;
        top: -9px;
        min-width: 80px;
        font-size: 10px;
        padding: 4px 7px;
    }

    .record-badge {
        left: 49px;
        bottom: calc(100% + 4px);
        font-size: 11px;
    }

    .composer-preview,
    #messageInput {
        padding: 10px 11px;
    }
}

/* ===== SINGLE CANONICAL MOBILE DRAWER ===== */
.drawer-backdrop.hidden {
    display: none !important;
}

@media (max-width: 1180px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(88vw, 360px);
        max-width: 360px;
        transform: translateX(-100%);
        transition: transform .22s ease;
        z-index: 1002;
        border-right: 1px solid var(--card-border);
        overflow-y: auto;
        overflow-x: hidden;
        pointer-events: auto;
    }

    :root.drawer-open .sidebar {
        transform: translateX(0);
    }

    .drawer-backdrop {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: min(88vw, 360px);
        z-index: 1001;
        background: rgba(0,0,0,.10);
        backdrop-filter: none;
    }
}

@media (min-width: 1181px) {
    .drawer-backdrop {
        display: none !important;
    }
}

/* ===== SINGLE CANONICAL VIDEO NOTE LAYOUT ===== */
.msg .att-video-wrap,
.msg .att-video-wrap--note,
.msg.mine .att-video-wrap,
.msg.mine .att-video-wrap--note,
.msg.me .att-video-wrap,
.msg.me .att-video-wrap--note {
    position: relative;
    display: inline-block;
    width: fit-content !important;
    max-width: min(320px, 100%);
    justify-self: start;
    align-self: flex-start;
}

.msg.mine .att-video-wrap,
.msg.mine .att-video-wrap--note,
.msg.me .att-video-wrap,
.msg.me .att-video-wrap--note {
    justify-self: end;
}

.msg .att-video,
.msg .att-video--note {
    display: block;
    width: auto !important;
    max-width: min(320px, 100%) !important;
    max-height: 360px;
    height: auto;
    border-radius: 14px;
    background: #000 !important;
}

.msg .att-video-wrap--note,
.msg.mine .att-video-wrap--note,
.msg.me .att-video-wrap--note {
    max-width: min(280px, 100%) !important;
}

    .msg .att-video-wrap--note .att-video,
    .msg .att-video--note {
        width: auto !important;
        max-width: min(280px, 100%) !important;
    }

.chat-input {
    position: relative !important;
    display: grid !important;
    grid-template-columns: 36px 36px minmax(0, 1fr) 40px !important;
    grid-template-rows: auto auto !important;
    grid-template-areas:
        "toggle toggle . ."
        "attach record input send" !important;
    align-items: end !important;
    gap: 8px 8px !important;
    margin: 10px 16px 16px !important;
    padding: 10px 12px 12px !important;
    border: 1px solid var(--card-border) !important;
    border-radius: 18px !important;
    background: color-mix(in srgb, var(--pane-bg) 94%, transparent) !important;
    box-shadow: var(--shadow-sm) !important;
    min-width: 0 !important;
    overflow: visible !important;
}

    .chat-input > .composer-toggle {
        grid-area: toggle !important;
        position: static !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        justify-self: center !important;
        align-self: end !important;
        width: 80px !important;
        min-width: 80px !important;
        max-width: 80px !important;
        margin: 0 0 2px !important;
        padding: 4px 8px !important;
        border-radius: 999px !important;
        border: 1px solid var(--card-border) !important;
        background: var(--card-bg) !important;
        box-shadow: var(--shadow-sm) !important;
        font-size: 10.5px !important;
        line-height: 1 !important;
        white-space: nowrap !important;
        color: var(--text-muted) !important;
        z-index: 4 !important;
    }

        .chat-input > .composer-toggle input {
            margin: 0 !important;
        }

    .chat-input > #btnAttach.attach-btn {
        grid-area: attach !important;
    }

    .chat-input > #btnRecord.record-btn {
        grid-area: record !important;
    }

    .chat-input > .composer-stack {
        grid-area: input !important;
        position: relative !important;
        min-width: 0 !important;
        align-self: stretch !important;
        border: 1px solid var(--input-border) !important;
        border-radius: 20px !important;
        background: var(--input-bg) !important;
        overflow: hidden !important;
    }

    .chat-input > #btnSend.primary.send {
        grid-area: send !important;
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
        padding: 0 !important;
        margin: 0 !important;
        border: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        border-radius: 12px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        color: var(--btn-primary) !important;
    }

    .chat-input > #btnAttach.attach-btn,
    .chat-input > #btnRecord.record-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 10px !important;
        border: 1px solid var(--input-border) !important;
        background: var(--pane-bg) !important;
        box-shadow: var(--shadow-sm) !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        color: var(--text-main) !important;
        flex: 0 0 36px !important;
        appearance: none !important;
        -webkit-appearance: none !important;
    }

        .chat-input > #btnAttach.attach-btn:hover,
        .chat-input > #btnRecord.record-btn:hover,
        .chat-input > #btnSend.primary.send:hover {
            background: var(--hover-bg) !important;
        }

        .chat-input > #btnAttach.attach-btn svg,
        .chat-input > #btnRecord.record-btn svg {
            width: 19px !important;
            height: 19px !important;
            stroke: currentColor !important;
            fill: none !important;
            stroke-width: 1.9 !important;
            stroke-linecap: round !important;
            stroke-linejoin: round !important;
        }

    .chat-input > .composer-stack > .composer-preview,
    .chat-input > .composer-stack > #messageInput {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        margin: 0 !important;
        padding: 14px 16px 12px !important;
        line-height: 1.4 !important;
        white-space: pre-wrap !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
        font: inherit !important;
    }

    .chat-input > .composer-stack > #messageInput {
        min-height: 52px !important;
        max-height: calc(1.4em * 10 + 30px) !important;
        border: 0 !important;
        outline: 0 !important;
        background: transparent !important;
        color: var(--input-fg) !important;
        resize: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        position: relative !important;
        z-index: 2 !important;
    }

    .chat-input > .composer-stack > .composer-preview {
        position: absolute !important;
        inset: 0 !important;
        z-index: 1 !important;
        pointer-events: none !important;
        color: var(--input-fg) !important;
        overflow: hidden !important;
    }

.has-live-preview .chat-input > .composer-stack > #messageInput {
    color: transparent !important;
    -webkit-text-fill-color: transparent !important;
    caret-color: var(--input-fg) !important;
    text-shadow: none !important;
}

    .has-live-preview .chat-input > .composer-stack > #messageInput::selection {
        color: transparent !important;
        -webkit-text-fill-color: transparent !important;
        background: rgba(158, 217, 222, .35) !important;
    }

    .has-live-preview .chat-input > .composer-stack > #messageInput::placeholder {
        color: var(--text-muted) !important;
        -webkit-text-fill-color: var(--text-muted) !important;
    }

.chat-input > .record-badge {
    right: 46px !important;
    bottom: 46px !important;
}

@media (max-width: 1180px) {
    .chat-input {
        grid-template-columns: 34px 34px minmax(0, 1fr) 36px !important;
        gap: 7px 8px !important;
        margin: 8px 10px 12px !important;
        padding: 9px 10px calc(10px + env(safe-area-inset-bottom)) !important;
        border-radius: 16px !important;
    }

        .chat-input > #btnAttach.attach-btn,
        .chat-input > #btnRecord.record-btn {
            width: 34px !important;
            height: 34px !important;
            min-width: 34px !important;
            min-height: 34px !important;
            flex-basis: 34px !important;
        }

        .chat-input > #btnSend.primary.send {
            width: 36px !important;
            height: 36px !important;
            min-width: 36px !important;
            min-height: 36px !important;
        }

        .chat-input > .composer-toggle {
            width: 78px !important;
            min-width: 78px !important;
            max-width: 78px !important;
            font-size: 10px !important;
            padding: 4px 7px !important;
        }

        .chat-input > .composer-stack > .composer-preview,
        .chat-input > .composer-stack > #messageInput {
            padding: 13px 14px 11px !important;
        }

        .chat-input > .record-badge {
            right: 44px !important;
            bottom: 44px !important;
            font-size: 11px !important;
        }
}

/* --- mobile menu button: принудительно показываем --- */
@media (max-width: 1180px) {
    .only-mobile {
        display: inline-flex !important;
    }

    .chat-header #btnMenu.only-mobile {
        display: inline-flex !important;
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        flex: 0 0 36px !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 10px !important;
        border: 1px solid var(--input-border) !important;
        background: var(--pane-bg) !important;
        color: var(--text-main) !important;
        box-shadow: var(--shadow-sm) !important;
        margin-right: 2px !important;
    }

    .sidebar {
        z-index: 1002 !important;
        pointer-events: auto !important;
    }

    .drawer-backdrop {
        left: min(88vw, 360px) !important;
        z-index: 1001 !important;
        background: rgba(0,0,0,.10) !important;
        backdrop-filter: none !important;
    }
}

/* --- video notes: bubble must shrink to media width --- */
.msg.msg--video-note,
.msg.mine.msg--video-note,
.msg.me.msg--video-note {
    display: inline-flex !important;
    flex-direction: column !important;
    width: fit-content !important;
    max-width: min(296px, calc(100vw - 40px)) !important;
}

    .msg.msg--video-note .atts,
    .msg.mine.msg--video-note .atts,
    .msg.me.msg--video-note .atts {
        display: block !important;
        width: fit-content !important;
        max-width: 100% !important;
    }

    .msg.msg--video-note .att-video-wrap,
    .msg.msg--video-note .att-video-wrap--note,
    .msg.mine.msg--video-note .att-video-wrap,
    .msg.mine.msg--video-note .att-video-wrap--note,
    .msg.me.msg--video-note .att-video-wrap,
    .msg.me.msg--video-note .att-video-wrap--note {
        display: inline-block !important;
        width: fit-content !important;
        max-width: min(280px, 100%) !important;
    }

    .msg.msg--video-note .att-video,
    .msg.msg--video-note .att-video--note,
    .msg.mine.msg--video-note .att-video,
    .msg.mine.msg--video-note .att-video--note,
    .msg.me.msg--video-note .att-video,
    .msg.me.msg--video-note .att-video--note {
        display: block !important;
        width: auto !important;
        max-width: min(280px, 100%) !important;
        height: auto !important;
        border-radius: 14px !important;
        background: #000 !important;
    }

.chat-input {
    position: relative;
}

    .chat-input .send-original-toggle {
        position: absolute;
        bottom: 50px;
        left: 8px;
        margin: 0;
    }

    .chat-input .record-badge {
        bottom: 56px !important;
        right: 8px !important;
        padding: 2px 6px !important;
        font-size: 10px;
    }

@media (max-width: 480px) {
    .profile-cover .p-reactions {
        font-size: 14px;
        gap: 4px;
    }
}

/* === composer hotfix: самый последний победитель === */
.chat-input {
    position: relative !important;
    grid-template-columns: 36px 36px minmax(0, 1fr) 40px !important;
    grid-template-rows: auto !important;
    grid-template-areas: "attach record input send" !important;
    align-items: end !important;
    gap: 8px !important;
    overflow: visible !important;
}

    .chat-input > .composer-toggle {
        position: absolute !important;
        left: 30px !important;
        bottom: calc(100% - 6px) !important;
        transform: translateX(-50%) !important;
        display: inline-flex !important;
        align-items: center !important;
        gap: 6px !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 4px 8px !important;
        border-radius: 999px !important;
        border: 1px solid var(--card-border) !important;
        background: var(--card-bg) !important;
        box-shadow: var(--shadow-sm) !important;
        font-size: 10.5px !important;
        line-height: 1 !important;
        white-space: nowrap !important;
        color: var(--text-muted) !important;
        z-index: 5 !important;
    }

        .chat-input > .composer-toggle input {
            margin: 0 !important;
        }

    .chat-input > .record-badge {
        position: absolute !important;
        left: 30px !important;
        right: auto !important;
        bottom: calc(100% + 10px) !important;
        transform: translateX(-50%) !important;
        display: inline-flex !important;
        align-items: center !important;
        width: auto !important;
        max-width: calc(100vw - 32px) !important;
        padding: 4px 7px !important;
        border-radius: 999px !important;
        font-size: 11px !important;
        line-height: 1 !important;
        white-space: nowrap !important;
        box-shadow: var(--shadow-sm) !important;
        z-index: 6 !important;
    }

@media (max-width: 1180px) {
    .chat-input > .composer-toggle {
        left: 28px !important;
        bottom: calc(100% - 4px) !important;
        font-size: 10px !important;
        padding: 4px 7px !important;
    }

    .chat-input > .record-badge {
        left: 28px !important;
        bottom: calc(100% + 8px) !important;
        font-size: 10px !important;
        padding: 4px 6px !important;
        max-width: calc(100vw - 20px) !important;
    }
}

/* === quick actions / favorites === */
.quick-actions {
    display: grid !important;
    gap: 8px !important;
    margin: 2px 0 8px !important;
}

.qa-create,
.qa-favorites {
    width: 100% !important;
    min-height: 44px !important;
    border-radius: 14px !important;
    padding: 0 14px !important;
    font-size: 14px !important;
    box-shadow: var(--shadow-sm) !important;
}

/* === profile hotfix === */
.avatar-wrap {
    position: relative;
    margin-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.p-avatar-edit {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border: 1px solid var(--card-border);
    border-radius: 999px;
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
}

.profile-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.profile-featured {
    display: flex;
    justify-content: flex-start;
    margin-top: 2px;
    margin-bottom: 0;
}

.profile-featured__card {
    width: 100%;
    max-width: 100%;
    cursor: default;
}

.profile-featured__head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    width: 100%;
}

#profileFeaturedChannelTitle {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-featured__head .p-more {
    margin-left: auto;
}

#profileBadgesBtn,
#profileEditDisplayName,
#profileEditUsername,
#profileEditFeaturedChannel,
#profileEditAbout {
    border: 0;
    background: transparent;
    box-shadow: none;
    padding: 2px 4px;
    width: auto;
    height: auto;
    min-width: 0;
    min-height: 0;
}

.username-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-wrap: nowrap;
}

.profile-about {
    margin-top: 2px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.profile-about__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.profile-about__body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.45;
    padding: 12px 14px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--pane-bg);
    box-shadow: var(--shadow-sm);
}

.profile-secondary-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.profile-mute-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.profile-media-open {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--card-bg);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.media-panel-card {
    width: min(860px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px) !important;
}

.media-panel__tabs {
    display: flex;
    gap: 8px;
    padding: 0 16px 12px;
    flex-wrap: wrap;
}

.media-panel__tab {
    border: 1px solid var(--card-border);
    background: var(--pane-bg);
    color: var(--text-main);
    border-radius: 999px;
    padding: 8px 14px;
    font-weight: 700;
    cursor: pointer;
}

    .media-panel__tab.is-active {
        background: var(--btn-primary);
        color: var(--text-invert, #17242a);
        border-color: transparent;
    }

.media-panel__body {
    padding: 0 16px 16px;
    max-height: min(70vh, 620px);
    overflow-y: auto;
}

.media-panel__empty {
    padding: 18px 4px;
    color: var(--text-muted);
}

.media-panel__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.media-panel__tile {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    overflow: hidden;
    background: var(--pane-bg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

    .media-panel__tile img,
    .media-panel__tile video {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        background: #000;
    }

.media-panel__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.media-panel__file,
.media-panel__audio {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: inherit;
}

.media-panel__file-title,
.media-panel__audio-title {
    font-weight: 700;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-panel__file-meta,
.media-panel__audio-meta {
    color: var(--text-muted);
    font-size: 12px;
}

@media (max-width: 720px) {
    .media-panel__grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }
}

@media (max-width: 420px) {
    .profile-cover .p-reactions {
        right: 10px !important;
        top: 10px !important;
        gap: 4px !important;
        flex-wrap: wrap !important;
        max-width: calc(100% - 132px) !important;
    }

    .profile-cover .p-reaction {
        padding: 5px 8px !important;
        font-size: 12px !important;
    }

    .profile-overlay .profile-card,
    .profile-overlay .theme-card {
        width: calc(100vw - 12px) !important;
        max-width: calc(100vw - 12px) !important;
    }

    .media-panel__body {
        padding: 0 12px 12px;
    }

    .media-panel__tabs {
        padding: 0 12px 10px;
    }
}

/* === FINAL COMPOSER HOTFIX (must be the last block in file) === */
.chat-input {
    position: relative !important;
    overflow: visible !important;
}

    .chat-input > .composer-toggle {
        position: absolute !important;
        left: 52px !important;
        top: auto !important;
        bottom: calc(100% + 6px) !important;
        transform: translateX(-50%) !important;
        margin: 0 !important;
        width: auto !important;
        min-width: 92px !important;
        max-width: none !important;
        z-index: 8 !important;
    }

    .chat-input > .record-badge {
        position: absolute !important;
        left: 52px !important;
        right: auto !important;
        bottom: calc(100% + 30px) !important;
        transform: translateX(-50%) !important;
        z-index: 9 !important;
        padding: 4px 8px !important;
        font-size: 11px !important;
        line-height: 1 !important;
        white-space: nowrap !important;
        pointer-events: none !important;
    }

        .chat-input > .record-badge.hidden {
            display: none !important;
        }

    .chat-input > #btnSend.primary.send {
        align-self: center !important;
        transform: translateY(-7px) !important;
    }

@media (max-width: 1180px) {
    .chat-input > .composer-toggle {
        left: 48px !important;
        bottom: calc(100% + 4px) !important;
        min-width: 84px !important;
        font-size: 10px !important;
        padding: 4px 7px !important;
    }

    .chat-input > .record-badge {
        left: 48px !important;
        bottom: calc(100% + 24px) !important;
        font-size: 10px !important;
    }

    .chat-input > #btnSend.primary.send {
        transform: translateY(-5px) !important;
    }
}

/* === overlays above drawer === */
.profile-overlay {
    z-index: 1105 !important;
    padding: 12px;
    box-sizing: border-box;
}

    .profile-overlay .profile-card,
    .profile-overlay .theme-card,
    .profile-overlay .about-card {
        position: relative;
        z-index: 1106;
    }

.drawer-backdrop {
    z-index: 1001 !important;
}

/* === profile / room menus must open downward, above cover === */
#profilePanel .p-more,
#roomPanel .p-more {
    position: relative !important;
}

#profilePanel .p-menu,
#roomPanel .p-menu {
    top: calc(100% + 8px) !important;
    bottom: auto !important;
    z-index: 1150 !important;
}

    #profilePanel .p-menu::after,
    #roomPanel .p-menu::after {
        top: -6px !important;
        bottom: auto !important;
        transform: rotate(225deg) !important;
    }

/* === profile about editor === */
#profilePanel .profile-about {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
}

.profile-about__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

#profileAboutText {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.45;
    padding: 12px 14px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--pane-bg);
    box-shadow: var(--shadow-sm);
}

/* === profile width / no useless right column === */
#profilePanel .profile-card {
    width: min(560px, calc(100vw - 28px)) !important;
    max-width: calc(100vw - 28px) !important;
}

#profilePanel .profile-body {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    grid-template-columns: 1fr !important;
}

#profilePanel .profile-aside {
    max-width: none !important;
}

/* === room panel redesign === */
#roomPanel .profile-card {
    width: min(560px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: min(88vh, 760px) !important;
    overflow: hidden !important;
}

#roomPanel .room-panel-body {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 220px !important;
    gap: 12px !important;
    padding: 14px 16px 16px !important;
    overflow: auto !important;
}

#roomPanel .room-main,
#roomPanel #roomAside {
    min-width: 0 !important;
}

#roomPanel .room-media-card {
    margin-top: 6px;
}

#roomPanel .p-avatar-edit {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border: 1px solid var(--card-border);
    border-radius: 999px;
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
}

#roomPanel .room-actions-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 900px) {
    #roomPanel .room-panel-body {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 425px) {
    #roomPanel .profile-card {
        width: calc(100vw - 10px) !important;
        max-width: calc(100vw - 10px) !important;
        border-radius: 14px !important;
    }

    #roomPanel .room-panel-body {
        padding: 12px !important;
    }

    #roomPanel #roomMembers,
    #roomPanel .card,
    #roomPanel .room-main,
    #roomPanel #roomAside {
        min-width: 0 !important;
        max-width: 100% !important;
        overflow-wrap: anywhere !important;
    }
}

/* === dark theme voice message tune === */
[data-theme="dark"] .msg .att-audio-card.is-voice,
[data-theme="dark"] .msg.mine .att-audio-card.is-voice {
    background: color-mix(in srgb, var(--card-bg) 82%, var(--msg-out-bg)) !important;
    border: 1px solid var(--card-border) !important;
    border-radius: 14px !important;
    box-shadow: var(--shadow-sm) !important;
    padding: 8px 10px 6px !important;
}

    [data-theme="dark"] .msg .att-audio-card.is-voice audio::-webkit-media-controls-panel,
    [data-theme="dark"] .msg.mine .att-audio-card.is-voice audio::-webkit-media-controls-panel {
        background-color: color-mix(in srgb, var(--card-bg) 82%, var(--msg-out-bg)) !important;
    }

/* === draft card must wrap only its own content === */
.record-draft {
    width: fit-content !important;
    max-width: min(420px, calc(100% - 32px)) !important;
    align-self: flex-start !important;
}

/* === center camera preview while recording video note === */
.record-camera-preview {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    background: transparent;
}

    .record-camera-preview.hidden {
        display: none !important;
    }

    .record-camera-preview video {
        width: min(54vw, 360px);
        aspect-ratio: 1 / 1;
        object-fit: cover;
        border-radius: 18px;
        border: 1px solid var(--card-border);
        box-shadow: var(--shadow-sm);
        background: #000;
    }

@media (max-width: 1180px) {
    .record-camera-preview video {
        width: min(72vw, 340px);
    }
}

/* === FINAL DOCK / PROFILE / AUDIO HOTFIX === */

.main {
    position: relative !important;
    overflow: hidden !important;
}

#messages {
    padding-bottom: calc(18px + var(--dock-total-h, 120px) + var(--keyboard-inset, 0px)) !important;
}

#pendingAtPreview,
.composer-options,
#composerMeta,
.chat-input {
    position: absolute !important;
    left: 16px !important;
    right: 16px !important;
    margin: 0 !important;
    z-index: 20 !important;
    background: transparent !important;
}

#recordDraft {
    position: absolute !important;
    left: 16px !important;
    right: auto !important;
    margin: 0 !important;
    width: fit-content !important;
    max-width: min(420px, calc(100% - 32px)) !important;
    z-index: 22 !important;
}

.composer-options {
    pointer-events: none !important;
}

#uploadBusy {
    pointer-events: auto !important;
}

.chat-input {
    position: absolute !important;
    display: grid !important;
    grid-template-columns: 36px 36px minmax(0, 1fr) 40px !important;
    grid-template-rows: auto !important;
    grid-template-areas: "attach record input send" !important;
    align-items: end !important;
    gap: 8px !important;
    padding: 26px 12px 12px !important;
    border: 1px solid var(--card-border) !important;
    border-radius: 18px !important;
    background: color-mix(in srgb, var(--pane-bg) 94%, transparent) !important;
    box-shadow: var(--shadow-sm) !important;
    overflow: visible !important;
}

    .chat-input > .composer-toggle {
        position: absolute !important;
        left: 12px !important;
        top: 6px !important;
        bottom: auto !important;
        transform: none !important;
        display: inline-flex !important;
        align-items: center !important;
        gap: 6px !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 4px 8px !important;
        border-radius: 999px !important;
        border: 1px solid var(--card-border) !important;
        background: var(--card-bg) !important;
        box-shadow: var(--shadow-sm) !important;
        font-size: 10.5px !important;
        line-height: 1 !important;
        white-space: nowrap !important;
        color: var(--text-muted) !important;
        z-index: 24 !important;
    }

    .chat-input > #btnSend.primary.send {
        transform: translateY(2px) !important;
    }

[data-theme="dark"] .att-audio-card.is-voice {
    padding: 10px 12px !important;
    border: 1px solid var(--card-border) !important;
    background: color-mix(in srgb, var(--card-bg) 74%, var(--msg-out-bg)) !important;
    border-radius: 16px !important;
    box-shadow: var(--shadow-sm) !important;
}

    [data-theme="dark"] .att-audio-card.is-voice .att-audio-title,
    [data-theme="dark"] .att-audio-card.is-voice .att-audio-sub {
        text-shadow: none !important;
        filter: none !important;
    }

    [data-theme="dark"] .att-audio-card.is-voice audio,
    [data-theme="dark"] .att-audio-card.is-voice .att-audio-player {
        background: transparent !important;
        color-scheme: dark !important;
        filter: none !important;
    }

        [data-theme="dark"] .att-audio-card.is-voice audio::-webkit-media-controls-panel,
        [data-theme="dark"] .att-audio-card.is-voice audio::-webkit-media-controls-enclosure {
            background: transparent !important;
        }

        [data-theme="dark"] .att-audio-card.is-voice audio::-webkit-media-controls-current-time-display,
        [data-theme="dark"] .att-audio-card.is-voice audio::-webkit-media-controls-time-remaining-display {
            color: var(--text-main) !important;
            text-shadow: none !important;
        }

#profilePanel .profile-card {
    display: grid !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
    max-height: min(88vh, 760px) !important;
    overflow: hidden !important;
}

#profilePanel .profile-body {
    min-height: 0 !important;
    overflow-y: auto !important;
}

#profilePanel.profile-self .profile-card {
    width: min(540px, calc(100vw - 28px)) !important;
    max-width: calc(100vw - 28px) !important;
}

#profilePanel.profile-self .profile-body {
    grid-template-columns: 1fr !important;
}

#profilePanel.profile-peer .profile-card {
    width: min(860px, calc(100vw - 28px)) !important;
    max-width: calc(100vw - 28px) !important;
}

#profilePanel.profile-peer .profile-body {
    grid-template-columns: minmax(0, 1fr) 280px !important;
}

#profilePanel .name-row {
    position: relative !important;
    padding-right: 52px !important;
}

    #profilePanel .name-row .p-more {
        position: absolute !important;
        top: 0 !important;
        right: 0 !important;
        margin-left: 0 !important;
        z-index: 30 !important;
    }

#profilePanel.profile-self .profile-featured__card,
#profilePanel.profile-self .profile-about,
#profilePanel.profile-self .profile-aside .card {
    max-width: none !important;
}

#profilePanel .profile-about,
#profilePanel .profile-aside .card,
#profilePanel .profile-featured__card {
    border-radius: 16px !important;
}

@media (max-width: 1180px) {
    #pendingAtPreview,
    .composer-options,
    #composerMeta,
    .chat-input {
        left: 10px !important;
        right: 10px !important;
    }

    #recordDraft {
        left: 10px !important;
        max-width: min(420px, calc(100% - 20px)) !important;
    }

    .chat-input {
        padding-top: 24px !important;
    }

        .chat-input > .composer-toggle {
            left: 10px !important;
            top: 5px !important;
        }

        .chat-input > #btnSend.primary.send {
            transform: translateY(1px) !important;
        }
}

.chat-input > #btnSend.primary.send {
    transform: translateY(3px) !important;
}

@media (max-width: 1180px) {
    .chat-input > #btnSend.primary.send {
        transform: translateY(2px) !important;
    }
}

#profilePanel.profile-self .profile-card {
    width: min(500px, calc(100vw - 28px)) !important;
    max-width: calc(100vw - 28px) !important;
}

#profilePanel.profile-self .profile-body {
    grid-template-columns: 1fr !important;
    padding: 18px 18px 20px !important;
    gap: 18px !important;
}

#profilePanel.profile-self .profile-featured__card,
#profilePanel.profile-self #profileAboutBox,
#profilePanel.profile-self .profile-secondary-card {
    width: 100% !important;
    max-width: none !important;
}

#profilePanel.profile-self .about-link-card,
#profilePanel.profile-self .profile-secondary-card,
#profilePanel.profile-self #profileAboutText,
#profilePanel.profile-self #profileAboutEditor {
    font-size: 15px !important;
}

#profilePanel.profile-self .p-ghost,
#profilePanel.profile-self .secondary,
#profilePanel.profile-self .profile-media-mode {
    min-height: 46px !important;
}

#profilePanel.profile-peer .profile-card {
    width: min(920px, calc(100vw - 28px)) !important;
    max-width: calc(100vw - 28px) !important;
    max-height: min(90vh, 820px) !important;
}

#profilePanel.profile-peer .profile-body {
    grid-template-columns: minmax(0, 1fr) 300px !important;
    padding: 18px 18px 20px !important;
    gap: 18px !important;
    align-items: start !important;
}

#profilePanel.profile-peer .profile-aside {
    width: 100% !important;
    max-width: 300px !important;
    align-self: start !important;
}

.profile-secondary-card--media {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
}

.profile-media-stats-title {
    font-weight: 700;
}

.profile-media-mode {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    background: var(--card-bg);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    font-weight: 700;
}

    .profile-media-mode:hover {
        background: var(--hover-bg);
    }

#profileAboutBox {
    width: 100%;
}

#profileAboutEditor {
    min-height: 132px;
}

#profileAboutCounter {
    font-size: 12px;
}

.chat-input {
    padding: 18px 12px 12px !important;
}

    .chat-input > .composer-toggle {
        left: 12px !important;
        top: 8px !important;
        bottom: auto !important;
        transform: none !important;
        min-width: 74px !important;
        max-width: 74px !important;
        padding: 3px 6px !important;
        font-size: 9.5px !important;
        line-height: 1 !important;
        border-radius: 9px !important;
        gap: 5px !important;
    }

        .chat-input > .composer-toggle span {
            white-space: nowrap !important;
        }

        .chat-input > .composer-toggle input {
            width: 13px !important;
            height: 13px !important;
        }

@media (max-width: 1180px) {
    .chat-input {
        padding: 16px 10px 10px !important;
    }

        .chat-input > .composer-toggle {
            left: 10px !important;
            top: 7px !important;
            min-width: 70px !important;
            max-width: 70px !important;
            padding: 3px 6px !important;
            font-size: 9px !important;
        }
}

.chat-input > .record-badge {
    left: 12px !important;
    right: auto !important;
    bottom: calc(100% + 3px) !important;
    transform: none !important;
    padding: 3px 7px !important;
    font-size: 10px !important;
    line-height: 1 !important;
    border-radius: 999px !important;
    z-index: 24 !important;
}

@media (max-width: 1180px) {
    .chat-input > .record-badge {
        left: 10px !important;
        bottom: calc(100% + 2px) !important;
        padding: 3px 6px !important;
        font-size: 9.5px !important;
    }
}

.media-panel__tabs {
    padding: 12px 16px 12px !important;
}

@media (max-width: 420px) {
    .media-panel__tabs {
        padding: 12px 12px 10px !important;
    }
}

.media-panel__audio {
    min-width: 0 !important;
    width: 100% !important;
    overflow: hidden !important;
}

    .media-panel__audio audio {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

.media-panel__body {
    overflow-x: hidden !important;
}

@media (max-width: 420px) {
    .media-panel__audio {
        padding: 10px 12px !important;
    }

    .media-panel__audio-title,
    .media-panel__audio-meta {
        min-width: 0 !important;
        overflow-wrap: anywhere !important;
    }
}

#profilePanel .name-row {
    position: relative !important;
    padding-right: 52px !important;
    align-items: flex-start !important;
}

    #profilePanel .name-row .p-more {
        position: absolute !important;
        top: 0 !important;
        right: 0 !important;
        margin-left: 0 !important;
        z-index: 30 !important;
    }

#profilePanel .profile-featured__head {
    padding-right: 0 !important;
}

:root[data-theme="dark"] .badge-panel-item {
    color: var(--text-main) !important;
}

:root[data-theme="dark"] .badge-panel-item__title {
    color: var(--text-main) !important;
}

.chat-input > .composer-toggle {
    top: 18px !important;
    bottom: auto !important;
}

@media (max-width: 1180px) {
    .chat-input > .composer-toggle {
        top: 11px !important;
        bottom: auto !important;
    }
}

#profilePanel .profile-card,
#profilePanel .profile-cover,
#profilePanel .p-reactions {
    overflow: visible !important;
}

#profilePanel .p-reactions,
#profilePanel .p-reaction {
    position: relative !important;
    z-index: 1201 !important;
    pointer-events: auto !important;
}

#profilePanel .p-emoji-editor {
    z-index: 1206 !important;
}

#profilePanel .profile-card {
    border-radius: 24px !important;
    overflow: hidden !important;
}

#profilePanel .profile-cover {
    position: relative !important;
    border-top-left-radius: 24px !important;
    border-top-right-radius: 24px !important;
    overflow: visible !important;
}

    #profilePanel #profileReactions,
    #profilePanel .profile-cover .p-reactions {
        position: absolute !important;
        top: 18px !important;
        right: 18px !important;
        left: auto !important;
        bottom: auto !important;
        margin: 0 !important;
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: flex-end !important;
        align-items: center !important;
        gap: 10px !important;
        max-width: calc(100% - 170px) !important;
        z-index: 1202 !important;
        pointer-events: auto !important;
    }

        #profilePanel #profileReactions .p-reaction,
        #profilePanel .profile-cover .p-reaction {
            position: relative !important;
            z-index: 1203 !important;
            pointer-events: auto !important;
        }

#profilePanel .p-emoji-editor {
    z-index: 1206 !important;
    pointer-events: auto !important;
}

@media (max-width: 420px) {
    #profilePanel .profile-card {
        border-radius: 18px !important;
    }

    #profilePanel .profile-cover {
        border-top-left-radius: 18px !important;
        border-top-right-radius: 18px !important;
    }

        #profilePanel #profileReactions,
        #profilePanel .profile-cover .p-reactions {
            top: 10px !important;
            right: 10px !important;
            gap: 4px !important;
            max-width: calc(100% - 132px) !important;
        }
}

#profilePanel .profile-cover {
    overflow: visible !important;
}

#profilePanel #profileReactions,
#profilePanel .p-reactions {
    z-index: 1300 !important;
    pointer-events: auto !important;
}

    #profilePanel #profileReactions .p-reaction,
    #profilePanel .p-reaction {
        position: relative !important;
        z-index: 1301 !important;
        pointer-events: auto !important;
    }

.emoji-picker {
    z-index: 5000 !important;
}

#profilePanel.profile-peer .profile-card {
    width: min(660px, calc(100vw - 28px)) !important;
    max-width: calc(100vw - 28px) !important;
}

#profilePanel.profile-peer .profile-body {
    grid-template-columns: minmax(0, 1fr) 230px !important;
    gap: 16px !important;
}

#profilePanel.profile-peer .profile-aside {
    width: 100% !important;
    max-width: 230px !important;
    align-self: stretch !important;
}

#profilePanel.profile-peer .profile-secondary-card--media {
    height: 100% !important;
}

@media (min-width: 768px) {
    #profilePanel .profile-body,
    #roomPanel .profile-body {
        grid-template-columns: minmax(0, 1fr) 260px !important;
        align-items: start !important;
    }

    #profilePanel .profile-aside,
    #roomPanel .profile-aside {
        display: flex;
        flex-direction: column;
        gap: 12px;
        align-self: start;
    }
}

.room-media-card,
#profilePanel .profile-aside .card {
    border-radius: 16px !important;
    box-shadow: var(--shadow-sm);
    background: color-mix(in srgb, var(--card-bg) 96%, transparent);
}

.room-media-card__title {
    font-weight: 700;
    margin-bottom: 8px;
}

.room-media-card__summary {
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.msg-text--emoji-only {
    font-size: clamp(32px, 2.6em, 56px);
    line-height: 1.1;
    letter-spacing: 0;
}

    .msg-text--emoji-only .msg-link {
        font-size: inherit;
    }

#readOnlyBanner.is-blocked {
    color: var(--btn-danger) !important;
    border-color: color-mix(in srgb, var(--btn-danger) 55%, var(--card-border)) !important;
}

@media (max-width: 767px) {
    #profilePanel.profile-peer .profile-card {
        width: min(680px, calc(100vw - 20px)) !important;
    }

    #profilePanel.profile-peer .profile-body {
        grid-template-columns: 1fr !important;
    }

    #profilePanel.profile-peer .profile-aside {
        max-width: none !important;
    }
}

@media (min-width: 768px) {
    #profilePanel.profile-peer .profile-card {
        width: min(860px, calc(100vw - 28px)) !important;
        max-width: calc(100vw - 28px) !important;
    }

    #profilePanel.profile-peer .profile-body {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 280px !important;
        gap: 18px !important;
        align-items: start !important;
    }

    #profilePanel.profile-peer .profile-main {
        min-width: 0 !important;
    }

    #profilePanel.profile-peer #profileAside,
    #profilePanel.profile-peer .profile-aside {
        grid-column: 2 !important;
        width: 100% !important;
        max-width: 280px !important;
        align-self: start !important;
        display: block !important;
    }

    #profilePanel.profile-peer .card.profile-secondary-card.profile-secondary-card--media {
        width: 100% !important;
        margin: 0 !important;
    }
}

@media (max-width: 767px) {
    #profilePanel.profile-peer .profile-body {
        grid-template-columns: 1fr !important;
    }

    #profilePanel.profile-peer #profileAside,
    #profilePanel.profile-peer .profile-aside {
        grid-column: auto !important;
        max-width: none !important;
    }
}

.main.chat-compose-disabled .chat-input {
    display: none !important;
}

.att-video-wrap,
.att-video-wrap--note {
    cursor: pointer;
}

.att-video {
    background: #000;
}

.room-e2ee-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

    .room-e2ee-toggle input {
        width: 16px;
        height: 16px;
        margin: 0;
    }

.room-e2ee-hint {
    margin-top: 8px;
    line-height: 1.35;
}

.chat-title-row .unread {
    margin-left: auto;
    flex: 0 0 auto;
    align-self: center;
}

.composer-meta {
    background: var(--card-bg) !important;
    border: 1px solid var(--card-border) !important;
    box-shadow: var(--shadow-sm) !important;
    opacity: 1 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

    .composer-meta .cm-title,
    .composer-meta .cm-text {
        color: var(--text-main) !important;
    }

    .composer-meta .cm-text {
        opacity: 0.92 !important;
    }


#composerMeta,
.composer-meta {
    background: var(--card-bg) !important;
    border: 1px solid var(--card-border) !important;
    box-shadow: var(--shadow-sm) !important;
    opacity: 1 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

    #composerMeta .cm-title,
    #composerMeta .cm-text,
    .composer-meta .cm-title,
    .composer-meta .cm-text {
        opacity: 1 !important;
    }

    #composerMeta .cm-title,
    .composer-meta .cm-title {
        color: var(--text-main) !important;
    }

    #composerMeta .cm-text,
    .composer-meta .cm-text {
        color: var(--text-muted) !important;
    }