:root {
    /* Фиолетовый — основной акцент */
    --primary: #a78bfa;
    --primary-hover: #b79cfb;
    --primary-light: rgba(167, 139, 250, 0.16);
    --on-primary: #1b1626;

    /* Золотой — акценты и собственные сообщения */
    --gold: #e8c36a;
    --gold-deep: #4a3d1e;
    --gold-border: #6b5a2a;
    --gold-text: #f6efd9;

    /* Тёмная база с фиолетовым оттенком */
    --bg: #16121f;
    --panel: #1f1a2a;
    --surface: #251f33;
    --chat-bg: #1b1626;

    /* Текст — светлый; серебро для вторичного */
    --text: #f0ecf7;
    --text-muted: #a39cb8;
    --secondary: #cdc7da;
    --muted: #8f89a6;

    --border: #3c354f;

    --danger: #f87171;
    --danger-light: #3a2327;

    --success: #22c55e;

    /* Скругления оставлены только для сообщений */
    --radius: 0;
    --card-radius: 0;

    --shadow-sm:
        0 1px 3px rgba(0, 0, 0, 0.35);

    --shadow:
        0 2px 8px rgba(0, 0, 0, 0.4);

    --shadow-lg:
        0 12px 32px rgba(0, 0, 0, 0.55);

    --font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        "Helvetica Neue",
        Arial,
        sans-serif;
}


/* =========================
   Base
========================= */

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100vh;
}

body {
    font-family: var(--font-family);
    color: var(--text);
    line-height: 1.5;

    background:
        radial-gradient(
            1100px 700px at 12% -5%,
            rgba(139, 92, 246, 0.18),
            transparent 60%
        ),
        radial-gradient(
            900px 650px at 100% 105%,
            rgba(232, 195, 106, 0.08),
            transparent 55%
        ),
        var(--bg);
}

button,
input,
textarea,
select {
    font-family: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}


/* =========================
   Main layout
========================= */

.chat-layout {
    width: 1100px;
    max-width: 95%;
    height: 85vh;

    margin: 5vh auto;

    display: flex;

    overflow: hidden;

    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--card-radius);

    box-shadow: var(--shadow-lg);
}


/* =========================
   Sidebar
========================= */

.rooms-sidebar {
    width: 260px;
    min-width: 260px;

    display: flex;
    flex-direction: column;

    background: var(--panel);

    border: none;
    border-right: 1px solid var(--border);

    border-radius: 0;

    box-shadow: none;

    overflow: hidden;

    transition:
        width 0.2s ease,
        min-width 0.2s ease;
}

.rooms-sidebar.collapsed {
    width: 72px;
    min-width: 72px;
}


/* =========================
   Sidebar header
========================= */

.rooms-header {
    height: 64px;
    min-height: 64px;

    flex-shrink: 0;

    display: flex;
    align-items: center;

    gap: 10px;

    padding: 16px;

    border-bottom: 1px solid var(--border);

    background: transparent;
}

.rooms-toggle-button {
    width: 32px;
    height: 32px;

    min-width: 32px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: 1px solid var(--border);
    border-radius: var(--radius);

    background: var(--surface);
    color: var(--text-muted);

    font-size: 16px;

    cursor: pointer;

    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease;
}

.rooms-toggle-button:hover {
    background: var(--bg);
    border-color: var(--primary);
    color: var(--primary);
}

.rooms-header-title {
    min-width: 0;

    color: var(--text);

    font-size: 16px;
    font-weight: 600;

    white-space: nowrap;
    overflow: hidden;

    transition:
        opacity 0.15s ease;
}

.rooms-search-input {
    flex: 1;

    min-width: 0;

    height: 32px;

    padding: 0 10px;

    border: 1px solid var(--border);
    border-radius: var(--radius);

    background: var(--surface);
    color: var(--text);

    font-family: inherit;
    font-size: 13px;

    outline: none;

    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.rooms-search-input::placeholder {
    color: var(--text-muted);
}

.rooms-search-input:focus {
    border-color: var(--primary);

    box-shadow:
        0 0 0 2px rgba(167, 139, 250, 0.28);
}

.rooms-search-input::-webkit-search-cancel-button {
    cursor: pointer;
}

.rooms-sidebar.collapsed .rooms-header {
    justify-content: center;
    padding: 16px 8px;
}

.rooms-sidebar.collapsed .rooms-header-title {
    display: none;
}

.rooms-sidebar.collapsed .rooms-search-input {
    display: none;
}


/* =========================
   Rooms list
========================= */

.rooms-list {
    flex: 1;

    padding: 12px;

    overflow-y: auto;
    overflow-x: hidden;
}

.room-link {
    width: 100%;

    display: flex;
    align-items: center;

    gap: 10px;

    justify-content: flex-start;

    padding: 8px 10px;
    margin-bottom: 4px;

    color: var(--text);

    text-decoration: none;

    border-radius: var(--radius);

    border-left: 3px solid transparent;

    font-size: 14px;
    font-weight: 500;

    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
}

.room-link[hidden] {
    display: none;
}

.room-link:hover {
    background: var(--bg);
    color: var(--primary);
}

.room-link.active {
    background: var(--primary-light);
    color: var(--primary);

    border-left-color: var(--primary);

    font-weight: 600;
}


/* =========================
   Room avatar
========================= */

.room-avatar {
    position: relative;

    width: 36px;
    height: 36px;

    min-width: 36px;

    display: flex;
    align-items: center;
    justify-content: center;

    /* Без overflow:visible значки индикации (unread/приватность),
       выступающие за круг, обрезались бы рамкой аватара. */
    overflow: visible;

    border-radius: 50%;

    background: #4a4360;
    color: var(--text-muted);

    font-size: 13px;
    font-weight: 600;
}

.room-avatar img {
    width: 100%;
    height: 100%;

    display: block;

    /* Картинку скругляет собственная обводка, а не overflow родителя. */
    border-radius: 50%;

    object-fit: cover;
}

.room-private-icon {
    position: absolute;

    right: -5px;
    bottom: -5px;

    width: 18px;
    height: 18px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 2px solid var(--panel);
    border-radius: 50%;

    background: var(--surface);
    color: var(--text-muted);

    font-size: 10px;
    line-height: 1;

    z-index: 2;
}

.room-unread {
    position: absolute;

    top: -6px;
    right: -6px;

    min-width: 18px;
    height: 18px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0 5px;

    border: 2px solid var(--panel);
    border-radius: 999px;

    background: var(--danger);
    color: white;

    font-size: 11px;
    font-weight: 700;
    line-height: 1;

    z-index: 3;

    pointer-events: none;
}

/* =========================
   Room name
========================= */

.room-name {
    flex: 1;
    min-width: 0;

    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;

    text-align: left;
}


/* =========================
   Collapsed sidebar
========================= */

.rooms-sidebar.collapsed .rooms-list {
    padding: 12px 8px;
}

.rooms-sidebar.collapsed .room-link {
    justify-content: center;

    padding: 8px;

    border-left: none;
}

.rooms-sidebar.collapsed .room-link.active {
    border-left: none;
}

.rooms-sidebar.collapsed .room-name {
    display: none;
}


/* =========================
   Empty rooms
========================= */

.rooms-empty {
    margin: 20px 10px;

    color: var(--text-muted);

    font-size: 13px;

    text-align: center;
}

.rooms-sidebar.collapsed .rooms-empty {
    display: none;
}


/* =========================
   Rooms sections (чаты / контакты)
========================= */

.rooms-section {
    margin-bottom: 10px;
}

.rooms-section-title {
    padding: 6px 10px 4px;

    font-size: 11px;
    font-weight: 700;

    letter-spacing: 0.6px;

    text-transform: uppercase;

    color: var(--text-muted);
}

.rooms-section-title[hidden] {
    display: none;
}

.rooms-sidebar.collapsed .rooms-section-title {
    display: none;
}


/* =========================
   Create room
========================= */

.create-room-button {
    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    gap: 8px;

    margin: 12px;

    padding: 10px;

    border: 1px solid var(--border);
    border-radius: var(--radius);

    background: var(--surface);
    color: var(--text);

    font-size: 13px;
    font-weight: 600;

    cursor: pointer;

    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease;
}

.create-room-button:hover {
    border-color: var(--primary);

    color: var(--primary);

    background: var(--primary-light);
}

.create-room-icon {
    font-size: 18px;
    line-height: 1;
}

.rooms-sidebar.collapsed .create-room-button {
    margin: 12px 8px;
    padding: 10px 0;
}

.rooms-sidebar.collapsed .create-room-text {
    display: none;
}


/* =========================
   Chat container
========================= */

.chat-container {
    position: relative;

    flex: 1;
    min-width: 0;

    display: flex;
    flex-direction: column;

    background: transparent;

    border: none;

    border-radius: 0;

    box-shadow: none;

    overflow: hidden;
}


/* =========================
   Chat header
========================= */

.chat-header {
    position: relative;

    flex-shrink: 0;

    border-bottom: 1px solid var(--border);

    background: var(--panel);
}

.online-users {
    position: relative;

    padding: 16px 20px;
}

.online-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;
}


