:root {
    --bg: #0e1621;
    --bg-2: #111b26;
    --panel: rgba(23, 33, 43, 0.96);
    --panel-2: rgba(18, 27, 36, 0.98);
    --line: rgba(255, 255, 255, 0.08);
    --text: #e6edf3;
    --muted: #8da1b5;
    --accent: #2b5278;
    --accent-2: #3a6d9c;
    --incoming: #182533;
    --danger: #ef4444;
    --success: #10b981;
    --glass: rgba(23, 33, 43, 0.96);
    --input: #17212b;
    --scroll: rgba(255, 255, 255, 0.16);
    --shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
}

html[data-theme="light"] {
    --bg: #dfe8f1;
    --bg-2: #edf3f9;
    --panel: rgba(255, 255, 255, 0.95);
    --panel-2: rgba(247, 250, 253, 0.98);
    --line: rgba(15, 23, 42, 0.08);
    --text: #102030;
    --muted: #61778d;
    --accent: #4f91d1;
    --accent-2: #3d7dbd;
    --incoming: #ffffff;
    --glass: rgba(255, 255, 255, 0.95);
    --input: #f5f8fc;
    --scroll: rgba(15, 23, 42, 0.18);
    --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(64, 112, 155, 0.16), transparent 22%),
        linear-gradient(180deg, var(--bg), var(--bg-2));
}

body.viewer-open,
body.sidebar-open { overflow: hidden; }

.page {
    min-height: 100vh;
    padding: 14px;
}

.page.chat-page {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
}

.glass {
    background: var(--glass);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.hidden { display: none !important; }
.mobile-only { display: none !important; }

button, input, textarea {
    font: inherit;
}

.primary-btn,
.ghost-btn,
.icon-btn,
.theme-toggle,
.room-item,
.toggle-switch,
.history-loader-btn,
.jump-latest,
.attachment-btn,
.tab-btn,
.picker-item,
.msg-menu-trigger {
    border: 0;
    outline: 0;
    cursor: pointer;
    transition: 0.18s ease;
}

.primary-btn:hover,
.ghost-btn:hover,
.icon-btn:hover,
.theme-toggle:hover,
.room-item:hover,
.toggle-switch:hover,
.history-loader-btn:hover,
.jump-latest:hover,
.attachment-btn:hover,
.tab-btn:hover,
.picker-item:hover,
.msg-menu-trigger:hover {
    transform: translateY(-1px);
}

.primary-btn {
    padding: 10px 16px;
    border-radius: 12px;
    color: #fff;
    font-weight: 700;
    background: var(--accent);
}

.primary-btn.compact { min-width: 86px; }

.ghost-btn {
    padding: 10px 16px;
    border-radius: 12px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
}

.danger-btn {
    background: rgba(239, 68, 68, 0.16);
    color: #fff;
}

.full-width { width: 100%; }

.icon-btn,
.theme-toggle {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    flex-shrink: 0;
}

.icon-btn.small {
    width: 34px;
    height: 34px;
}

.auth-wrap {
    min-height: calc(100vh - 28px);
    display: grid;
    place-items: center;
}

.auth-card {
    width: min(100%, 440px);
    border-radius: 22px;
    padding: 26px;
}

.brand-block { margin-bottom: 22px; }
.brand-block h1 {
    margin: 12px 0 8px;
    font-size: 2rem;
}
.brand-block p {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
}

.brand-badge {
    width: 52px;
    height: 52px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    color: #fff;
    background: var(--accent);
}

.brand-badge.small {
    width: 38px;
    height: 38px;
    border-radius: 12px;
}

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

.field { display: grid; gap: 8px; }

.field span {
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
}

.field input,
.room-search-input {
    width: 100%;
    height: 46px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--input);
    color: var(--text);
    outline: none;
}

.field input:focus,
.room-search-input:focus,
.composer textarea:focus {
    border-color: rgba(82, 156, 225, 0.55);
    box-shadow: 0 0 0 3px rgba(82, 156, 225, 0.12);
}