/* =========================
   Chat title
========================= */

.chat-title {
    min-width: 0;

    display: flex;
    flex-direction: column;

    gap: 2px;
}

.chat-title h3 {
    margin: 0;

    color: var(--text);

    font-size: 16px;
    font-weight: 600;

    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-title > span {
    color: var(--text-muted);

    font-size: 12px;
    font-weight: 500;
}

#room-members-count,
#room-members-menu-count {
    color: var(--primary);
    font-weight: 600;
}


/* =========================
   Room title
========================= */

.room-title-button {
    min-width: 0;

    display: flex;
    align-items: center;

    gap: 8px;

    padding: 0;

    border: none;

    background: transparent;
    color: var(--text);

    font-family: inherit;

    cursor: pointer;
}

.room-title-button:hover {
    color: var(--primary);
}

.room-title-avatar {
    width: 30px;
    height: 30px;

    min-width: 30px;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    border-radius: 50%;

    background: #4a4360;
    color: var(--text-muted);

    font-size: 12px;
    font-weight: 600;
}

.room-title-avatar img {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}

.room-title-name {
    max-width: 260px;

    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 16px;
    font-weight: 600;
}

.room-title-arrow {
    flex-shrink: 0;

    color: var(--text-muted);

    font-size: 12px;

    transition:
        color 0.15s ease,
        transform 0.15s ease;
}

.room-title-button:hover .room-title-arrow {
    color: var(--primary);
}


/* =========================
   User menu
========================= */

.user-menu {
    position: relative;

    flex-shrink: 0;
}

.user-menu-button {
    width: 38px;
    min-width: 38px;
    height: 38px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: none;

    border-radius: var(--radius);

    background: transparent;
    color: var(--text-muted);

    cursor: pointer;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.user-menu-button:hover {
    background: var(--primary-light);

    color: var(--primary);
}

.user-menu-dropdown {
    position: absolute;

    top: calc(100% + 8px);
    right: 0;

    min-width: 260px;
    max-width: 320px;

    padding: 6px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius);

    box-shadow: var(--shadow-lg);

    z-index: 500;
}

.user-menu-dropdown.hidden {
    display: none;
}

.user-menu-item {
    width: 100%;

    display: block;

    padding: 8px 12px;

    border: none;
    border-radius: 0;

    background: transparent;
    color: var(--text);

    font-family: inherit;
    font-size: 13px;
    font-weight: 500;

    text-align: left;
    text-decoration: none;

    cursor: pointer;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

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

.user-menu-dropdown form {
    margin: 0;
}

.logout-item {
    color: var(--danger);
}

.logout-item:hover {
    background: var(--danger-light);
}


/* =========================
   Room menu
========================= */

.room-menu-dropdown {
    position: absolute;

    top: calc(100% + 8px);
    left: 20px;

    width: 340px;
    max-width: calc(100vw - 40px);

    padding: 8px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius);

    box-shadow: var(--shadow-lg);

    z-index: 400;
}

.room-menu-dropdown.hidden {
    display: none;
}

.room-menu-header {
    display: flex;
    align-items: center;

    gap: 12px;

    padding: 10px 8px 14px;

    border-bottom: 1px solid var(--border);
}

.room-menu-avatar {
    width: 42px;
    height: 42px;

    min-width: 42px;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    border-radius: 50%;

    background: #4a4360;
    color: var(--text-muted);

    font-size: 14px;
    font-weight: 600;
}

.room-menu-avatar img {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}

.room-menu-room-info {
    min-width: 0;

    display: flex;
    flex-direction: column;

    gap: 2px;
}

.room-menu-room-info strong {
    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 14px;
}

.room-menu-room-info span {
    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;

    color: var(--text-muted);

    font-size: 12px;
}


/* =========================
   Room members
========================= */

.room-members-section {
    padding: 6px 0;
}

.room-menu-title {
    display: flex;
    align-items: center;

    gap: 5px;

    padding: 8px 12px;

    color: var(--text-muted);

    font-size: 12px;
    font-weight: 600;

    text-transform: uppercase;

    letter-spacing: 0.04em;
}

.room-menu-title span {
    color: var(--primary);
}

.room-members-list {
    display: flex;
    flex-direction: column;

    gap: 2px;

    max-height: 260px;

    overflow-y: auto;
}

.room-member {
    min-width: 0;

    display: flex;
    align-items: center;

    gap: 8px;

    padding: 7px 8px;

    border-radius: 0;
}

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

.room-member-avatar {
    width: 28px;
    height: 28px;

    min-width: 28px;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    border-radius: 50%;

    background: #4a4360;
    color: var(--text-muted);

    font-size: 11px;
    font-weight: 600;
}

.room-member-avatar img {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}

.room-member-name {
    flex: 1;
    min-width: 0;

    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 13px;
    font-weight: 500;
}

.room-owner {
    flex-shrink: 0;

    color: var(--gold);

    font-size: 10px;
}


/* =========================
   Participant status
========================= */

.participant-status {
    width: 8px;
    height: 8px;

    min-width: 8px;

    flex-shrink: 0;

    border-radius: 50%;

    background: var(--danger);

    box-shadow:
        0 0 0 2px var(--surface);
}

.participant-status.online {
    background: var(--success);
}


/* =========================
   Remove member
========================= */

.remove-member-button {
    width: 24px;
    height: 24px;

    min-width: 24px;

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;

    padding: 0;

    border: none;
    border-radius: 0;

    background: transparent;
    color: var(--text-muted);

    font-size: 18px;
    line-height: 1;

    cursor: pointer;

    opacity: 0;

    transition:
        opacity 0.15s ease,
        background 0.15s ease,
        color 0.15s ease;
}

.room-member:hover .remove-member-button {
    opacity: 1;
}

.remove-member-button:hover {
    background: var(--danger-light);
    color: var(--danger);
}


/* =========================
   Menu divider
========================= */

.menu-divider {
    height: 1px;

    margin: 6px 0;

    background: var(--border);
}


/* =========================
   Leave room
========================= */

.leave-room-item {
    color: var(--danger);
}

.leave-room-item:hover {
    background: var(--danger-light);
}


/* =========================
   Messages
========================= */

.chat-log {
    flex: 1;
    min-height: 0;

    display: flex;
    flex-direction: column;

    gap: 16px;

    padding: 10px;

    overflow-y: auto;
    overflow-x: hidden;

    background: var(--chat-bg);
}

.message {
    display: flex;

    flex-direction: column;

    align-items: flex-start;

    animation:
        fadeIn 0.2s ease-out;
}

.message-highlighted {
    animation:
        message-highlight
        1.8s ease-out 1;
}

@keyframes message-highlight {

    0% {
        box-shadow:
            0 0 0 3px var(--primary);
    }

    70% {
        box-shadow:
            0 0 0 3px var(--primary);
    }

    100% {
        box-shadow:
            0 0 0 0 transparent;
    }
}

.message-hover-menu {
    position: absolute;

    top: -14px;
    right: auto;
    left: 12px;

    z-index: 10;

    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;

    gap: 2px;

    padding: 4px 6px;

    border: 1px solid var(--border);

    border-radius: 999px;

    background: var(--surface);

    box-shadow: var(--shadow-sm);

    animation:
        fadeIn 0.15s ease-out;
}

.message-hover-menu[hidden] {
    display: none;
}

.message-hover-menu .emoji-option {
    width: 30px;
    height: 30px;

    border-radius: 50%;

    font-size: 17px;

    transition:
        transform 0.15s ease,
        background 0.15s ease;
}

.message-hover-menu .emoji-option:hover {
    transform: scale(1.15);

    background: rgba(255, 255, 255, 0.08);
}

.message.own {
    align-items: flex-end;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    position: relative;

    max-width: 65%;

    padding: 12px 16px;

    border-radius: 12px;

    background: var(--surface);

    border: 1px solid var(--border);

    box-shadow: var(--shadow-sm);

    overflow-wrap: anywhere;
}

.message-content.has-reactions {
    padding-bottom: 30px;
}

.message.own .message-content {
    background: var(--gold-deep);

    border-color: var(--gold-border);

    color: var(--gold-text);

    border-bottom-right-radius: 4px;

    box-shadow: var(--shadow-sm);
}

.message:not(.own) .message-content {
    border-bottom-left-radius: 4px;
}

/* Видео-сообщение без подписи — только кружок, без пузыря. */
.message.video-only .message-content,
.message.video-only.own .message-content {
    max-width: 65%;

    padding: 0;

    border: none;

    background: none;

    box-shadow: none;

    border-radius: 0;
}

.message.video-only .video-attachment {
    margin-top: 4px;
}


/* =========================
   Reply quote box (внутри пузыря)
========================= */

.reply-quote {
    margin-bottom: 6px;
    padding: 8px 10px;

    border-left: 3px solid var(--primary);

    border-radius: 6px;

    background: #2e283f;

    min-width: 0;

    cursor: pointer;
}

.reply-quote-header {
    display: flex;
    align-items: center;

    gap: 6px;

    margin-bottom: 4px;
}

.reply-quote-name {
    font-size: 13px;
    font-weight: 700;

    color: var(--primary);
}

.reply-quote-thumb-wrap {
    display: inline-block;

    max-width: 100%;
}

.reply-quote-thumb {
    display: block;

    width: 140px;
    height: 90px;

    object-fit: cover;

    border-radius: 6px;

    margin-bottom: 4px;

    background: #000;
}

.reply-quote-attachment,
.reply-quote-text {
    font-size: 13px;

    color: var(--secondary);

    overflow-wrap: anywhere;

    white-space: pre-wrap;
}

.reply-quote-attachment {
    color: var(--primary);
}

.message.own .reply-quote {
    border-left-color: white;

    background: rgba(255, 255, 255, 0.18);
}

.message.own .reply-quote-name {
    color: white;
}

.message.own .reply-quote-attachment,
.message.own .reply-quote-text {
    color: white;
}


/* =========================
   Message header
========================= */

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 8px;

    margin-bottom: 6px;
}


/* =========================
   Message username
========================= */

.username {
    display: flex;
    align-items: center;

    gap: 8px;

    min-width: 0;

    font-size: 13px;
    font-weight: 600;
}

.message.own .username {
    color: rgba(255, 255, 255, 0.9);
}


/* =========================
   Message avatar
========================= */

.message-avatar {
    width: 24px;
    height: 24px;

    min-width: 24px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    border-radius: 50%;

    background: #4a4360;
    color: var(--text-muted);

    font-size: 11px;
    font-weight: 600;
}

.message.own .message-avatar {
    background: rgba(255, 255, 255, 0.2);

    color: white;
}

.message-avatar img {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}


/* =========================
   Message text
========================= */

.text {
    font-size: 14px;
    line-height: 1.5;

    overflow-wrap: anywhere;
}


/* =========================
   Message time
========================= */

.time {
    flex-shrink: 0;

    color: var(--text-muted);

    font-size: 11px;
    font-weight: 500;

    white-space: nowrap;
}

.message.own .time {
    color: rgba(255, 255, 255, 0.7);
}


/* =========================
   Message reactions (в теле сообщения)
========================= */

.message-reactions {
    position: absolute;

    bottom: -11px;

    left: 10px;

    z-index: 4;

    display: flex;
    align-items: center;

    flex-wrap: wrap;

    gap: 6px;

    padding: 2px 4px;

    max-width: calc(100% - 28px);
}

.reaction-chip {
    display: inline-flex;
    align-items: center;

    gap: 4px;

    padding: 2px 8px;

    border: 1px solid var(--border);

    border-radius: 999px;

    background: var(--surface);

    color: var(--text);

    font-size: 13px;
    line-height: 1.4;

    cursor: pointer;

    transition:
        border-color 0.15s ease,
        background 0.15s ease;
}