.auth-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.status-box {
    min-height: 20px;
    color: var(--muted);
    font-size: 0.94rem;
}

.status-box.success { color: var(--success); }
.status-box.error { color: #ff8b8b; }

.app-shell {
    width: min(100%, 1400px);
    height: 100%;
    min-height: 0;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 12px;
}

.sidebar,
.chat-panel,
.room-list,
.messages {
    min-width: 0;
    min-height: 0;
}

.sidebar,
.chat-panel {
    height: 100%;
    border-radius: 18px;
}

.sidebar {
    padding: 14px;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    overflow: hidden;
}

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

.sidebar-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-inline {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-inline strong {
    display: block;
    font-size: 0.98rem;
}

.brand-inline small {
    color: var(--muted);
    font-size: 0.82rem;
}

.sidebar-controls {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.room-list {
    display: grid;
    gap: 6px;
    overflow: auto;
    padding-right: 4px;
    margin-top: 12px;
}

.room-item {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    background: transparent;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    color: var(--text);
}

.room-item.active {
    background: rgba(43, 82, 120, 0.24);
    border-color: rgba(43, 82, 120, 0.36);
}

.room-avatar {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    font-weight: 800;
    color: #fff;
    background: var(--accent);
}

.room-copy {
    display: grid;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.room-copy strong,
.room-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-copy small {
    color: var(--muted);
    font-size: 0.8rem;
}

.room-unread {
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #4aa3ff;
    color: #fff;
    font-size: 0.76rem;
    font-weight: 700;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    display: grid;
    gap: 8px;
}

.chat-panel {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    overflow: hidden;
    position: relative;
    background:
        radial-gradient(circle at center, rgba(40, 77, 110, 0.12), transparent 42%),
        var(--panel);
}

.chat-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-shrink: 0;
}

.chat-header-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-header h1 {
    margin: 0 0 3px;
    font-size: 1.05rem;
}

.chat-header p {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.messages {
    padding: 14px 18px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-anchor: none;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.history-loader-row {
    display: flex;
    justify-content: center;
    padding: 2px 0 6px;
}

.history-loader-btn {
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border: 1px solid var(--line);
    font-size: 0.8rem;
    font-weight: 700;
}

.unread-divider {
    display: flex;
    justify-content: center;
    padding: 8px 0 6px;
}

.unread-divider span {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(74, 163, 255, 0.16);
    color: #7fc2ff;
    border: 1px solid rgba(74, 163, 255, 0.22);
    font-size: 0.76rem;
    font-weight: 700;
}

.empty-state,
.empty-prompt {
    color: var(--muted);
    font-size: 0.92rem;
}

.empty-state {
    padding: 0 18px 12px;
}

.jump-latest {
    position: absolute;
    right: 18px;
    bottom: 112px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
    z-index: 5;
}

.message-row {
    display: flex;
    width: 100%;
}

.message-row.incoming { justify-content: flex-start; }
.message-row.mine { justify-content: flex-end; }

.bubble {
    width: auto;
    max-width: min(78%, 720px);
    padding: 8px 10px;
    border-radius: 18px 18px 18px 8px;
    border: 1px solid var(--line);
    background: var(--incoming);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    position: relative;
}

.message-row.mine .bubble {
    background: var(--accent);
    border-color: rgba(255, 255, 255, 0.08);
    border-radius: 18px 18px 8px 18px;
}

.bubble-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.message-sender {
    font-size: 0.84rem;
    font-weight: 800;
    color: #7fc2ff;
}

.message-time,
.message-edited {
    font-size: 0.74rem;
    opacity: 0.82;
}

.message-text {
    font-size: 0.95rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-deleted {
    font-size: 0.9rem;
    font-style: italic;
    color: var(--muted);
}

.forward-badge {
    display: grid;
    gap: 2px;
    margin: 4px 0 8px;
    padding: 7px 9px;
    border-left: 3px solid rgba(127, 194, 255, 0.7);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
}

.forward-badge strong {
    font-size: 0.78rem;
}

.forward-badge span {
    font-size: 0.78rem;
    color: var(--muted);
}

.reply-preview {
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border-radius: 10px;
    margin-bottom: 7px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: inherit;
}

.reply-preview strong {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.reply-preview span {
    display: block;
    font-size: 0.84rem;
    opacity: 0.88;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-menu {
    position: relative;
    flex-shrink: 0;
}

.msg-menu-trigger {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: inherit;
}

.msg-menu-dropdown {
    position: absolute;
    top: 34px;
    right: 0;
    min-width: 126px;
    display: none;
    padding: 6px;
    border-radius: 12px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    z-index: 20;
}

.msg-menu.open .msg-menu-dropdown {
    display: grid;
    gap: 4px;
}

.msg-menu-dropdown button {
    padding: 8px 10px;
    border-radius: 9px;
    color: var(--text);
    background: transparent;
    border: 0;
    text-align: left;
}

.msg-menu-dropdown button:hover {
    background: rgba(255, 255, 255, 0.06);
}

.attachment-card {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
    padding: 9px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
    flex-wrap: wrap;
}

.attachment-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    font-size: 1rem;
    flex-shrink: 0;
}

.attachment-meta {
    flex: 1;
    min-width: 0;
    display: grid;
    gap: 2px;
}

.attachment-meta strong {
    font-size: 0.88rem;
    font-weight: 800;
}

.attachment-meta span {
    font-size: 0.78rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.attachment-btn {
    padding: 7px 11px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.8rem;
    font-weight: 700;
}

.message-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 7px;
    flex-wrap: wrap;
}

.reply-bar {
    margin: 0 18px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.reply-label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 3px;
}

.reply-text {
    font-size: 0.9rem;
    line-height: 1.4;
    word-break: break-word;
}

.composer-wrap {
    padding: 12px 18px 16px;
    flex-shrink: 0;
}

.composer {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    gap: 10px;
    align-items: flex-end;
}

.composer textarea {
    width: 100%;
    min-height: 48px;
    max-height: none;
    resize: none;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--input);
    color: var(--text);
    outline: none;
    line-height: 1.5;
    overflow-y: hidden;
    scrollbar-width: none;
}

.composer textarea::-webkit-scrollbar { display: none; }

.composer-hint {
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.8rem;
}

.composer-hint.error { color: #ff8b8b; }

.recording {
    animation: pulse 1s infinite ease-in-out;
    background: rgba(239, 68, 68, 0.22);
}

.composer-wrap.is-locked {
    opacity: 0.65;
}

.composer-disabled {
    pointer-events: none;
}

.composer textarea:disabled,
.icon-btn:disabled,
.primary-btn:disabled,
input:disabled {
    cursor: not-allowed;
}

.no-room-panel {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    justify-content: center;
}

.no-room-card {
    padding: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
}

.no-room-card h3 {
    margin: 0 0 8px;
    font-size: 1rem;
}

.no-room-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.no-room-actions {
    margin-top: 14px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.quick-section-head {
    margin-bottom: 10px;
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.quick-user-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-user-chip {
    padding: 9px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5, 10, 18, 0.58);
}

.modal-dialog {
    position: relative;
    width: min(94vw, 520px);
    max-height: 86vh;
    margin: 6vh auto;
    padding: 16px;
    border-radius: 18px;
    display: grid;
    gap: 12px;
    overflow: hidden;
    background: var(--panel);
}

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

.modal-tabs {
    display: flex;
    gap: 8px;
}

.tab-btn {
    padding: 9px 12px;
    border-radius: 10px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
}

.tab-btn.active {
    background: var(--accent);
    color: #fff;
}

.tab-panel {
    display: none;
    gap: 10px;
}

.tab-panel.active {
    display: grid;
}

.picker-list {
    max-height: 320px;
    overflow: auto;
    display: grid;
    gap: 6px;
    padding-right: 4px;
}

.picker-item {
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
}

.picker-item.selected {
    background: rgba(43, 82, 120, 0.24);
    border-color: rgba(43, 82, 120, 0.36);
}

.picker-item strong {
    display: block;
    font-size: 0.92rem;
}

.picker-item span {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
}

.picker-item.static {
    cursor: default;
}

.selection-info,
.admin-note {
    font-size: 0.82rem;
    color: var(--muted);
}

.mini-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.room-info-grid {
    display: grid;
    gap: 12px;
}

.room-info-grid div {
    display: grid;
    gap: 4px;
}

.room-info-grid strong {
    font-size: 0.82rem;
    color: var(--muted);
}

.media-viewer {
    position: fixed;
    inset: 0;
    z-index: 120;
}

.media-viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 10, 16, 0.72);
}

.media-viewer-dialog {
    position: relative;
    width: min(92vw, 920px);
    max-height: 88vh;
    margin: 5vh auto;
    border-radius: 20px;
    padding: 14px;
    display: grid;
    gap: 14px;
    overflow: hidden;
    background: var(--panel);
}

.media-viewer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.media-viewer-copy {
    display: grid;
    gap: 5px;
    min-width: 0;
}

.media-viewer-copy strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-viewer-copy span {
    color: var(--muted);
    font-size: 0.84rem;
}

.media-viewer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.media-viewer-body {
    min-height: 180px;
    max-height: calc(88vh - 95px);
    overflow: auto;
    display: grid;
    place-items: center;
}

.viewer-image,
.viewer-video {
    display: block;
    max-width: 100%;
    max-height: calc(88vh - 160px);
    border-radius: 14px;
}

.viewer-audio {
    width: min(100%, 560px);
}

.viewer-file-fallback {
    width: 100%;
    max-width: 440px;
    padding: 24px;
    text-align: center;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
}

.viewer-file-icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.mobile-backdrop {
    display: none;
}

.messages::-webkit-scrollbar,
.room-list::-webkit-scrollbar,
.picker-list::-webkit-scrollbar,
.media-viewer-body::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

.messages::-webkit-scrollbar-thumb,
.room-list::-webkit-scrollbar-thumb,
.picker-list::-webkit-scrollbar-thumb,
.media-viewer-body::-webkit-scrollbar-thumb {
    background: var(--scroll);
    border-radius: 999px;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

@media (max-width: 920px) {
    .page { padding: 10px; }

    .app-shell {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .mobile-only { display: inline-flex !important; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 330px);
        max-width: 330px;
        min-height: 100dvh;
        padding: 14px;
        border-radius: 0 16px 16px 0;
        z-index: 60;
        transform: translateX(-110%);
        transition: transform 0.25s ease;
    }

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

    .mobile-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(4, 10, 20, 0.48);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
        z-index: 50;
    }

    body.sidebar-open .mobile-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .jump-latest {
        right: 14px;
        bottom: 104px;
    }

    .composer-wrap {
        position: sticky;
        bottom: 0;
        background: linear-gradient(to top, var(--panel), rgba(0, 0, 0, 0));
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }
}

@media (max-width: 640px) {
    .auth-card,
    .chat-panel {
        border-radius: 16px;
    }

    .auth-actions {
        grid-template-columns: 1fr;
    }

    .sidebar {
        width: min(90vw, 320px);
        border-radius: 0 16px 16px 0;
    }

    .brand-inline small { display: none; }

    .chat-header {
        padding: 12px 14px;
    }

    .chat-header h1 {
        font-size: 1rem;
    }

    .chat-header p {
        font-size: 0.78rem;
    }

    .messages {
        padding: 12px 14px;
        gap: 7px;
    }

    .bubble {
        max-width: 88%;
    }

    .reply-bar {
        margin: 0 14px;
    }

    .composer-wrap {
        padding: 10px 14px 14px;
    }

    .composer {
        grid-template-columns: auto auto 1fr;
    }

    .composer .primary-btn.compact {
        grid-column: 1 / -1;
        width: 100%;
    }

    .attachment-actions {
        width: 100%;
    }

    .attachment-btn {
        flex: 1 1 auto;
    }

    .media-viewer-dialog,
    .modal-dialog {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        margin: 8px auto;
        border-radius: 16px;
    }

    .media-viewer-head {
        flex-direction: column;
        align-items: stretch;
    }

    .media-viewer-actions {
        justify-content: space-between;
    }

    .viewer-image,
    .viewer-video {
        max-height: calc(100vh - 220px);
    }
}

.draft-attachment-bar {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.draft-attachment-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.draft-attachment-copy strong,
.draft-attachment-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.draft-attachment-copy span {
    color: var(--muted);
    font-size: 0.8rem;
}

.draft-attachment-progress {
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: rgba(255,255,255,0.08);
    overflow: hidden;
    margin-top: 4px;
}

.draft-attachment-progress span {
    display: block;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 0.15s ease;
}

.attachment-caption {
    margin-top: 6px;
    font-size: 0.88rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.settings-dialog {
    max-width: 760px;
    max-height: min(88dvh, 860px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 10px;
}

.stat-card {
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    display: grid;
    gap: 4px;
}

.stat-card strong {
    font-size: 1.1rem;
}

.stat-card span,
.settings-subtitle {
    color: var(--muted);
    font-size: 0.82rem;
}

.room-info-grid.compact {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.room-members-panel {
    margin-top: 16px;
}

.member-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.member-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
}

.member-row > div {
    display: grid;
    gap: 3px;
}

.member-row span {
    color: var(--muted);
    font-size: 0.8rem;
}

.member-status {
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    border: 1px solid transparent;
}

.member-status.online {
    color: #9be6bc;
    background: rgba(16, 185, 129, 0.14);
    border-color: rgba(16, 185, 129, 0.24);
}

.member-status.offline {
    color: var(--muted);
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.08);
}

.member-status.inactive {
    color: #ffd37b;
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.24);
}

.member-status.banned {
    color: #ff9f9f;
    background: rgba(239, 68, 68, 0.14);
    border-color: rgba(239, 68, 68, 0.24);
}

.admin-user-row.is-banned {
    border-color: rgba(239, 68, 68, 0.22);
}

@media (max-width: 640px) {
    .draft-attachment-bar {
        padding: 9px 10px;
    }

    .member-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.avatar.has-image,
.profile-avatar-preview.has-image,
.member-avatar.has-image,
.picker-avatar.has-image,
.mention-avatar.has-image {
    overflow: hidden;
    padding: 0;
}

.avatar.has-image img,
.profile-avatar-preview.has-image img,
.member-avatar.has-image img,
.picker-avatar.has-image img,
.mention-avatar.has-image img,
#meAvatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.picker-item-main,
.member-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.picker-avatar {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.member-avatar {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.member-row.rich {
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.member-main > div,
.picker-item-main > div {
    min-width: 0;
}

.room-info-section {
    margin-top: 12px;
}

.room-info-section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.82rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pager-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--muted);
}

.profile-dialog {
    max-width: 720px;
}

.profile-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
}

.profile-avatar-block {
    display: grid;
    gap: 10px;
    align-content: start;
}

.profile-avatar-preview {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 800;
}

.profile-form {
    display: grid;
    gap: 12px;
    align-content: start;
}

.profile-select {
    width: 100%;
    height: 50px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    outline: none;
    background: var(--input);
    color: var(--text);
    font-size: 1rem;
}

.mention-picker {
    margin-bottom: 8px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    border-radius: 14px;
    padding: 6px;
    display: grid;
    gap: 4px;
    max-height: 220px;
    overflow: auto;
}

.mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
}

.mention-item:hover {
    background: rgba(255,255,255,0.06);
}

.mention-avatar {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.mention-pill {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(74,163,255,0.16);
    color: #7fc2ff;
    border: 1px solid rgba(74,163,255,0.22);
    font-weight: 700;
}

.room-info-content .member-list.compact {
    gap: 8px;
}

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

.room-avatar.has-image,
.room-info-avatar.has-image,
.room-manage-avatar-preview.has-image {
    overflow: hidden;
    padding: 0;
}

.room-avatar.has-image img,
.room-info-avatar.has-image img,
.room-manage-avatar-preview.has-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.room-item {
    align-items: center;
}

.room-avatar {
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--line);
}

.room-info-dialog {
    width: min(96vw, 920px);
}

.room-info-content {
    max-height: calc(86vh - 76px);
    overflow: auto;
    padding-right: 6px;
    display: grid;
    gap: 14px;
}

.room-info-hero {
    display: grid;
    grid-template-columns: 104px 1fr;
    gap: 14px;
    align-items: stretch;
}

.room-info-avatar {
    width: 104px;
    height: 104px;
    border-radius: 24px;
    font-size: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.room-info-hero-copy {
    min-width: 0;
    display: grid;
    align-content: center;
    gap: 6px;
    padding: 12px 14px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.04);
}

.room-info-hero-copy strong {
    font-size: 1.15rem;
}

.room-info-hero-copy span {
    color: var(--muted);
    font-size: 0.9rem;
}

.room-info-member-row {
    padding: 12px 14px;
}

.room-info-member-avatar {
    width: 46px;
    height: 46px;
    font-size: 0.95rem;
}

.room-manage-panel {
    display: grid;
    gap: 12px;
    margin-top: 4px;
    padding-top: 4px;
}

.room-manage-grid {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 14px;
}

.room-manage-avatar-block {
    display: grid;
    gap: 10px;
    align-content: start;
}

.room-manage-avatar-preview {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 800;
}

.room-manage-form,
.room-manage-members {
    display: grid;
    gap: 10px;
    align-content: start;
}

.room-manage-user-list {
    max-height: 240px;
}

.admin-switch-stack {
    display: grid;
    gap: 12px;
}

.filter-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 10px;
}

.filter-chip {
    padding: 8px 11px;
    border-radius: 999px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 700;
}

.filter-chip.active {
    background: rgba(43,82,120,0.24);
    border-color: rgba(43,82,120,0.36);
}

.admin-picker-list {
    max-height: 360px;
}

@media (max-width: 760px) {
    .admin-picker-list {
        max-height: none;
    }
}

@media (max-width: 700px) {
    .room-info-hero,
    .room-manage-grid {
        grid-template-columns: 1fr;
    }

    .room-info-avatar {
        width: 88px;
        height: 88px;
        border-radius: 20px;
    }
}

/* feature pack 4 overrides */
.brand-copy {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.brand-copy strong,
.brand-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-me-avatar {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--line);
    box-shadow: none;
}

.sidebar-me-avatar.has-image {
    overflow: hidden;
    padding: 0;
}

.sidebar-me-avatar.has-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.toggle-switch {
    position: relative;
    width: 102px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.06);
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 46px 0 14px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 800;
}

.toggle-switch .toggle-label {
    pointer-events: none;
    letter-spacing: 0.02em;
}

.toggle-switch .toggle-knob {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 10px 24px rgba(0,0,0,0.18);
    transition: transform 0.18s ease;
}

.toggle-switch.active {
    background: rgba(43,82,120,0.46);
    color: #dbeeff;
    border-color: rgba(74,163,255,0.34);
}

.toggle-switch.active .toggle-knob {
    transform: translateX(-58px);
}

.admin-switch-stack {
    gap: 14px;
}

.admin-switch-stack .switch-row {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.04);
    align-items: center;
}

.room-create-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 14px;
}

.room-create-avatar-block,
.room-create-form {
    display: grid;
    gap: 10px;
    align-content: start;
}

.room-create-avatar-preview {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 800;
}

.room-create-avatar-preview.has-image {
    overflow: hidden;
    padding: 0;
}

.room-create-avatar-preview.has-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.mention-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 8px;
    border-radius: 999px;
    border: 1px solid rgba(74,163,255,0.22);
    background: rgba(74,163,255,0.14);
    color: #86c7ff;
    font: inherit;
    cursor: pointer;
}

.user-card-dialog {
    width: min(520px, 92vw);
}

.user-card-content {
    display: grid;
    gap: 14px;
}

.user-card-hero {
    display: grid;
    grid-template-columns: 72px 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 12px 14px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.04);
}

.user-card-avatar {
    width: 72px;
    height: 72px;
    font-size: 1.5rem;
}

.user-card-copy {
    min-width: 0;
    display: grid;
    gap: 5px;
}

.user-card-copy strong {
    font-size: 1.04rem;
}

.user-card-copy span {
    color: var(--muted);
    font-size: 0.88rem;
}

.user-card-actions {
    display: flex;
    justify-content: flex-end;
}

.room-info-dialog {
    width: min(96vw, 940px);
    height: min(88vh, 780px);
    display: grid;
    grid-template-rows: auto 1fr;
}

.room-info-content {
    min-height: 0;
    overflow: auto;
    padding-right: 6px;
    display: grid;
    gap: 14px;
}

.room-info-hero-card {
    display: grid;
    grid-template-columns: 112px 1fr;
    gap: 16px;
    align-items: stretch;
    padding: 14px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.04);
}