.reaction-chip:hover {
    border-color: var(--primary);
}

.reaction-chip.active {
    border-color: var(--primary);

    background: var(--primary-light);

    color: var(--primary);
}

.reaction-emoji {
    font-size: 14px;
}

.reaction-count {
    font-size: 12px;
    font-weight: 600;
}

.emoji-option {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 34px;
    height: 34px;

    padding: 0;

    border: none;

    border-radius: 0;

    background: transparent;

    font-size: 20px;

    cursor: pointer;

    transition: background 0.15s ease;
}

.emoji-option:hover {
    background: rgba(255, 255, 255, 0.08);
}

.message.own .reaction-chip {
    background: rgba(255, 255, 255, 0.12);

    border-color: rgba(255, 255, 255, 0.35);

    color: white;

    cursor: default;
}

.message.own .reaction-chip:hover {
    border-color: rgba(255, 255, 255, 0.35);
}

.message.own .reaction-chip.active {
    background: rgba(255, 255, 255, 0.28);

    border-color: white;
}

/* =========================
   Message attachments
========================= */

.message-attachment {
    margin-top: 8px;

    overflow: hidden;

    border-radius: 8px;

    background: rgba(255, 255, 255, 0.05);

    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Видео-сообщения выводятся КРУГОМ без рамок обёртки. */
.message-attachment.video-attachment,
.message.own .message-attachment.video-attachment {
    margin-top: 8px;

    overflow: visible;

    background: transparent;

    border: none;

    border-color: transparent;

    border-radius: 0;

    box-shadow: none;
}

.video-message {
    position: relative;

    width: min(260px, 70vw);
    height: min(260px, 70vw);

    display: block;

    overflow: hidden;

    border-radius: 50%;

    background: var(--bg);

    cursor: pointer;
}

.video-message video {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}

.video-message-play {
    position: absolute;

    inset: 0;

    margin: auto;

    width: 56px;
    height: 56px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: none;
    border-radius: 50%;

    background: rgba(8, 6, 14, 0.55);
    color: #ffffff;

    font-size: 24px;
    line-height: 1;

    cursor: pointer;

    transition:
        background 0.15s ease,
        transform 0.15s ease;
}

.video-message-play[hidden] {
    display: none;
}

.video-message-play:hover {
    background: rgba(8, 6, 14, 0.7);

    transform: scale(1.06);
}

.message-attachment img {
    display: block;

    width: 100%;
    max-width: 320px;
    max-height: 320px;

    object-fit: cover;

    border-radius: 8px;
}

.message-attachment video {
    display: block;

    width: 100%;
    max-width: 320px;
    max-height: 260px;

    border-radius: 8px;
}

.message-attachment audio {
    display: block;

    width: 250px;
    max-width: 100%;

    margin: 6px;
}

.message.own .message-attachment {
    background: rgba(255, 255, 255, 0.16);

    border-color: rgba(255, 255, 255, 0.22);
}

.message-attachment-link {
    display: flex;
    align-items: center;

    gap: 8px;

    padding: 10px 12px;

    color: var(--primary);

    font-size: 13px;
    font-weight: 600;

    text-decoration: none;
}

.message-attachment-link:hover {
    text-decoration: underline;
}

.attachment-download {
    display: inline-flex;
    align-items: center;

    gap: 6px;

    margin-top: 8px;
    margin-left: 8px;
    margin-bottom: 8px;

    padding: 6px 12px;

    border: 1px solid var(--border);

    border-radius: 0;

    background: var(--surface);

    color: var(--primary);

    font-size: 12px;
    font-weight: 600;

    text-decoration: none;

    transition:
        border-color 0.15s ease,
        background 0.15s ease;
}

.attachment-download:hover {
    border-color: var(--primary);

    background: var(--primary-light);
}

.attachment-media-wrap {
    position: relative;

    overflow: hidden;

    border-radius: 8px;
}

.attachment-download-icon {
    position: absolute;
    left: 8px;
    bottom: 8px;

    z-index: 2;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 32px;
    height: 32px;

    border-radius: 50%;

    background: rgba(0, 0, 0, 0.6);
    color: white;

    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.4);

    transition: background 0.15s ease;
}

.attachment-download-icon:hover {
    background: rgba(0, 0, 0, 0.85);
}

.message.own .attachment-download {
    background: rgba(255, 255, 255, 0.16);

    border-color: rgba(255, 255, 255, 0.25);

    color: white;
}

.message.own .attachment-download:hover {
    background: rgba(255, 255, 255, 0.28);

    border-color: rgba(255, 255, 255, 0.45);
}


/* =========================
   System message
========================= */

.system-message {
    align-self: center;

    margin: 8px 0;

    padding: 6px 12px;

    color: var(--text-muted);

    font-size: 12px;
    font-weight: 500;

    text-align: center;

    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: 20px;
}


/* =========================
   Chat input
========================= */

.chat-input {
    flex-shrink: 0;

    display: flex;
    align-items: center;

    gap: 0;

    padding: 5px 6px;

    border: 1px solid var(--border);

    border-radius: var(--radius);

    background: var(--surface);

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.chat-input:focus-within {
    border-color: var(--primary);

    box-shadow:
        0 0 0 3px rgba(167, 139, 250, 0.28);
}

.chat-message-field {
    flex: 1;
    min-width: 0;

    display: flex;
    flex-direction: column;
}

.chat-reply-preview {
    width: 100%;

    display: flex;
}

.chat-reply-preview[hidden] {
    display: none;
}

.reply-preview {
    display: flex;
    align-items: flex-start;

    gap: 8px;

    width: 100%;

    padding: 8px 12px 8px 10px;

    border-bottom: 1px solid var(--border);
    border-radius: 0;

    background: #2c2640;
}

.reply-preview-block {
    flex: 1;
    min-width: 0;
}

.reply-preview .reply-quote {
    margin-bottom: 0;
}

.reply-preview-label {
    display: block;

    margin-bottom: 4px;

    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
}

.reply-preview-close {
    flex-shrink: 0;

    width: 24px;
    height: 24px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    margin-top: 2px;

    border: none;
    border-radius: 50%;

    background: transparent;
    color: var(--muted);

    font-size: 14px;
    line-height: 1;

    cursor: pointer;

    transition:
        background 0.2s ease,
        color 0.2s ease;
}

.reply-preview-close:hover {
    background: #383349;
    color: var(--text);
}

.chat-input input[type="text"] {
    flex: 1;
    min-width: 0;

    padding: 8px 10px;

    border: none;

    background: transparent;
    color: var(--text);

    font-size: 15px;

    outline: none;
}

.chat-input input[type="text"]::placeholder {
    color: var(--text-muted);
}

.chat-input-button {
    width: 38px;
    min-width: 38px;
    height: 38px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: none;

    border-radius: var(--radius);

    cursor: pointer;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.chat-attach-button {
    background: transparent;

    color: var(--text-muted);
}

.chat-attach-button:hover:not(:disabled) {
    background: var(--primary-light);

    color: var(--primary);
}

.chat-attach-button:disabled {
    opacity: 0.5;

    cursor: not-allowed;
}

.chat-send-button {
    border: none;

    background: var(--primary);
    color: var(--on-primary);
}

.chat-send-button:hover:not(:disabled) {
    background: var(--primary-hover);
}

.chat-send-button:disabled {
    opacity: 0.6;

    cursor: not-allowed;
}


/* Панель выбора смайликов */
.chat-emoji-wrap {
    position: relative;
}

.chat-emoji-button {
    background: transparent;

    color: var(--text-muted);
}

.chat-emoji-button:hover:not(:disabled) {
    background: var(--primary-light);

    color: var(--primary);
}

.chat-emoji-button.active {
    background: var(--primary-light);

    color: var(--primary);
}

.chat-emoji-panel {
    position: absolute;

    right: 0;
    bottom: calc(100% + 10px);

    z-index: 1000;

    width: 300px;
    max-height: 280px;

    overflow-y: auto;
    overflow-x: hidden;

    padding: 8px 6px 10px;

    border: 1px solid var(--border);

    background: var(--surface);

    box-shadow: var(--shadow-lg);
}

.chat-emoji-panel[hidden] {
    display: none;
}

/* Тонкий и малозаметный скролл панели смайликов. */
.chat-emoji-panel::-webkit-scrollbar {
    width: 4px;
}

.chat-emoji-panel::-webkit-scrollbar-track {
    background: transparent;
}

.chat-emoji-panel::-webkit-scrollbar-thumb {
    background: rgba(60, 53, 79, 0.6);

    border-radius: 999px;
}

.chat-emoji-panel::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.chat-emoji-group-title {
    padding: 4px 8px;

    color: var(--text-muted);

    font-size: 11px;
    font-weight: 600;

    text-transform: uppercase;

    letter-spacing: 0.04em;
}

.chat-emoji-grid {
    display: grid;

    grid-template-columns: repeat(8, 34px);

    gap: 2px;

    padding: 2px 4px 8px;
}

.chat-emoji-item {
    width: 34px;
    height: 34px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: none;

    border-radius: 4px;

    background: transparent;

    font-size: 20px;
    line-height: 1;

    cursor: pointer;

    transition: background 0.12s ease;
}

.chat-emoji-item:hover {
    background: var(--primary-light);
}


/* Кнопка переключения отправки/записи должна прятаться
   через hidden-атрибут (иначе display:flex его перебивает). */
.chat-input-button[hidden] {
    display: none;
}

.chat-record-button {
    position: relative;

    background: transparent;

    color: var(--text-muted);

    touch-action: none;

    user-select: none;

    -webkit-user-select: none;
}

.chat-record-button:hover:not(:disabled) {
    background: var(--primary-light);

    color: var(--primary);
}

.chat-record-button:disabled {
    opacity: 0.5;

    cursor: not-allowed;
}

.chat-record-button.recording {
    background: var(--danger-light);

    color: var(--danger);
}

.chat-record-button.holding {
    background: var(--primary-light);

    color: var(--primary);
}

.chat-record-button.holding::before {
    content: "";

    position: absolute;

    inset: -5px;

    border: 2px solid var(--primary);

    animation:
        chat-hold-pulse 1.2s ease-out infinite;

    opacity: 0;

    pointer-events: none;
}

@keyframes chat-hold-pulse {
    0% {
        transform: scale(0.9);

        opacity: 0.7;
    }
    100% {
        transform: scale(1.4);

        opacity: 0;
    }
}

.chat-record-button.recording::before {
    content: "";

    position: absolute;

    inset: -5px;

    border: 2px solid var(--danger);

    animation:
        chat-record-pulse 1.2s ease-out infinite;

    opacity: 0;

    pointer-events: none;
}

@keyframes chat-record-pulse {
    0% {
        transform: scale(0.9);

        opacity: 0.7;
    }
    100% {
        transform: scale(1.4);

        opacity: 0;
    }
}

.chat-recording-bar {
    display: flex;
    align-items: center;

    gap: 8px;

    padding: 6px 10px;

    font-size: 13px;

    color: var(--text);
}

.chat-recording-bar[hidden] {
    display: none;
}

.chat-recording-dot {
    width: 10px;
    height: 10px;

    flex-shrink: 0;

    border-radius: 50%;

    background: var(--danger);

    animation:
        chat-record-dot 1s ease-in-out infinite;
}

@keyframes chat-record-dot {
    0%,
    100% {
        opacity: 1;

        transform: scale(1);
    }
    50% {
        opacity: 0.45;

        transform: scale(0.8);
    }
}

.chat-recording-time {
    color: var(--text);

    font-weight: 600;

    font-variant-numeric: tabular-nums;
}

.chat-recording-hint {
    color: var(--text-muted);

    white-space: nowrap;

    overflow: hidden;

    text-overflow: ellipsis;
}

/* Превью камеры при записи видео. */
.chat-recording-preview {
    width: 96px;
    height: 96px;

    flex-shrink: 0;

    display: block;

    overflow: hidden;

    border: 2px solid var(--danger);
    border-radius: 50%;

    background: var(--bg);
}

.chat-recording-preview[hidden] {
    display: none;
}

.chat-recording-preview video {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}

.chat-input.recording {
    border-color: var(--danger);
}


/* =========================
   Media upload panel
========================= */

.chat-upload-panel {
    flex-shrink: 0;

    padding: 12px 20px;

    border-top: 1px solid var(--border);

    background: var(--chat-bg);
}

.chat-upload-files {
    display: flex;
    flex-direction: column;

    gap: 6px;

    margin-bottom: 10px;
}

.upload-file {
    display: flex;
    align-items: center;

    gap: 8px;

    padding: 6px 10px;

    border: 1px solid var(--border);

    border-radius: 0;

    background: var(--surface);
}

.upload-file-name {
    flex: 1;
    min-width: 0;

    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;

    color: var(--text);

    font-size: 13px;
    font-weight: 500;
}

.upload-file-size {
    flex-shrink: 0;

    color: var(--text-muted);

    font-size: 12px;
}

.upload-file-status {
    width: 18px;
    min-width: 18px;
    height: 18px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    color: var(--text-muted);

    font-size: 12px;
    font-weight: 700;
}

.upload-file-status.spinner {
    border: 2px solid var(--border);

    border-top-color: var(--primary);

    border-radius: 50%;

    animation: upload-spin 0.8s linear infinite;
}

.upload-file-status.ok {
    color: #22c55e;
}

.upload-file-status.error {
    color: #ef4444;
}

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

.upload-file-remove {
    width: 22px;
    min-width: 22px;
    height: 22px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: none;

    border-radius: 0;

    background: transparent;

    color: var(--text-muted);

    font-size: 14px;
    line-height: 1;

    cursor: pointer;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.upload-file-remove:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);

    color: var(--text);
}

.upload-file-remove:disabled {
    opacity: 0.4;

    cursor: not-allowed;
}

.chat-upload-controls {
    display: flex;

    gap: 8px;
}

.chat-upload-caption {
    flex: 1;
    min-width: 0;

    padding: 10px 12px;

    border: 1px solid #4a4460;

    border-radius: var(--radius);

    background: var(--surface);
    color: var(--text);

    font-size: 14px;

    outline: none;

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.chat-upload-caption:focus {
    border-color: var(--primary);

    box-shadow:
        0 0 0 3px rgba(167, 139, 250, 0.28);
}

.chat-upload-caption::placeholder {
    color: var(--text-muted);
}

.chat-upload-send {
    flex-shrink: 0;

    padding: 10px 18px;

    border: none;

    border-radius: var(--radius);

    background: var(--primary);
    color: var(--on-primary);

    font-size: 14px;
    font-weight: 600;

    cursor: pointer;

    transition: background 0.15s ease;
}

.chat-upload-send:hover:not(:disabled) {
    background: var(--primary-hover);
}

.chat-upload-send:disabled {
    opacity: 0.6;

    cursor: not-allowed;
}

.chat-upload-cancel {
    flex-shrink: 0;

    padding: 10px 14px;

    border: 1px solid var(--border);

    border-radius: var(--radius);

    background: var(--surface);

    color: var(--text-muted);

    font-size: 14px;
    font-weight: 500;

    cursor: pointer;

    transition:
        border-color 0.15s ease,
        color 0.15s ease;
}

.chat-upload-cancel:hover:not(:disabled) {
    border-color: #4a4460;

    color: var(--text);
}

.chat-upload-cancel:disabled {
    opacity: 0.5;

    cursor: not-allowed;
}

.chat-upload-status {
    margin-top: 8px;

    color: var(--text-muted);

    font-size: 12px;
}


/* =========================
   Toast
========================= */

.chat-toast {
    position: fixed;
    left: 50%;
    bottom: 90px;

    transform: translate(-50%, 16px);

    z-index: 2000;

    max-width: calc(100vw - 32px);

    padding: 12px 18px;

    border-radius: 10px;

    background: #2a2440;
    color: white;

    font-size: 14px;
    font-weight: 500;

    box-shadow:
        0 12px 28px rgba(0, 0, 0, 0.5);

    opacity: 0;

    pointer-events: none;

    transition:
        opacity 0.25s ease,
        transform 0.25s ease;
}

.chat-toast.visible {
    opacity: 1;

    transform: translate(-50%, 0);
}

.chat-toast.ok {
    background: #22c55e;
}

.chat-toast.error {
    background: #ef4444;
}


/* =========================
   Join prompt
========================= */

.chat-join-prompt {
    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 16px;

    padding: 14px 20px;

    border-top: 1px solid var(--border);

    background: var(--panel);
}

.chat-join-message {
    min-width: 0;

    display: flex;
    flex-direction: column;

    gap: 2px;
}

.chat-join-message strong {
    color: var(--text);

    font-size: 13px;
    font-weight: 600;
}

.chat-join-message span {
    color: var(--text-muted);

    font-size: 12px;
}

.join-room-button {
    flex-shrink: 0;

    padding: 9px 16px;

    border: none;

    border-radius: var(--radius);

    background: var(--primary);
    color: var(--on-primary);

    font-size: 13px;
    font-weight: 600;

    cursor: pointer;

    transition:
        background 0.15s ease;
}

.join-room-button:hover {
    background: var(--primary-hover);
}

.join-room-button:active {
    transform: translateY(0);
}


/* =========================
   Modals
========================= */

.modal {
    position: fixed;

    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    background: rgba(8, 6, 14, 0.6);

    z-index: 1000;

    animation:
        fadeIn 0.2s ease-out;
}

.modal.hidden {
    display: none;
}

.modal-content {
    width: 400px;
    max-width: 100%;
    max-height: 90vh;

    overflow-y: auto;

    padding: 32px;

    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--card-radius);

    box-shadow: var(--shadow-lg);
}

.modal-header {
    margin-bottom: 24px;

    text-align: center;
}

.modal-header h2 {
    margin: 0 0 8px;

    color: var(--text);

    font-size: 20px;
    font-weight: 700;
}

.modal-header p {
    margin: 0;

    color: var(--text-muted);

    font-size: 14px;
}

.modal-content form {
    display: flex;
    flex-direction: column;

    gap: 16px;
}


/* =========================
   Form
========================= */

.form-group {
    display: flex;
    flex-direction: column;

    gap: 6px;
}

.form-group label {
    color: var(--text-muted);

    font-size: 13px;
    font-weight: 600;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;

    padding: 11px 12px;

    border: 1px solid #4a4460;

    border-radius: var(--radius);

    background: var(--surface);
    color: var(--text);

    font-size: 14px;

    outline: none;

    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.form-group input:hover,
.form-group textarea:hover,
.form-group select:hover {
    border-color: #5e5780;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary);

    box-shadow:
        0 0 0 3px rgba(167, 139, 250, 0.28);
}

.form-group textarea {
    min-height: 90px;

    resize: vertical;
}

.checkbox-group label {
    display: flex;
    flex-direction: row;
    align-items: center;

    gap: 8px;

    cursor: pointer;
}

.checkbox-group input {
    width: auto;

    margin: 0;

    accent-color: var(--primary);
}

.form-group select option {
    background: var(--surface);
    color: var(--text);
}


/* =========================
   Buttons
========================= */

.primary-button {
    width: 100%;

    margin-top: 8px;

    padding: 11px;

    border: none;

    border-radius: var(--radius);

    background: var(--primary);
    color: var(--on-primary);

    font-size: 14px;
    font-weight: 600;

    cursor: pointer;

    transition:
        background 0.15s ease;
}

.primary-button:hover:not(:disabled) {
    background: var(--primary-hover);
}

.primary-button:disabled {
    opacity: 0.6;

    cursor: not-allowed;
}

.confirm-delete-button {
    background: var(--danger);
}

.confirm-delete-button:hover:not(:disabled) {
    background: var(--danger);

    filter: brightness(1.15);
}

.modal-cancel-button {
    width: 100%;

    padding: 11px;

    border: 1px solid var(--border);

    border-radius: var(--radius);

    background: var(--surface);
    color: var(--text-muted);

    font-size: 14px;
    font-weight: 600;

    cursor: pointer;

    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
}

.modal-cancel-button:hover {
    background: var(--bg);

    color: var(--text);

    border-color: var(--text-muted);
}


/* =========================
   Modal footer
========================= */

.modal-footer {
    margin-top: 24px;

    color: var(--text-muted);

    font-size: 13px;

    text-align: center;
}

.link-button {
    padding: 0;

    border: none;

    background: none;

    color: var(--primary);

    font-size: 13px;
    font-weight: 600;

    cursor: pointer;
}

.link-button:hover {
    text-decoration: underline;
}


/* =========================
   Errors
========================= */

.form-error {
    min-height: 20px;

    padding: 8px;

    color: var(--danger);

    background: var(--danger-light);

    border: 1px solid #8f3b3b;

    border-radius: var(--radius);

    font-size: 13px;
    font-weight: 500;

    text-align: center;
}


/* =========================
   Room media (панель «Медиа»)
========================= */

.media-modal-content {
    width: 720px;
    max-width: 100%;
}

.media-tabs {
    display: flex;

    gap: 4px;

    margin-bottom: 14px;

    border-bottom: 1px solid var(--border);

    overflow-x: auto;
}

.media-tab {
    position: relative;

    display: inline-flex;
    align-items: center;

    gap: 6px;

    padding: 9px 14px;

    border: none;

    border-radius: 0;

    background: transparent;
    color: var(--text-muted);

    font-family: inherit;
    font-size: 13px;
    font-weight: 600;

    cursor: pointer;

    border-bottom: 2px solid transparent;

    transition:
        color 0.15s ease,
        border-color 0.15s ease;
}

.media-tab:hover {
    color: var(--text);
}

.media-tab.active {
    color: var(--primary);

    border-bottom-color: var(--primary);
}

.media-tab-count {
    font-size: 12px;

    color: var(--muted);
}

.media-tab.active .media-tab-count {
    color: var(--primary);
}

.media-gallery {
    max-height: 52vh;

    padding: 4px 2px 8px;

    overflow-y: auto;
}

.media-empty {
    padding: 44px 0;

    color: var(--text-muted);

    font-size: 13px;

    text-align: center;
}

.media-loading {
    padding: 30px 0;

    color: var(--text-muted);

    font-size: 13px;

    text-align: center;
}

/* Грид для фото и видео */

.media-grid {
    display: grid;

    grid-template-columns:
        repeat(auto-fill, minmax(150px, 1fr));

    gap: 8px;
}

.media-grid-item {
    position: relative;

    display: block;

    aspect-ratio: 1 / 1;

    overflow: hidden;

    background: #1d1829;

    border: 1px solid var(--border);

    text-decoration: none;

    transition: border-color 0.15s ease;
}

.media-grid-item img,
.media-grid-item video {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}

.media-grid-item:hover {
    border-color: var(--primary);
}

.media-tile-play {
    position: absolute;

    top: 50%;
    left: 50%;

    transform: translate(-50%, -50%);

    display: flex;
    align-items: center;
    justify-content: center;

    width: 40px;
    height: 40px;

    border-radius: 50%;

    background: rgba(0, 0, 0, 0.55);
    color: white;

    font-size: 14px;

    pointer-events: none;
}

.media-tile-overlay {
    position: absolute;

    left: 0;
    right: 0;
    bottom: 0;

    display: flex;
    flex-direction: column;

    gap: 2px;

    padding: 6px 8px;

    background: linear-gradient(
        transparent,
        rgba(0, 0, 0, 0.75)
    );

    color: white;

    font-size: 11px;

    pointer-events: none;
}

.media-tile-meta {
    font-weight: 600;
}

.media-tile-caption {
    max-width: 100%;

    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Список для документов и ссылок */

.media-list {
    display: flex;

    flex-direction: column;

    gap: 8px;
}

.media-list-item {
    display: flex;
    align-items: center;

    gap: 12px;

    padding: 10px 12px;

    border: 1px solid var(--border);

    background: var(--surface);
    color: var(--text);

    text-decoration: none;

    transition:
        border-color 0.15s ease,
        background 0.15s ease;
}

.media-list-item:hover {
    border-color: var(--primary);

    background: var(--primary-light);
}

.media-list-icon {
    width: 40px;
    min-width: 40px;
    height: 40px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--primary-light);
    color: var(--primary);

    font-size: 18px;
}

.media-list-body {
    flex: 1;
    min-width: 0;

    display: flex;
    flex-direction: column;

    gap: 2px;
}

.media-list-name {
    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 13px;
    font-weight: 600;
}

.media-list-meta {
    color: var(--text-muted);

    font-size: 12px;
}

.media-modal-close {
    margin-top: 18px;
}


/* =========================
   Old create room page
========================= */

.create-room-page {
    min-height: 100vh;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;
}

.create-room-page form p {
    display: flex;
    flex-direction: column;

    gap: 8px;

    margin-bottom: 16px;
}

.create-room-page input,
.create-room-page textarea,
.create-room-page select {
    width: 100%;

    padding: 10px 12px;

    box-sizing: border-box;
}

.create-room-page input[type="checkbox"] {
    width: auto;
}


/* =========================
   Scrollbars
========================= */

.rooms-list::-webkit-scrollbar,
.chat-log::-webkit-scrollbar,
.room-members-list::-webkit-scrollbar,
.modal-content::-webkit-scrollbar {
    width: 6px;
}

.rooms-list::-webkit-scrollbar-track,
.chat-log::-webkit-scrollbar-track,
.room-members-list::-webkit-scrollbar-track,
.modal-content::-webkit-scrollbar-track {
    background: transparent;
}

.rooms-list::-webkit-scrollbar-thumb,
.chat-log::-webkit-scrollbar-thumb,
.room-members-list::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb {
    background: var(--border);

    border-radius: 999px;
}

.rooms-list::-webkit-scrollbar-thumb:hover,
.chat-log::-webkit-scrollbar-thumb:hover,
.room-members-list::-webkit-scrollbar-thumb:hover,
.modal-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}


/* =========================
   Mobile
========================= */

@media (max-width: 768px) {

    .chat-layout {
        width: 100%;
        max-width: none;

        height: 100vh;
        height: 100dvh;

        margin: 0;

        border-radius: 0;
    }

    .rooms-sidebar {
        width: 64px;
        min-width: 64px;

        border-radius: 0;

        border-right: 1px solid var(--border);
    }

    .rooms-sidebar:not(.collapsed) {
        width: 220px;
        min-width: 220px;
    }

    .rooms-sidebar.collapsed {
        width: 64px;
        min-width: 64px;
    }

    .rooms-header {
        height: 64px;
        min-height: 64px;

        padding: 16px 8px;
    }

    .rooms-list {
        padding: 8px;
    }

    .room-link {
        justify-content: center;

        padding: 8px;

        border-left: none;
    }

    .room-link.active {
        border-left: none;

        border-bottom: 3px solid var(--primary);
    }

    .rooms-sidebar.collapsed .room-link.active {
        border-bottom: none;
    }

    .room-name {
        display: block;
    }

    .rooms-sidebar.collapsed .room-name {
        display: none;
    }

    .create-room-button {
        margin: 8px;

        padding: 10px 8px;
    }

    .rooms-sidebar.collapsed .create-room-text {
        display: none;
    }

    .chat-container {
        width: auto;
        height: 100vh;

        border-radius: 0;

        border-left: none;
    }

    .chat-log {
        padding: 16px;
    }

    .message-content {
        max-width: 85%;
    }

    .online-users {
        padding: 12px 14px;
    }

    .online-header {
        gap: 8px;
    }

    .room-title-name {
        max-width: 160px;
    }

    .room-menu-dropdown {
        left: 8px;

        width: 340px;
        max-width: calc(100vw - 16px);
    }

    .user-menu-dropdown {
        right: -4px;

        max-width: calc(100vw - 80px);
    }

    .chat-input {
        padding:
            calc(12px + env(safe-area-inset-top, 0px))
            calc(16px + env(safe-area-inset-right, 0px))
            calc(12px + env(safe-area-inset-bottom, 0px))
            calc(16px + env(safe-area-inset-left, 0px));

        gap: 8px;
    }

    .chat-join-prompt {
        padding: 12px 16px;
    }

    .modal {
        padding: 12px;
    }

    .modal-content {
        width: 400px;
        max-width: 100%;

        padding: 24px;
    }
}


/* =========================
   Small mobile
========================= */

@media (max-width: 480px) {

    .rooms-sidebar:not(.collapsed) {
        width: 190px;
        min-width: 190px;
    }

    .online-users {
        padding: 10px 10px;
    }

    .room-title-button {
        gap: 6px;
    }

    .room-title-avatar {
        width: 26px;
        height: 26px;

        min-width: 26px;

        font-size: 11px;
    }

    .room-title-name {
        max-width: 110px;

        font-size: 14px;
    }

    .chat-title > span {
        font-size: 11px;
    }

    .header-right {
        gap: 4px;
    }

    .user-menu-button {
        width: 34px;
        min-width: 34px;
        height: 34px;
    }

    .chat-selection-count {
        min-width: 22px;

        padding: 2px 6px;

        font-size: 12px;
    }

    .chat-selection-button {
        width: 28px;
        min-width: 28px;
        height: 28px;
    }

    .chat-selection-button svg {
        width: 16px;
        height: 16px;
    }

    .chat-emoji-panel {
        width: 300px;
        max-width: calc(100vw - 24px);
    }

    .room-menu-dropdown {
        left: auto;
        right: 12px;

        width: 340px;
        max-width: calc(100vw - 24px);
    }

    .message-content {
        max-width: 90%;
    }

    .chat-input-button {
        width: 40px;
        min-width: 40px;
        height: 40px;
    }

    .chat-recording-preview {
        width: 80px;
        height: 80px;
    }

    .video-message {
        width: min(220px, 62vw);
        height: min(220px, 62vw);
    }

    .chat-join-prompt {
        align-items: stretch;
        flex-direction: column;
    }

    .join-room-button {
        width: 100%;
    }

    .modal-content {
        padding: 20px;
    }

    .chat-upload-panel {
        padding: 12px 16px;
    }

    .chat-upload-controls {
        flex-wrap: wrap;
    }

    .chat-upload-caption {
        min-width: 100%;
    }

    .chat-upload-send,
    .chat-upload-cancel {
        flex: 1;
    }

    .chat-toast {
        bottom: 120px;

        font-size: 13px;
    }
}


/* =========================
   Small phones
========================= */

@media (max-width: 400px) {

    .rooms-sidebar:not(.collapsed) {
        width: 160px;
        min-width: 160px;
    }

    .room-title-name {
        max-width: 84px;
    }

    .room-title-arrow {
        display: none;
    }

    .chat-selection-button {
        width: 26px;
        min-width: 26px;
        height: 26px;
    }

    .chat-input-button {
        width: 36px;
        min-width: 36px;
        height: 36px;
    }

    .chat-recording-preview {
        width: 68px;
        height: 68px;
    }

    .chat-recording-hint {
        display: none;
    }
}


/* =========================
   Message context menu
========================= */

.message-context-menu {
    position: fixed;

    z-index: 2000;

    display: flex;
    flex-direction: column;

    min-width: 200px;

    padding: 6px;

    border: 1px solid var(--border);

    border-radius: 12px;

    background: var(--surface);

    box-shadow: var(--shadow-lg);

    animation: fadeIn 0.12s ease-out;
}

.message-context-menu[hidden] {
    display: none;
}

.context-menu-btn {
    display: inline-flex;
    align-items: center;

    gap: 10px;

    padding: 9px 12px;

    border: none;
    border-radius: 8px;

    background: transparent;

    color: var(--text);

    font-size: 14px;
    line-height: 1;

    text-align: left;

    cursor: pointer;

    white-space: nowrap;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

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

.context-menu-btn[data-action-id="delete"] {
    color: var(--danger);
}

.context-menu-icon {
    width: 18px;

    font-size: 15px;
    line-height: 1;

    text-align: center;

    flex-shrink: 0;
}


/* =========================
   Selection mode
========================= */

.chat-log.selection-mode .message {
    cursor: pointer;

    user-select: none;
}

.message.selected {
    background: var(--primary-light);
}

.chat-log.selection-mode .message .message-hover-menu {
    display: none;
}

.header-right {
    display: flex;
    align-items: center;

    gap: 8px;

    margin-left: auto;
}

.chat-selection-bar {
    display: flex;
    align-items: center;

    gap: 4px;
}

.chat-selection-bar[hidden] {
    display: none;
}

.chat-selection-count {
    min-width: 28px;

    padding: 2px 8px;

    border-radius: 999px;

    background: var(--primary-light);

    color: var(--primary);

    font-size: 13px;
    font-weight: 600;

    text-align: center;
}

.chat-selection-button {
    width: 32px;
    min-width: 32px;
    height: 32px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: none;

    border-radius: var(--radius);

    background: transparent;
    color: var(--text-muted);

    cursor: pointer;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.chat-selection-button:hover {
    background: var(--primary-light);

    color: var(--primary);
}

.chat-selection-button[hidden] {
    display: none;
}

.chat-selection-delete {
    color: var(--danger);
}

.chat-selection-delete:hover {
    background: var(--danger-light);

    color: var(--danger);
}

.chat-selection-cancel {
    color: var(--text-muted);
}

.chat-selection-cancel:hover {
    background: var(--danger-light);

    color: var(--danger);
}


/* =========================
   Message edited marker
========================= */

.message-edited {
    color: var(--muted);

    font-size: 11px;
    line-height: 1;

    white-space: nowrap;
}


/* =========================
   Inline message edit
========================= */

.message-edit-wrap {
    display: flex;
    flex-direction: column;

    gap: 8px;
}

.message-edit-input {
    width: 100%;

    padding: 7px 10px;

    border: 1px solid var(--primary);
    border-radius: 8px;

    background: var(--panel);

    color: var(--text);

    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.4;

    outline: none;
}

.message-edit-actions {
    display: flex;

    gap: 8px;
}

.message-edit-save,
.message-edit-cancel {
    padding: 5px 12px;

    border: none;
    border-radius: 8px;

    font-size: 13px;
    line-height: 1;

    cursor: pointer;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.message-edit-save {
    background: var(--primary);

    color: var(--on-primary);
}

.message-edit-save:hover {
    background: var(--primary-hover);
}

.message-edit-cancel {
    background: var(--surface);

    color: var(--text-muted);
}

.message-edit-cancel:hover {
    color: var(--text);
}