.room-info-avatar {
    width: 112px;
    height: 112px;
    border-radius: 26px;
    font-size: 2.1rem;
}

.room-info-hero-copy {
    min-width: 0;
    display: grid;
    align-content: center;
    gap: 6px;
}

.room-info-hero-copy strong {
    font-size: 1.2rem;
}

.room-info-hero-copy span {
    color: var(--muted);
    font-size: 0.9rem;
}

.room-members-panel {
    display: grid;
    gap: 12px;
}

.room-members-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 2;
    padding-bottom: 6px;
    background: linear-gradient(to bottom, var(--panel) 72%, transparent);
}

.room-info-member-row {
    width: 100%;
    display: grid;
    grid-template-columns: 52px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.04);
    text-align: left;
}

.room-info-member-avatar {
    width: 52px;
    height: 52px;
    font-size: 1rem;
}

.room-info-member-copy {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.room-info-member-copy strong {
    font-size: 0.98rem;
}

.room-info-member-copy span {
    color: var(--muted);
    font-size: 0.84rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-info-member-row .member-status {
    justify-self: end;
}

.room-info-section {
    display: grid;
    gap: 8px;
}

.room-info-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.inline-audio-player {
    width: min(320px, 100%);
    margin-top: 8px;
}

.attachment-card.is-voice-card .attachment-meta {
    gap: 4px;
}

.attachment-caption {
    margin-top: 6px;
    font-size: 0.84rem;
    color: var(--muted);
    white-space: pre-wrap;
    word-break: break-word;
}

.room-avatar.has-image,
.room-info-avatar.has-image,
.sidebar-me-avatar.has-image {
    overflow: hidden;
    padding: 0;
}

.room-avatar.has-image img,
.room-info-avatar.has-image img,
.sidebar-me-avatar.has-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

@media (max-width: 760px) {
    .room-create-layout,
    .room-info-hero-card,
    .user-card-hero {
        grid-template-columns: 1fr;
    }

    .room-info-avatar {
        width: 88px;
        height: 88px;
        border-radius: 22px;
    }

    .room-info-member-row {
        grid-template-columns: 46px 1fr;
    }

    .room-info-member-row .member-status {
        grid-column: 2;
        justify-self: start;
    }
}


.room-info-member-row,
.room-info-member-row strong,
.room-info-member-copy strong {
    color: var(--text);
}

@supports (-webkit-touch-callout: none) {
    .settings-dialog {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
