@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,600;1,9..40,300&display=swap');

:root {
    /* ── Palette ── */
    --bg:           #0a0a0f;
    --bg-noise:     url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
    --surface:      #111118;
    --surface-2:    #17171f;
    --surface-3:    #1e1e28;
    --surface-4:    #252532;
    --line:         #22222e;
    --line-strong:  #2e2e3e;

    --text:         #eeeef5;
    --text-2:       #b8b8cc;
    --muted:        #7878a0;
    --muted-2:      #4a4a68;

    /* Violet accent */
    --accent:       #a78bfa;
    --accent-2:     #7c3aed;
    --accent-hover: #c4b5fd;
    --accent-soft:  rgba(167,139,250,.08);
    --accent-line:  rgba(167,139,250,.22);
    --accent-glow:  rgba(167,139,250,.15);

    /* Status colors */
    --green:        #34d399;
    --green-soft:   rgba(52,211,153,.1);
    --danger:       #f87171;
    --danger-soft:  rgba(248,113,113,.1);
    --danger-hover: #fca5a5;
    --warning:      #fbbf24;
    --warning-hover:#fcd34d;
    --warning-soft: rgba(251,191,36,.1);

    --shadow-sm:    0 2px 8px rgba(0,0,0,.4);
    --shadow:       0 8px 32px rgba(0,0,0,.55);
    --shadow-lg:    0 24px 64px rgba(0,0,0,.7);

    --font:         'DM Sans', system-ui, sans-serif;
    --font-mono:    'DM Mono', ui-monospace, monospace;
    --radius:       6px;
    --radius-lg:    10px;
    --sidebar-w:    248px;
    --servers-w:    68px;
    --members-w:    216px;
}

/* ── Reset ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* ── Scrollbar ──────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }

/* ── Buttons ────────────────────────────────── */
button {
    border: 1px solid transparent;
    background: var(--accent);
    color: #0a0a0f;
    min-height: 36px;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius);
    transition: background .15s, border-color .15s, color .15s, transform .1s, box-shadow .15s, opacity .15s;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: .01em;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .35; cursor: not-allowed; }

.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-success { background: var(--accent); color: #0a0a0f; }
.btn-success:hover:not(:disabled) { background: var(--accent-hover); }
.btn-warning { background: var(--warning); color: #0a0a0f; }
.btn-warning:hover:not(:disabled) { background: var(--warning-hover); }
.btn-ghost {
    background: transparent;
    color: var(--text-2);
    border-color: var(--line-strong);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--surface-3);
    color: var(--text);
    border-color: var(--accent-line);
}

.btn-small { min-height: 28px; padding: 0 10px; font-size: 12px; }
.icon-btn { width: 36px; min-width: 36px; padding: 0; }
.icon-btn.btn-small { width: 28px; min-width: 28px; }
.link-btn {
    background: transparent; color: var(--muted);
    border: 0; padding: 0; min-height: auto;
    font-size: 13px; border-radius: 0; font-weight: 400;
}
.link-btn:hover { background: transparent; color: var(--accent); }
.icon-control { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }

/* ── SVG icons ──────────────────────────────── */
.ui-icon {
    width: 16px; height: 16px;
    stroke: currentColor; fill: none;
    stroke-width: 1.75;
    stroke-linecap: round; stroke-linejoin: round;
    flex: 0 0 auto; display: block;
    pointer-events: none;
}
.ui-icon-lg { width: 20px; height: 20px; }
.ui-icon-xl { width: 26px; height: 26px; }

/* ── Status dot ─────────────────────────────── */
.status-dot-inline {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--green); display: inline-block;
    box-shadow: 0 0 0 2px var(--green-soft);
    flex-shrink: 0;
}
#my-status-dot, .status-dot {
    position: absolute; right: -1px; bottom: -1px;
    width: 9px; height: 9px; border-radius: 50%;
    border: 2px solid var(--surface);
    background: var(--green);
}

/* ── Auth screens ───────────────────────────── */
.box {
    width: 420px;
    background: var(--surface);
    border: 1px solid var(--line);
    padding: 32px;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
}

/* Subtle gradient top edge */
.box::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-line), transparent);
    pointer-events: none;
}

#screen-chat.box {
    width: min(1520px, 98vw);
    height: min(880px, 96vh);
    padding: 0;
    overflow: hidden;
    border-radius: var(--radius-lg);
}
#screen-chat.box::before { display: none; }

/* ── Typography ─────────────────────────────── */
h2, h3 {
    color: var(--text);
    display: flex; align-items: center; gap: 10px;
    font-size: 20px; line-height: 1.2; margin-bottom: 24px;
    font-weight: 600;
}
h3 { font-size: 17px; margin-bottom: 18px; }
h2 .ui-icon, h3 .ui-icon { color: var(--accent); width: 20px; height: 20px; }

label {
    display: block; font-size: 11px;
    color: var(--muted); margin-bottom: 5px;
    letter-spacing: .07em; text-transform: uppercase;
    font-weight: 500;
}

input, textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--line-strong);
    color: var(--text);
    min-height: 40px;
    padding: 0 12px;
    outline: none;
    font-size: 14px;
    margin-bottom: 14px;
    border-radius: var(--radius);
    transition: border-color .15s, box-shadow .15s;
}
textarea { padding: 10px 12px; resize: vertical; min-height: 80px; }
input:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }

.err {
    color: var(--danger); font-size: 12px; min-height: 18px;
    margin-bottom: 10px; display: flex; align-items: center; gap: 6px;
}
.err:not(:empty)::before {
    content: ''; display: inline-block;
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--danger); flex-shrink: 0;
}
.ok { color: var(--green); font-size: 12px; min-height: 18px; margin-bottom: 10px; }
.hint { color: var(--muted-2); font-size: 12px; margin-top: 12px; }

/* Password rules */
#pwd-rules, #reset-pwd-rules {
    display: none; margin: 4px 0 14px;
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    padding: 10px 12px;
    border-radius: var(--radius);
}
.rule { padding: 3px 0; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.rule::before {
    content: ''; width: 5px; height: 5px; border-radius: 50%;
    background: var(--line-strong); flex-shrink: 0;
}
.rule.pass { color: var(--green); }
.rule.pass::before { background: var(--green); }

/* Code inputs */
.code-inputs {
    display: grid; grid-template-columns: repeat(6,1fr);
    gap: 8px; margin-bottom: 16px;
}
.code-inputs input {
    text-align: center; font-size: 24px; padding: 0; margin: 0;
    min-height: 54px;
    font-family: var(--font-mono);
    letter-spacing: .05em;
}

/* Dev login */
.dev-login-panel {
    margin-top: 18px; padding: 14px;
    border: 1px solid var(--accent-line);
    background: var(--accent-soft);
    border-radius: var(--radius);
}
.dev-login-title  { color: var(--accent); font-size: 11px; font-weight: 600; margin-bottom: 10px; text-transform: uppercase; letter-spacing: .07em; }
.dev-login-buttons { display: flex; flex-direction: column; gap: 7px; }
.dev-login-buttons button { width: 100%; }
.dev-login-hint { color: var(--muted); margin-top: 10px; font-size: 11px; }

/* ── App layout ─────────────────────────────── */
.app-layout {
    height: 100%; display: grid;
    grid-template-columns: var(--servers-w) var(--sidebar-w) minmax(0,1fr) var(--members-w);
    background: var(--bg);
    overflow: hidden;
}

/* ── Servers bar ────────────────────────────── */
.servers-bar {
    background: #080810;
    border-right: 1px solid var(--line);
    padding: 12px 10px;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    overflow-y: auto; overflow-x: hidden;
}
#servers-list {
    display: flex; flex-direction: column;
    gap: 6px; width: 100%; align-items: center;
}

.server-icon {
    width: 44px; height: 44px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-weight: 700; font-size: 15px;
    position: relative; flex-shrink: 0;
    transition: background .18s, border-color .18s, color .18s, border-radius .2s, box-shadow .18s;
    user-select: none;
}
.server-icon:hover {
    border-color: var(--accent-line); color: var(--text);
    background: var(--surface-3); border-radius: 14px;
    box-shadow: 0 0 0 2px var(--accent-soft);
}
.server-icon.active {
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    color: #fff; border-color: transparent;
    border-radius: 14px;
    box-shadow: 0 0 16px var(--accent-glow);
}
.server-icon.home { border-radius: 14px; }
.server-icon.home.active {
    background: linear-gradient(135deg, #4f46e5, var(--accent));
}
.server-icon.add { color: var(--accent); }
.server-icon.add:hover { background: var(--accent); color: #0a0a0f; border-radius: 14px; }
.server-icon .ui-icon { width: 18px; height: 18px; }
.server-divider { width: 28px; height: 1px; background: var(--line); flex-shrink: 0; margin: 2px 0; }
.unread-badge-server { position: absolute; top: -4px; right: -4px; z-index: 2; }

/* ── Sidebar ────────────────────────────────── */
.sidebar {
    min-width: 0;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
}

.sidebar-header {
    height: 54px;
    border-bottom: 1px solid var(--line);
    padding: 0 14px;
    display: flex; align-items: center; justify-content: space-between;
    font-size: 14px; font-weight: 600;
    flex-shrink: 0;
    background: var(--surface);
    letter-spacing: .005em;
}
.sidebar-header > span:first-child {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.sidebar-header .icon-control {
    width: 28px; height: 28px; cursor: pointer;
    border-radius: var(--radius);
    transition: background .14s, color .14s;
}
.sidebar-header .icon-control:hover { background: var(--surface-3); color: var(--text); }

.sidebar-content { flex: 1; overflow-y: auto; padding: 8px 6px 10px; }

.section-title {
    color: var(--muted-2); text-transform: uppercase;
    letter-spacing: .09em; font-size: 10px; font-weight: 600;
    padding: 14px 8px 5px;
    display: flex; justify-content: space-between; align-items: center;
}
.section-title .add-btn {
    width: 20px; height: 20px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--muted-2); cursor: pointer; border-radius: 4px;
    font-size: 15px; line-height: 1;
    transition: background .14s, color .14s;
}
.section-title .add-btn:hover { background: var(--surface-3); color: var(--accent); }

/* Channel / DM rows */
.channel-item, .dm-item {
    min-height: 34px; padding: 0 8px; margin: 1px 0;
    color: var(--muted); display: flex; align-items: center;
    gap: 8px; justify-content: space-between; cursor: pointer;
    border-radius: var(--radius); border: 1px solid transparent;
    transition: background .12s, color .12s, border-color .12s;
    font-size: 13px;
}
.channel-item:hover, .dm-item:hover {
    color: var(--text-2); background: var(--surface-2);
}
.channel-item.active, .dm-item.active {
    background: var(--accent-soft);
    border-color: var(--accent-line);
    color: var(--accent);
    font-weight: 600;
}
.channel-item .ch-name, .dm-item .dm-name {
    display: flex; align-items: center; gap: 7px;
    min-width: 0; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
    flex: 1;
}
.channel-item .ch-del {
    display: none; width: 22px; height: 22px;
    align-items: center; justify-content: center;
    color: currentColor; opacity: .5; border-radius: 4px;
    flex-shrink: 0; transition: opacity .12s, background .12s;
}
.channel-item:hover .ch-del { display: inline-flex; }
.channel-item .ch-del:hover { opacity: 1; color: var(--danger); background: var(--danger-soft); }

/* Voice occupants */
.voice-occupants { margin: 0 0 4px 14px; padding-left: 10px; border-left: 2px solid var(--line); color: var(--muted-2); font-size: 12px; }
.vo-row { padding: 2px 0; display: flex; align-items: center; gap: 6px; }
.vo-row.speaking { color: var(--green); }
.vo-row.speaking::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--green); flex-shrink: 0; }

/* Sidebar footer */
.sidebar-footer {
    min-height: 62px;
    border-top: 1px solid var(--line);
    background: #09090f;
    padding: 0 10px;
    display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.sidebar-footer .me-name {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 13px; color: var(--text); font-weight: 600;
    letter-spacing: .01em;
}

/* Footer controls group */
.footer-controls {
    display: flex; align-items: center; gap: 2px; flex-shrink: 0;
}
.footer-divider {
    width: 1px; height: 16px;
    background: var(--line-strong);
    margin: 0 4px; flex-shrink: 0;
}
.footer-btn {
    width: 28px; min-width: 28px; min-height: 28px; padding: 0;
    background: transparent; color: var(--muted-2);
    border-color: transparent; border-radius: var(--radius);
    margin: 0;
}
.footer-btn:hover:not(:disabled) {
    background: var(--surface-3);
    color: var(--text-2);
}
.footer-btn.active { color: var(--warning); }
.footer-btn.active:hover:not(:disabled) { background: var(--warning-soft); color: var(--warning-hover); }
.footer-btn-logout:hover:not(:disabled) {
    background: var(--danger-soft) !important;
    color: var(--danger) !important;
}

/* Keep old selectors working for JS that adds classes */
.sidebar-footer .btn-warning { color: var(--warning); }
.sidebar-footer .btn-warning:hover:not(:disabled) { background: var(--warning-soft); color: var(--warning-hover); }
.sidebar-footer .btn-danger  { color: var(--muted-2); }
.sidebar-footer .btn-danger:hover:not(:disabled)  { background: var(--danger-soft); color: var(--danger); }

.me-avatar-wrap, .avatar-wrap { position: relative; flex-shrink: 0; }
.me-avatar-wrap { cursor: pointer; display: inline-flex; }
.avatar { border: 1px solid var(--line); border-radius: var(--radius); }

/* DM search */
#dm-search { margin: 6px 2px 8px; width: calc(100% - 4px); }

/* ── Main area ──────────────────────────────── */
.main {
    min-width: 0; display: flex; flex-direction: column;
    background: var(--bg);
}

.main-header {
    min-height: 54px;
    border-bottom: 1px solid var(--line);
    padding: 0 18px;
    display: flex; align-items: center;
    justify-content: space-between; gap: 12px;
    flex-shrink: 0;
    background: var(--bg);
}
.main-header > div:first-child {
    display: flex; align-items: center; gap: 10px;
    min-width: 0; flex: 1; overflow: hidden;
}
.main-header > div:last-child {
    display: flex; align-items: center; gap: 6px;
    flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0;
}
.main-header .title {
    font-size: 16px; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.main-header .subtitle { color: var(--muted-2); font-size: 12px; white-space: nowrap; }
.main-header .title-icon { color: var(--muted-2); flex-shrink: 0; }

.main-header button.icon-btn {
    background: transparent; color: var(--muted);
    border-color: transparent; min-height: 30px; width: 30px; min-width: 30px;
    border-radius: var(--radius);
}
.main-header button.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.main-header button.btn-success { background: var(--accent); color: #0a0a0f; min-height: 30px; padding: 0 12px; font-size: 12px; }
.main-header button.btn-success:hover:not(:disabled) { background: var(--accent-hover); }
.main-header button.btn-danger { min-height: 30px; padding: 0 12px; font-size: 12px; }
.main-header button.btn-warning { min-height: 30px; padding: 0 12px; font-size: 12px; }

/* ── Messages ───────────────────────────────── */
.messages-area {
    flex: 1; overflow-y: auto;
    padding: 12px 18px;
    font-size: 14px; line-height: 1.6;
    display: flex; flex-direction: column; gap: 1px;
}

.msg {
    position: relative;
    padding: 7px 64px 7px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    overflow-wrap: anywhere;
    transition: background .1s, border-color .1s;
}
.msg:hover { background: var(--surface); border-color: var(--line); }
.msg.self { border-left: 2px solid var(--accent-line); }
.msg.self:hover { border-left-color: var(--accent); }
.msg .author { color: var(--accent); font-weight: 600; font-size: 13px; }
.msg.self .author { color: #a5b4fc; }
.msg .time   { color: var(--muted-2); font-size: 11px; margin-left: 7px; font-family: var(--font-mono); }
.msg .edited { color: var(--muted-2); font-size: 10px; margin-left: 4px; font-style: italic; opacity: .7; }
.msg .content { margin-top: 3px; color: var(--text-2); white-space: pre-wrap; line-height: 1.6; }
.msg:hover .content { color: var(--text); }
.msg.system {
    color: var(--muted-2); font-size: 12px; font-style: italic;
    padding-right: 12px; background: transparent !important;
    border-color: transparent !important; text-align: center;
}
.msg.error { color: var(--danger); font-size: 12px; text-align: center; background: transparent !important; border-color: transparent !important; }
.msg.highlight { background: var(--accent-soft) !important; border-color: var(--accent-line) !important; }

/* Message actions */
.msg .actions {
    position: absolute; right: 6px; top: 6px;
    display: none; gap: 2px;
    background: var(--surface-2); border: 1px solid var(--line);
    padding: 2px; border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.msg:hover .actions { display: flex; }
.msg .actions button {
    width: 26px; min-width: 26px; min-height: 26px; padding: 0;
    background: transparent; color: var(--muted); border: none; border-radius: 4px;
}
.msg .actions button:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); }
.msg .actions button.del:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }

/* Pin mark */
.pin-mark { display: inline-flex; margin-left: 6px; color: var(--accent); vertical-align: middle; }
.pin-mark .ui-icon { width: 11px; height: 11px; }

/* Reply preview */
.reply-preview {
    display: flex; align-items: center; gap: 7px;
    border-left: 2px solid var(--accent);
    padding: 4px 8px; margin-bottom: 5px;
    color: var(--muted); background: var(--surface);
    cursor: pointer; border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 12px; transition: background .12s;
}
.reply-preview:hover { background: var(--surface-2) !important; }
.reply-preview.deleted { border-left-color: var(--muted-2); color: var(--muted-2); cursor: default; }

/* Reactions */
.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.reactions button {
    min-height: 22px; padding: 0 7px;
    background: var(--surface-2); color: var(--text-2);
    border: 1px solid var(--line); font-size: 12px; border-radius: 10px;
    font-weight: 400;
}
.reactions button:hover:not(:disabled) { background: var(--surface-3); border-color: var(--line-strong); }
.reactions button.mine { border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }
.reaction-add { color: var(--muted-2) !important; font-weight: 700 !important; }

/* Attachments */
.attachment { margin-top: 7px; }
.att-image img { max-width: 340px; max-height: 240px; border: 1px solid var(--line); display: block; border-radius: var(--radius); }
.att-audio audio { max-width: 320px; }
.att-meta, .att-size { color: var(--muted-2); font-size: 11px; margin-top: 2px; }
.att-file { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.att-file a { color: var(--accent); text-decoration: none; }
.att-file a:hover { text-decoration: underline; }

/* Edit area */
.edit-area { display: flex; flex-direction: column; gap: 4px; margin-top: 5px; }
.edit-area textarea { min-height: 60px; margin-bottom: 4px; }
.edit-area .hint { font-size: 11px; color: var(--muted-2); }

/* ── Send row ────────────────────────────────── */
.send-row {
    border-top: 1px solid var(--line);
    padding: 10px 18px;
    display: flex; gap: 8px; align-items: center;
    flex-shrink: 0; background: var(--bg);
}
.send-row input {
    margin: 0; flex: 1; height: 40px; min-width: 0;
    background: var(--surface);
    border-color: var(--line);
}
.send-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}
.send-row button { flex-shrink: 0; }
.send-row .icon-btn { background: transparent; color: var(--muted); border-color: transparent; }
.send-row .icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.send-row #send-btn { background: var(--accent); color: #0a0a0f; min-height: 40px; }
.send-row #send-btn:hover:not(:disabled) { background: var(--accent-hover); }

#composer-hints, #attachment-preview { padding: 0 18px; }
.composer-hint {
    background: var(--surface); border: 1px solid var(--line);
    color: var(--muted); padding: 6px 10px; margin-top: 5px;
    display: flex; align-items: center; gap: 8px; border-radius: var(--radius);
    font-size: 12px;
}
#typing-indicator {
    min-height: 20px; padding: 2px 18px;
    color: var(--muted-2); font-size: 12px; font-style: italic;
}

/* ── Empty state ─────────────────────────────── */
.empty-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--muted-2); gap: 14px;
}
.empty-icon {
    width: 60px; height: 60px;
    border: 1px solid var(--line);
    background: var(--surface);
    display: flex; align-items: center; justify-content: center;
    color: var(--accent); border-radius: var(--radius-lg);
    box-shadow: 0 0 24px var(--accent-glow);
}
.empty-icon .ui-icon { width: 26px; height: 26px; }
.empty-state > div { font-size: 14px; color: var(--muted); }

/* ── Voice panel ─────────────────────────────── */
.voice-panel {
    min-height: 52px;
    border-top: 1px solid var(--line);
    background: var(--surface);
    padding: 0 14px;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.vp-info {
    color: var(--green); display: flex; align-items: center;
    gap: 7px; font-size: 13px; font-weight: 600;
}
.voice-panel > div:last-child { display: flex; gap: 6px; }
.voice-panel button { min-height: 28px; padding: 0 12px; font-size: 12px; }

/* ── Members bar ─────────────────────────────── */
.members-bar {
    min-width: 0;
    background: var(--surface);
    border-left: 1px solid var(--line);
    padding: 12px 8px;
    overflow-y: auto;
}
.mb-title, .member-group-title {
    color: var(--muted-2); text-transform: uppercase;
    letter-spacing: .09em; font-size: 10px; font-weight: 600;
    padding: 0 6px 8px;
}
.member-group-title { padding: 12px 6px 6px; }
.member-row {
    display: flex; align-items: center; gap: 9px;
    padding: 5px 6px; color: var(--muted);
    cursor: pointer; border-radius: var(--radius);
    border: 1px solid transparent;
    transition: background .12s, color .12s;
}
.member-row:hover { background: var(--surface-2); color: var(--text-2); }
.member-row.offline { opacity: .45; }
.member-name-block { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.member-status-text { color: var(--muted-2); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }

/* ── Modals ──────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(5,5,12,.8); z-index: 100;
    align-items: center; justify-content: center;
    backdrop-filter: blur(6px);
}
.modal-overlay.active { display: flex; }

.modal {
    width: 420px; max-width: calc(100vw - 32px);
    background: var(--surface);
    border: 1px solid var(--line);
    padding: 26px;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
    max-height: 90vh; overflow-y: auto;
    position: relative;
}
.modal::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-line), transparent);
    pointer-events: none; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal.modal-wide { width: 540px; }
.modal-tabs { display: flex; gap: 6px; margin-bottom: 20px; }
.modal-tab {
    padding: 6px 14px;
    border: 1px solid var(--line);
    color: var(--muted); cursor: pointer;
    border-radius: var(--radius);
    font-size: 13px; font-family: var(--font); font-weight: 600;
    transition: background .14s, border-color .14s, color .14s;
}
.modal-tab.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.modal-tab:hover:not(.active) { border-color: var(--line-strong); color: var(--text-2); }

/* Incoming call toast */
#call-modal {
    display: none; position: fixed; top: 20px; right: 20px;
    z-index: 1000; width: 300px;
    background: var(--surface);
    border: 1px solid var(--accent-line);
    padding: 18px; box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
}
#call-modal > div:first-child {
    font-size: 13px; font-weight: 600; margin-bottom: 8px;
    display: flex; align-items: center; gap: 8px;
    color: var(--text-2);
}
#call-caller-name { margin-bottom: 14px; color: var(--accent); font-size: 18px; font-weight: 700; }
#call-modal button { margin-right: 6px; min-height: 30px; font-size: 12px; padding: 0 12px; }

/* ── Search / Pinned ─────────────────────────── */
.results-list {
    max-height: 360px; overflow-y: auto; margin-top: 10px;
    border: 1px solid var(--line); border-radius: var(--radius);
}
.result-item {
    padding: 10px 12px; border-bottom: 1px solid var(--line);
    cursor: pointer; transition: background .12s;
}
.result-item:last-child { border-bottom: none; }
.result-item:hover { background: var(--surface-2); }
.result-empty, .empty-hint { color: var(--muted-2); padding: 10px 12px; font-size: 12px; }
.meta { color: var(--muted-2); font-size: 11px; margin-bottom: 2px; }

.user-search-result {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    background: var(--surface); margin-bottom: 6px;
    cursor: pointer; border-radius: var(--radius);
    transition: border-color .12s, background .12s;
}
.user-search-result:hover { border-color: var(--accent-line); background: var(--surface-2); }

/* Status modal */
.status-option {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; cursor: pointer;
    border: 1px solid transparent; border-radius: var(--radius);
    transition: background .12s, border-color .12s;
    font-size: 13px;
}
.status-option:hover, .status-option.active { background: var(--surface-2); border-color: var(--line); }
.status-dot-sm { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

hr { border: 0; border-top: 1px solid var(--line) !important; margin: 16px 0 !important; }

/* Emoji picker */
#emoji-picker {
    position: absolute; background: var(--surface);
    border: 1px solid var(--line); padding: 8px;
    z-index: 200; display: flex; gap: 4px; flex-wrap: wrap;
    max-width: 240px; box-shadow: var(--shadow);
    border-radius: var(--radius);
}
.emoji-picker-btn {
    min-height: 28px; padding: 0 8px;
    background: var(--surface-2); border: 1px solid var(--line);
    color: var(--text); border-radius: var(--radius); font-size: 13px;
}
.emoji-picker-btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--accent-line); }

/* ── Unread badge ────────────────────────────── */
.unread-badge {
    background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
    padding: 1px 5px; border-radius: 8px; min-width: 16px;
    text-align: center; flex-shrink: 0; line-height: 1.5;
}
.unread-badge-server {
    position: absolute; top: -4px; right: -4px;
    border: 2px solid #080810; border-radius: 8px;
    min-width: 16px; padding: 0 3px;
}
.channel-item.has-unread .ch-name { color: var(--text); font-weight: 600; }

/* Call log */
.call-status { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted-2); }
.call-status-answered { background: var(--green); }
.call-status-missed, .call-status-declined, .call-status-failed { background: var(--danger); }

/* ── Screen share panel ──────────────────────── */
.screen-share-panel {
    position: fixed; right: 20px; bottom: 20px;
    width: min(720px, 72vw); max-height: 76vh;
    background: var(--surface);
    border: 1px solid var(--line);
    z-index: 2000;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    border-radius: var(--radius-lg);
    min-width: 320px; min-height: 220px;
}
.screen-share-panel.minimized { width: 300px; height: 42px !important; min-height: 42px; }
.screen-share-panel.minimized .screen-share-videos { display: none; }
.screen-share-panel.minimized .screen-share-resize-handle { display: none; }

.screen-share-header {
    height: 42px; padding: 0 10px 0 14px;
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    cursor: move; user-select: none;
}
.screen-share-header-title {
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .08em;
    color: var(--text-2);
}
.screen-share-header-actions { display: flex; align-items: center; gap: 4px; }
.screen-share-window-btn {
    width: 26px; height: 26px; padding: 0; min-height: 26px;
    border: 1px solid var(--line); background: transparent;
    color: var(--muted); border-radius: var(--radius);
}
.screen-share-window-btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

.screen-share-videos {
    display: flex; flex-direction: column; gap: 10px;
    max-height: calc(76vh - 42px); overflow: auto; padding: 12px;
}
.screen-video-wrap { background: #050508; border: 1px solid var(--line); padding: 8px; border-radius: var(--radius); }
.screen-video-label { margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.screen-video { display: block; width: 100%; max-height: 55vh; background: #000; border-radius: var(--radius); }
.local-screen-preview { display: none; max-height: 160px; opacity: .85; }
.screen-placeholder { min-height: 220px; border: 1px dashed var(--line-strong); background: #050508; border-radius: var(--radius); }
.screen-waiting { height: 180px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.dragging-screen-panel, .resizing-screen-panel,
.resizing-screen-panel * { user-select: none !important; }
.resizing-screen-panel * { cursor: nwse-resize !important; }

.screen-share-resize-handle {
    position: absolute; right: 0; bottom: 0;
    width: 18px; height: 18px;
    cursor: nwse-resize; z-index: 3;
}
.screen-share-resize-handle::before {
    content: '';
    position: absolute; right: 5px; bottom: 5px;
    width: 8px; height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    opacity: .6;
}
.screen-share-resize-handle:hover::before { border-color: var(--accent); opacity: 1; }
.screen-share-panel[style*="height"] .screen-share-videos { max-height: calc(100% - 42px); }

/* ── Auth screens visibility ─────────────────── */
#screen-login { display: block; }
#screen-register, #screen-verify, #screen-forgot, #screen-reset, #screen-chat { display: none; }

/* ── Settings toggle helpers (legacy compat) ─────── */
.toggle-label-title { font-weight: 600; font-size: 14px; color: var(--text); }
.toggle-label-desc  { font-size: 11px; color: var(--muted-2); margin-top: 2px; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 1100px) {
    :root { --members-w: 0px; }
    .app-layout { grid-template-columns: var(--servers-w) var(--sidebar-w) minmax(0,1fr); }
    .members-bar { display: none !important; }
}
@media (max-width: 720px) {
    #screen-chat.box { width: 100vw; height: 100svh; border-radius: 0; }
    .app-layout { grid-template-columns: var(--servers-w) minmax(0,1fr); }
    .sidebar { display: none; }
    :root { --servers-w: 58px; }
}

/* Camera stream in the shared media panel */
.local-camera-wrap,
.remote-camera-wrap {
    border-color: var(--accent-line, rgba(157, 242, 47, 0.35));
}

.local-camera-preview,
.remote-camera-video {
    object-fit: cover;
    max-height: 360px;
}

.camera-placeholder {
    min-height: 220px;
}

.footer-btn.active,
#voice-camera-toggle-btn.active {
    color: var(--accent, #9df22f);
    border-color: var(--accent-line, rgba(157, 242, 47, 0.45));
    background: var(--accent-soft, rgba(157, 242, 47, 0.12));
}

/* ── Voice member state icons and stable speaking indicator ───────────── */
.voice-occupants .vo-row,
.vo-row {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px;
    min-height: 26px;
    padding: 3px 8px;
}

.voice-occupants .vo-row::before,
.vo-row::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: transparent;
    box-shadow: none;
}

.voice-occupants .vo-row.speaking::before,
.vo-row.speaking::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent, #9df22f);
    box-shadow: 0 0 10px rgba(157, 242, 47, 0.75);
}

.vo-row.speaking {
    color: var(--accent, #9df22f);
}

.vo-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vo-state-icons {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    min-width: 34px;
    flex-shrink: 0;
}

.vo-state-icon {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
}

.vo-state-icon.muted {
    color: #ff5c7a;
}

.vo-state-icon.deafened {
    color: #b794ff;
}

.sidebar-footer button.active {
    color: #ff5c7a;
    border-color: rgba(255, 92, 122, 0.45);
    background: rgba(255, 92, 122, 0.12);
}

/* ── Per-user and stream volume controls ─────────────────────────────── */
.vo-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 118px;
    flex-shrink: 0;
}

.volume-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted, #9ca3af);
}

.volume-control-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 14px;
    opacity: 0.82;
}

.volume-control-icon .ui-icon {
    width: 14px;
    height: 14px;
}

.volume-control-compact {
    gap: 5px;
}

.volume-slider {
    width: 92px;
    height: 4px;
    margin: 0;
    padding: 0;
    border: 0;
    min-height: 0;
    accent-color: var(--accent, #9df22f);
    cursor: pointer;
}

.volume-control-compact .volume-slider {
    width: 74px;
}

.volume-value {
    min-width: 34px;
    font-size: 11px;
    color: var(--muted-2, #6b7280);
    text-align: right;
}

.screen-video-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.screen-video-meta .screen-video-label {
    margin-bottom: 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.screen-video-meta .volume-control {
    flex-shrink: 0;
}

.screen-video-meta .volume-control-compact .volume-slider {
    width: 110px;
}

/* =========================================================
   Voice users: avatar + speaking ring + stable layout
   Keeps camera and volume controls intact
   ========================================================= */
.voice-occupants {
    margin: 0 0 4px 14px;
    padding: 4px 0 6px 10px;
    border-left: 2px solid var(--line);
    color: var(--muted-2);
    font-size: 12px;
}

.voice-occupants .vo-row,
.vo-row {
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 10px;
    width: 100%;
    min-height: 34px;
    padding: 4px 8px;
    color: var(--muted-2);
}

.voice-occupants .vo-row::before,
.vo-row::before {
    content: none !important;
}

.vo-avatar {
    width: 26px;
    min-width: 26px;
    height: 26px;
    min-height: 26px;
    padding: 0;
    margin: 0;
    border: 1px solid rgba(167, 139, 250, 0.35);
    border-radius: 50%;
    background: rgba(167, 139, 250, 0.14);
    color: var(--accent, #a78bfa);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: pointer;
    box-shadow: none;
}

.vo-avatar .avatar,
.vo-avatar img,
.vo-avatar div {
    width: 26px !important;
    height: 26px !important;
    min-width: 26px;
    min-height: 26px;
    border-radius: 50% !important;
    object-fit: cover;
}

.vo-row.speaking .vo-avatar {
    border-color: var(--accent, #a78bfa);
    box-shadow:
        0 0 0 2px rgba(167, 139, 250, 0.35),
        0 0 14px rgba(167, 139, 250, 0.45);
}

.vo-row.speaking .vo-name {
    color: var(--accent, #a78bfa);
}

.vo-name {
    min-width: 0;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
}

.vo-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 118px;
    flex-shrink: 0;
}

.vo-state-icons {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    min-width: 0;
    flex-shrink: 0;
}

/* =========================================================
   Footer controls layout fix
   ========================================================= */
.sidebar-footer {
    min-height: 76px;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.sidebar-footer .me-avatar,
.sidebar-footer .avatar,
.sidebar-footer img {
    flex-shrink: 0;
}

.sidebar-footer .me-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-footer .footer-controls,
.sidebar-footer .controls,
.sidebar-footer .footer-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.sidebar-footer button {
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar-footer .ui-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

/* =========================================================
   Voice users with avatar and volume popover
   ========================================================= */
.voice-occupants {
    padding: 4px 0 6px 20px;
}

.voice-occupants .vo-row,
.vo-row {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 10px;
    width: 100%;
    min-height: 36px;
    padding: 4px 8px;
    color: var(--muted, #9ca3af);
    cursor: pointer;
}

.voice-occupants .vo-row::before,
.vo-row::before {
    content: none !important;
}

.vo-avatar {
    width: 28px;
    min-width: 28px;
    height: 28px;
    min-height: 28px;
    padding: 0;
    margin: 0;
    border: 1px solid rgba(167, 139, 250, 0.35);
    border-radius: 50%;
    background: rgba(167, 139, 250, 0.14);
    color: var(--accent, #a78bfa);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    overflow: hidden;
    box-shadow: none;
}

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

.vo-row.speaking .vo-avatar {
    border-color: var(--accent, #a78bfa);
    box-shadow:
        0 0 0 2px rgba(167, 139, 250, 0.35),
        0 0 14px rgba(167, 139, 250, 0.45);
}

.vo-name {
    min-width: 0;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
}

.vo-row.speaking .vo-name {
    color: var(--accent, #a78bfa);
}

.vo-state-icons,
.vo-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    min-width: 0;
    flex-shrink: 0;
}

.vo-state-icon {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
}

.vo-state-icon.muted {
    color: #ff5c7a;
}

.vo-state-icon.deafened {
    color: #b794ff;
}

.vo-volume-btn {
    width: 24px;
    min-width: 24px;
    height: 24px;
    min-height: 24px;
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.65;
}

.vo-volume-btn:hover {
    opacity: 1;
    color: var(--accent, #a78bfa);
}

.vo-volume-btn .ui-icon {
    width: 14px;
    height: 14px;
}

/* Старые inline-ползунки в voice скрываем: громкость теперь открывается popover-ом */
.vo-actions > .volume-control,
.vo-state-icons > .volume-control {
    display: none !important;
}

/* =========================================================
   Volume popover
   ========================================================= */
.volume-popover {
    position: fixed;
    z-index: 5000;
    width: 250px;
    padding: 12px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
    border-radius: 12px;
    background: var(--surface, #11111b);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.volume-popover-title {
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text, #f4f4f5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.volume-popover-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) 50px;
    align-items: center;
    gap: 10px;
}

.volume-popover-range {
    width: 100%;
    min-width: 0;
    height: 28px;
    margin: 0;
    padding: 0;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    cursor: pointer;
    overflow: visible;
}

.volume-popover-range::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(
        to right,
        var(--accent, #8b5cf6) 0%,
        var(--accent, #8b5cf6) var(--volume-percent, 100%),
        rgba(255, 255, 255, 0.92) var(--volume-percent, 100%),
        rgba(255, 255, 255, 0.92) 100%
    );
}

.volume-popover-range::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 26px;
    height: 26px;
    margin-top: -9px;
    border: 0;
    border-radius: 50%;
    background: var(--accent, #8b5cf6);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.volume-popover-range::-moz-range-track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
}

.volume-popover-range::-moz-range-progress {
    height: 8px;
    border-radius: 999px;
    background: var(--accent, #8b5cf6);
}

.volume-popover-range::-moz-range-thumb {
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 50%;
    background: var(--accent, #8b5cf6);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.volume-popover-value {
    font-size: 12px;
    color: var(--muted, #9ca3af);
    text-align: right;
}

.volume-popover-profile {
    width: 100%;
    margin-top: 12px;
    height: 32px;
    min-height: 32px;
    font-size: 12px;
}

/* =========================================================
   Message avatars
   ========================================================= */
.messages-area .msg {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    column-gap: 12px;
    align-items: flex-start;
    padding-right: 0;
}

.messages-area .msg.system,
.messages-area .msg.error {
    display: block;
}

.msg-avatar {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    margin: 2px 0 0;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid rgba(167, 139, 250, 0.35);
    background: rgba(167, 139, 250, 0.14);
    color: var(--accent, #a78bfa);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

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

.msg-body {
    min-width: 0;
    position: relative;
}

.msg-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.msg-meta .author {
    padding: 0;
    margin: 0;
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 0;
    border: 0;
    background: transparent;
    color: var(--accent, #a78bfa);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.msg-meta .author:hover {
    text-decoration: underline;
}

.messages-area .msg .content {
    margin-top: 2px;
}

/* =========================================================
   User profile modal
   ========================================================= */
.profile-modal {
    width: min(460px, 92vw);
}

.profile-header {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 16px;
    align-items: center;
    margin-bottom: 18px;
}

.profile-avatar-slot {
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-main {
    min-width: 0;
}

.profile-main h3 {
    margin: 0 0 6px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-email,
.profile-muted {
    color: var(--muted, #9ca3af);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.profile-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 8px;
    color: var(--muted, #9ca3af);
    font-size: 13px;
}

.profile-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 8px;
}

.profile-section {
    padding: 12px 0;
    border-top: 1px solid var(--border, rgba(255, 255, 255, 0.12));
}

.profile-label {
    color: var(--muted, #9ca3af);
    font-size: 12px;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.profile-shared-servers {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.profile-server-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 9px;
    border-radius: 999px;
    background: rgba(167, 139, 250, 0.12);
    color: var(--accent, #a78bfa);
    font-size: 12px;
}

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

/* =========================================================
   FINAL FIX: footer controls layout
   ========================================================= */

.sidebar-footer {
    height: 74px;
    min-height: 74px;
    padding: 10px 14px;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    overflow: hidden;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer .me-avatar-wrap,
.sidebar-footer .me-avatar,
.sidebar-footer .user-avatar,
.sidebar-footer .avatar,
.sidebar-footer > img {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    border-radius: 50%;
    object-fit: cover;
    grid-column: 1;
}

.sidebar-footer .me-name,
#my-name-display {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    grid-column: 2;
    font-size: 13px;
    font-weight: 700;
}

.sidebar-footer .footer-controls,
.sidebar-footer .footer-actions,
.sidebar-footer .controls,
.sidebar-footer .user-controls {
    grid-column: 3;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
}

.sidebar-footer button,
.sidebar-footer .icon-btn,
.sidebar-footer #status-btn,
.sidebar-footer #settings-btn,
.sidebar-footer #mute-mic-btn,
.sidebar-footer #deafen-btn,
.sidebar-footer #camera-toggle-btn,
.sidebar-footer #audio-settings-btn,
.sidebar-footer #logout-btn {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    margin: 0;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 36px;
    line-height: 1;
}

.sidebar-footer .ui-icon,
.sidebar-footer svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.sidebar-footer .footer-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.12);
    margin: 0 4px;
    flex: 0 0 1px;
}

.sidebar-footer #logout-btn::before {
    content: none !important;
}

.sidebar-footer button.active {
    color: var(--danger, #ff5c7a);
    border-color: rgba(255, 92, 122, 0.45);
    background: rgba(255, 92, 122, 0.12);
}

/* =========================================================
   FINAL FIX: voice panel layout
   ========================================================= */

.voice-panel {
    min-height: 72px;
    height: 72px;
    padding: 12px 18px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    overflow: hidden;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.voice-panel .vp-info {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
}

.voice-panel .vp-status-text {
    color: var(--muted-2, #6b7280);
    font-weight: 400;
    flex-shrink: 0;
}

.voice-panel .vp-info .ui-icon,
.voice-panel .vp-info svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.voice-panel #vp-channel-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-panel .vp-actions,
.voice-panel > div:last-child {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
    flex-wrap: nowrap;
}

.voice-panel button,
.voice-panel #voice-camera-toggle-btn,
.voice-panel #voice-share-screen-btn,
.voice-panel #voice-stop-share-screen-btn,
.voice-panel #leave-voice-btn {
    height: 42px;
    min-height: 42px;
    width: auto;
    min-width: 104px;
    padding: 0 16px;
    margin: 0;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    white-space: nowrap;
    line-height: 1;
    font-size: 13px;
}

.voice-panel button .ui-icon,
.voice-panel button svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.voice-panel #leave-voice-btn {
    min-width: 116px;
}

/* =========================================================
   FINAL FIX: voice users list
   ========================================================= */

.voice-occupants {
    padding: 6px 0 8px 20px;
    overflow: hidden;
}

.voice-occupants .vo-row,
.vo-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 10px;
    width: 100%;
    min-height: 38px;
    padding: 5px 8px;
    color: var(--muted, #9ca3af);
    cursor: pointer;
    overflow: hidden;
}

.voice-occupants .vo-row::before,
.vo-row::before {
    content: none !important;
}

.vo-avatar {
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    margin: 0;
    border: 1px solid rgba(167, 139, 250, 0.35);
    border-radius: 50%;
    background: rgba(167, 139, 250, 0.14);
    color: var(--accent, #a78bfa);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    overflow: hidden;
    box-shadow: none;
    grid-column: 1;
}

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

.vo-row.speaking .vo-avatar {
    border-color: var(--accent, #a78bfa);
    box-shadow:
        0 0 0 2px rgba(167, 139, 250, 0.35),
        0 0 14px rgba(167, 139, 250, 0.45);
}

.vo-name {
    min-width: 0;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
    grid-column: 2;
}

.vo-row.speaking .vo-name {
    color: var(--accent, #a78bfa);
}

.vo-state-icons {
    grid-column: 3;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    min-width: 0;
    flex-shrink: 0;
}

.vo-state-icon {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
}

.vo-state-icon.muted {
    color: #ff5c7a;
}

.vo-state-icon.deafened {
    color: #b794ff;
}

.vo-volume-btn {
    width: 24px;
    min-width: 24px;
    height: 24px;
    min-height: 24px;
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.vo-volume-btn:hover {
    opacity: 1;
    color: var(--accent, #a78bfa);
}

.vo-volume-btn .ui-icon,
.vo-volume-btn svg {
    width: 14px;
    height: 14px;
}

/* =========================================================
   FINAL FIX: responsive safety
   ========================================================= */

@media (max-width: 980px) {
    .voice-panel {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 92px;
        align-items: stretch;
    }

    .voice-panel .vp-actions,
    .voice-panel > div:last-child {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .voice-panel button,
    .voice-panel #voice-camera-toggle-btn,
    .voice-panel #voice-share-screen-btn,
    .voice-panel #voice-stop-share-screen-btn,
    .voice-panel #leave-voice-btn {
        min-width: 94px;
    }
}

/* =========================================================
   FIX: chat composer must stay visible with long history
   ========================================================= */

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    min-height: 100dvh;
}

#screen-chat.box {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.app-layout {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.sidebar,
.main,
.members-bar {
    min-height: 0;
}

.main {
    height: 100%;
    overflow: hidden;
}

.main-header,
.send-row,
.voice-panel,
#typing-indicator,
#composer-hints,
#attachment-preview {
    flex-shrink: 0;
}

.messages-area {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.send-row {
    position: relative;
    z-index: 20;
}

/* The typing line should not steal vertical space when it is empty. */
#typing-indicator:empty {
    min-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

/* Keep composer hints above the input without pushing the input out of the app. */
#composer-hints:empty,
#attachment-preview:empty {
    display: none;
}


/* =========================================================
   FINAL FIX 2: initial screen visibility and compact bottom panels
   ========================================================= */

/* Chat must not be visible on first page load. showScreen("chat") sets inline display:flex. */
#screen-chat.box {
    display: none;
    flex-direction: column;
    min-height: 0;
}

#screen-login {
    display: block;
}

#screen-register,
#screen-verify,
#screen-forgot,
#screen-reset {
    display: none;
}

/* Left footer: compact, aligned, no overlapping controls */
.sidebar-footer {
    height: 58px !important;
    min-height: 58px !important;
    padding: 8px 10px !important;
    display: grid !important;
    grid-template-columns: 38px minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 8px !important;
    overflow: hidden !important;
}

.sidebar-footer .me-avatar-wrap {
    grid-column: 1 !important;
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    min-height: 38px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    overflow: visible !important;
}

.sidebar-footer .me-avatar-wrap .avatar,
.sidebar-footer .me-avatar-wrap img,
.sidebar-footer #my-avatar-slot .avatar,
.sidebar-footer #my-avatar-slot img {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    min-height: 38px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
}

.sidebar-footer #my-status-dot {
    position: absolute !important;
    right: -1px !important;
    bottom: -1px !important;
    width: 10px !important;
    height: 10px !important;
    border-radius: 50% !important;
    border: 2px solid var(--surface, #11111b) !important;
}

.sidebar-footer .me-name,
.sidebar-footer #my-name-display {
    grid-column: 2 !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 12px !important;
}

.sidebar-footer .footer-controls {
    grid-column: 3 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 5px !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: hidden !important;
}

.sidebar-footer .footer-btn,
.sidebar-footer button,
.sidebar-footer .icon-btn,
.sidebar-footer #status-btn,
.sidebar-footer #mute-mic-btn,
.sidebar-footer #camera-toggle-btn,
.sidebar-footer #audio-settings-btn,
.sidebar-footer #deafen-btn,
.sidebar-footer #settings-btn,
.sidebar-footer #logout-btn {
    width: 30px !important;
    min-width: 30px !important;
    height: 30px !important;
    min-height: 30px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 30px !important;
    line-height: 1 !important;
}

.sidebar-footer .footer-btn .ui-icon,
.sidebar-footer button .ui-icon,
.sidebar-footer .footer-btn svg,
.sidebar-footer button svg {
    width: 16px !important;
    height: 16px !important;
    flex: 0 0 16px !important;
}

.sidebar-footer .footer-divider {
    width: 1px !important;
    height: 18px !important;
    margin: 0 3px !important;
    flex: 0 0 1px !important;
}

.sidebar-footer #status-btn .status-dot-inline {
    width: 10px !important;
    height: 10px !important;
    min-width: 10px !important;
    border-radius: 50% !important;
}

/* Main voice panel: thinner and aligned */
.voice-panel {
    height: 58px !important;
    min-height: 58px !important;
    padding: 8px 14px !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 12px !important;
    overflow: hidden !important;
}

.voice-panel .vp-info {
    min-width: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    overflow: hidden !important;
    white-space: nowrap !important;
}

.voice-panel #vp-channel-name {
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}

.voice-panel .vp-actions,
.voice-panel > div:last-child {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    min-width: 0 !important;
    flex-wrap: nowrap !important;
}

.voice-panel button,
.voice-panel #voice-camera-toggle-btn,
.voice-panel #voice-share-screen-btn,
.voice-panel #voice-stop-share-screen-btn,
.voice-panel #leave-voice-btn {
    height: 38px !important;
    min-height: 38px !important;
    width: auto !important;
    min-width: 96px !important;
    padding: 0 14px !important;
    margin: 0 !important;
    border-radius: 10px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    white-space: nowrap !important;
    line-height: 1 !important;
    font-size: 13px !important;
}

.voice-panel #leave-voice-btn {
    min-width: 108px !important;
}

.voice-panel button .ui-icon,
.voice-panel button svg,
.voice-panel .vp-info .ui-icon,
.voice-panel .vp-info svg {
    width: 17px !important;
    height: 17px !important;
    flex: 0 0 17px !important;
}

/* If the sidebar is narrow, keep controls readable by hiding only the name, not buttons. */
@media (max-width: 1180px) {
    .sidebar-footer {
        grid-template-columns: 38px auto !important;
    }

    .sidebar-footer .me-name,
    .sidebar-footer #my-name-display {
        display: none !important;
    }

    .sidebar-footer .footer-controls {
        grid-column: 2 !important;
        justify-content: flex-start !important;
    }
}

/* =========================================================
   Final realtime state guards and compact footer fixes
   ========================================================= */

[hidden] {
    display: none !important;
}

#voice-panel[hidden],
#active-call-btn[hidden],
#call-peer-btn[hidden],
#share-screen-btn[hidden],
#stop-share-screen-btn[hidden],
#voice-share-screen-btn[hidden],
#voice-stop-share-screen-btn[hidden],
#voice-camera-toggle-btn[hidden],
#screen-share-panel[hidden] {
    display: none !important;
}

#voice-panel {
    display: none;
}

#voice-panel:not([hidden]) {
    display: grid;
}

#status-btn,
#audio-settings-btn {
    display: none !important;
}

.sidebar-footer {
    height: 68px !important;
    min-height: 68px !important;
    padding: 8px 12px !important;
    display: grid !important;
    grid-template-columns: 44px minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 10px !important;
    overflow: hidden !important;
}

.sidebar-footer .footer-controls {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 6px !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: hidden !important;
}

.sidebar-footer .footer-btn,
.sidebar-footer button,
.sidebar-footer .icon-btn,
.sidebar-footer #mute-mic-btn,
.sidebar-footer #camera-toggle-btn,
.sidebar-footer #deafen-btn,
.sidebar-footer #settings-btn,
.sidebar-footer #logout-btn {
    width: 32px !important;
    min-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 9px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 32px !important;
}

.sidebar-footer .footer-btn .ui-icon,
.sidebar-footer button .ui-icon,
.sidebar-footer .footer-btn svg,
.sidebar-footer button svg {
    width: 17px !important;
    height: 17px !important;
    flex: 0 0 17px !important;
}

.sidebar-footer #camera-toggle-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.sidebar-footer .footer-divider {
    width: 1px !important;
    height: 22px !important;
    margin: 0 3px !important;
    flex: 0 0 1px !important;
}

.voice-panel {
    height: 64px !important;
    min-height: 64px !important;
    padding: 10px 16px !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 14px !important;
    overflow: hidden !important;
}

.voice-panel .vp-actions,
.voice-panel > div:last-child {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 10px !important;
    flex-wrap: nowrap !important;
}

.voice-panel button,
.voice-panel #voice-camera-toggle-btn,
.voice-panel #voice-share-screen-btn,
.voice-panel #voice-stop-share-screen-btn,
.voice-panel #leave-voice-btn {
    height: 40px !important;
    min-height: 40px !important;
    min-width: 108px !important;
    padding: 0 15px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    white-space: nowrap !important;
}

/* =========================================================
   FINAL FIX: footer realtime controls and voice panel guards
   ========================================================= */

[hidden] {
    display: none !important;
}

#voice-panel[hidden],
#voice-share-screen-btn[hidden],
#voice-stop-share-screen-btn[hidden],
#share-screen-btn[hidden],
#stop-share-screen-btn[hidden],
#screen-share-panel[hidden],
#active-call-btn[hidden],
#call-peer-btn[hidden] {
    display: none !important;
}

#voice-panel {
    display: none;
}

#voice-panel:not([hidden]) {
    display: grid;
}

.sidebar-footer {
    height: 72px;
    min-height: 72px;
    padding: 10px 14px;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.sidebar-footer .me-avatar-wrap {
    grid-column: 1;
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 0;
    margin: 0;
    position: relative;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

#my-avatar-slot,
#my-avatar-slot > *,
.me-avatar-fallback {
    width: 46px !important;
    height: 46px !important;
    min-width: 46px !important;
    min-height: 46px !important;
    border-radius: 50%;
    overflow: hidden;
}

#my-avatar-slot img,
.me-avatar-fallback img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#my-status-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg, #08080d);
    background: #22c55e;
    z-index: 2;
}

#my-status-dot.online { background: #22c55e; }
#my-status-dot.idle { background: #facc15; }
#my-status-dot.dnd { background: #ef4444; }
#my-status-dot.invisible,
#my-status-dot.offline { background: #6b7280; }

.sidebar-footer .me-name,
#my-name-display {
    grid-column: 2;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 700;
}

.footer-controls {
    grid-column: 3;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
    overflow: visible;
}

.footer-controls .icon-btn,
.sidebar-footer .icon-btn,
#mute-mic-btn,
#camera-toggle-btn,
#deafen-btn,
#settings-btn,
#logout-btn {
    width: 34px !important;
    min-width: 34px !important;
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    line-height: 1;
}

.footer-controls .ui-icon,
.sidebar-footer .ui-icon,
.footer-controls svg,
.sidebar-footer svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

#audio-settings-btn,
#status-btn {
    display: none !important;
}

.footer-divider {
    width: 1px;
    height: 26px;
    margin: 0 2px;
    background: rgba(255, 255, 255, 0.14);
    flex: 0 0 1px;
}

.icon-btn.active,
.footer-btn.active {
    color: var(--danger, #ff6b6b);
    background: rgba(255, 107, 107, 0.12);
    border-color: rgba(255, 107, 107, 0.35);
}

.voice-panel {
    height: 72px;
    min-height: 72px;
    padding: 12px 18px;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    overflow: hidden;
}

.voice-panel .vp-info {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
}

.voice-panel .vp-info .ui-icon,
.voice-panel .vp-info svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.voice-panel #vp-channel-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-panel .vp-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
    flex-wrap: nowrap;
}

.voice-panel .vp-actions button {
    height: 42px;
    min-height: 42px;
    width: auto;
    min-width: 104px;
    padding: 0 16px;
    margin: 0;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    white-space: nowrap;
    line-height: 1;
    font-size: 13px;
}

.voice-panel .vp-actions button .ui-icon,
.voice-panel .vp-actions button svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

#leave-voice-btn {
    min-width: 116px;
}

@media (max-width: 1100px) {
    .sidebar-footer {
        grid-template-columns: 42px minmax(0, 1fr) auto;
        gap: 8px;
        padding-left: 10px;
        padding-right: 10px;
    }

    .footer-controls {
        gap: 6px;
    }

    .footer-controls .icon-btn,
    .sidebar-footer .icon-btn,
    #mute-mic-btn,
    #camera-toggle-btn,
    #deafen-btn,
    #settings-btn,
    #logout-btn {
        width: 32px !important;
        min-width: 32px !important;
        height: 32px !important;
        min-height: 32px !important;
        flex-basis: 32px;
    }
}

/* =========================================================
   FINAL FIX: always show microphone button in footer
   ========================================================= */
.sidebar-footer {
    height: 72px !important;
    min-height: 72px !important;
    padding: 10px 14px !important;
    display: grid !important;
    grid-template-columns: 54px minmax(0, 1fr) !important;
    grid-template-areas: "avatar controls" !important;
    align-items: center !important;
    gap: 12px !important;
    overflow: hidden !important;
}

.sidebar-footer .me-avatar-wrap,
.sidebar-footer #upload-avatar-btn,
.sidebar-footer .me-avatar-btn {
    grid-area: avatar !important;
    width: 46px !important;
    min-width: 46px !important;
    height: 46px !important;
    min-height: 46px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.sidebar-footer .me-name,
.sidebar-footer #my-name-display {
    display: none !important;
}

.sidebar-footer .footer-controls {
    grid-area: controls !important;
    min-width: 0 !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 8px !important;
    overflow: visible !important;
}

.sidebar-footer #mute-mic-btn,
.sidebar-footer #camera-toggle-btn,
.sidebar-footer #deafen-btn,
.sidebar-footer #settings-btn,
.sidebar-footer #logout-btn,
.sidebar-footer .footer-controls .icon-btn {
    width: 30px !important;
    min-width: 30px !important;
    height: 30px !important;
    min-height: 30px !important;
    flex: 0 0 30px !important;
    padding: 0 !important;
    margin: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 9px !important;
}

.sidebar-footer #mute-mic-btn[hidden],
.sidebar-footer #mute-mic-btn[style*="display: none"] {
    display: inline-flex !important;
}

.sidebar-footer #mute-mic-btn .ui-icon,
.sidebar-footer #camera-toggle-btn .ui-icon,
.sidebar-footer #deafen-btn .ui-icon,
.sidebar-footer #settings-btn .ui-icon,
.sidebar-footer #logout-btn .ui-icon,
.sidebar-footer .footer-controls svg {
    width: 17px !important;
    height: 17px !important;
    flex: 0 0 17px !important;
}

.sidebar-footer .footer-divider {
    width: 1px !important;
    height: 24px !important;
    margin: 0 4px !important;
    flex: 0 0 1px !important;
    background: rgba(255, 255, 255, 0.14) !important;
}

.sidebar-footer #logout-btn::before {
    content: none !important;
}

.sidebar-footer #mute-mic-btn.active,
.sidebar-footer #camera-toggle-btn.active,
.sidebar-footer #deafen-btn.active {
    color: var(--danger, #ff6b6b) !important;
    background: rgba(255, 107, 107, 0.12) !important;
    border-color: rgba(255, 107, 107, 0.35) !important;
}

/* =========================================================
   Profile self actions fix
   ========================================================= */
.profile-actions {
    flex-wrap: wrap;
}

.profile-actions button {
    min-height: 36px;
}

#profile-logout-btn {
    margin-left: auto;
}

#upload-avatar-btn {
    cursor: pointer;
}

#upload-avatar-btn:hover #my-avatar-slot,
#upload-avatar-btn:hover .avatar {
    filter: brightness(1.08);
}

/* =========================================================
   FINAL FIX: clickable own profile + profile status editor
   ========================================================= */

.sidebar-footer .me-avatar-wrap,
#upload-avatar-btn {
    cursor: pointer;
    pointer-events: auto;
    z-index: 2;
}

#upload-avatar-btn * {
    pointer-events: none;
}

.profile-modal {
    width: min(860px, 94vw);
    max-height: 86vh;
    overflow-y: auto;
}

.profile-header {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 26px;
    align-items: center;
}

.profile-avatar-slot {
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-avatar-slot .avatar,
.profile-avatar-slot img {
    width: 148px !important;
    height: 148px !important;
    border-radius: 50%;
    object-fit: cover;
}

.profile-main {
    min-width: 0;
}

.profile-main h3 {
    margin: 0 0 12px;
    font-size: 30px;
    line-height: 1.1;
}

.profile-email,
.profile-status,
.profile-muted {
    overflow-wrap: anywhere;
}

.profile-section {
    padding: 22px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.profile-status-options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.profile-status-option {
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
}

.profile-status-option.active {
    border-color: var(--accent, #a78bfa);
    background: rgba(167, 139, 250, 0.15);
    color: var(--accent, #a78bfa);
}

.profile-status-text-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px;
    gap: 10px;
    align-items: center;
    margin-top: 12px;
}

.profile-status-text-row input {
    margin: 0;
}

.profile-status-text-row button {
    height: 42px;
    min-height: 42px;
    margin: 0;
}

.profile-actions {
    display: grid;
    gap: 12px;
    padding-top: 6px;
}

.profile-actions-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.profile-actions button {
    min-height: 46px;
    margin: 0;
    justify-content: center;
}

.profile-logout-btn {
    width: min(330px, 100%);
    justify-self: center;
}

.profile-close-btn {
    justify-self: center;
    min-height: 32px !important;
}

.status-dot-sm {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: 0 0 10px;
}

.status-dot.online { background: #4ade80 !important; }
.status-dot.idle { background: #facc15 !important; }
.status-dot.dnd { background: #f87171 !important; }
.status-dot.invisible,
.status-dot.offline { background: #6b7280 !important; }

@media (max-width: 720px) {
    .profile-header {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 16px;
    }

    .profile-status-options {
        grid-template-columns: 1fr 1fr;
    }

    .profile-status-text-row,
    .profile-actions-row {
        grid-template-columns: 1fr;
    }
}

/* =========================================================
   Fix own avatar button in sidebar footer
   ========================================================= */

.sidebar-footer .me-avatar-wrap,
#my-profile-btn {
    width: 56px;
    min-width: 56px;
    height: 56px;
    min-height: 56px;
    padding: 0 !important;
    margin: 0;
    border: 0;
    background: transparent;
    border-radius: 50%;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    cursor: pointer;
    flex: 0 0 56px;
    box-shadow: none;
}

.sidebar-footer .me-avatar-wrap:hover,
#my-profile-btn:hover {
    background: transparent;
    box-shadow: none;
}

#my-avatar-slot {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(167, 139, 250, 0.24);
    border: 1px solid rgba(167, 139, 250, 0.45);
    color: var(--accent, #a78bfa);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}

#my-avatar-slot img,
#my-avatar-slot .avatar-img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: 50%;
}

#my-status-dot {
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 3px solid var(--bg, #08080d);
    background: #4ade80;
    z-index: 2;
}

#my-status-dot.online {
    background: #4ade80;
}

#my-status-dot.idle {
    background: #facc15;
}

#my-status-dot.dnd {
    background: #f87171;
}

#my-status-dot.invisible,
#my-status-dot.offline {
    background: #6b7280;
}

#my-profile-btn:hover #my-avatar-slot {
    filter: brightness(1.08);
}
/* =========================================================
   FINAL FIXES: media panel close/fullscreen/resize/avatar
   ========================================================= */

.screen-share-panel {
    min-width: 320px;
    min-height: 220px;
    resize: none;
}

.screen-share-panel:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-height: none !important;
    inset: 0 !important;
    border-radius: 0 !important;
}

.screen-share-panel:fullscreen .screen-share-videos {
    height: calc(100vh - 48px) !important;
    max-height: none !important;
}

.screen-share-videos {
    height: calc(100% - 44px);
    align-content: stretch;
}

.screen-video-wrap {
    min-height: 180px;
    display: flex;
    flex-direction: column;
}

.screen-video-wrap .screen-video,
.screen-video-wrap video {
    width: 100% !important;
    flex: 1 1 auto;
    min-height: 160px;
    max-height: none !important;
    object-fit: contain;
    background: #000;
}

.remote-camera-video,
.local-camera-preview {
    object-fit: cover !important;
}

.screen-share-panel:fullscreen .remote-camera-video,
.screen-share-panel:fullscreen .local-camera-preview {
    object-fit: contain !important;
}

.screen-video-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 30px;
}

.screen-video-label {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.screen-media-close-btn {
    width: 26px;
    min-width: 26px;
    height: 26px;
    min-height: 26px;
    padding: 0;
    margin: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 26px;
    line-height: 1;
    font-size: 18px;
    color: var(--muted, #a1a1aa);
    background: transparent;
    border: 1px solid transparent;
}

.screen-media-close-btn:hover {
    color: var(--danger, #ff6b6b);
    border-color: rgba(255, 107, 107, 0.35);
    background: rgba(255, 107, 107, 0.12);
}

#screen-share-fullscreen-btn {
    font-size: 14px;
}

/* Own avatar in sidebar footer: keep it round, clickable, and stable */
.sidebar-footer .me-avatar-wrap,
#upload-avatar-btn,
#my-profile-btn {
    width: 58px !important;
    min-width: 58px !important;
    height: 58px !important;
    min-height: 58px !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    background: transparent !important;
    border-radius: 50% !important;
    position: relative !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
    cursor: pointer !important;
    flex: 0 0 58px !important;
    box-shadow: none !important;
}

.sidebar-footer .me-avatar-wrap:hover,
#upload-avatar-btn:hover,
#my-profile-btn:hover {
    background: transparent !important;
    box-shadow: none !important;
}

#my-avatar-slot {
    width: 50px !important;
    height: 50px !important;
    min-width: 50px !important;
    min-height: 50px !important;
    border-radius: 50% !important;
    overflow: hidden !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(167, 139, 250, 0.24) !important;
    border: 1px solid rgba(167, 139, 250, 0.45) !important;
    color: var(--accent, #a78bfa) !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    line-height: 1 !important;
}

#my-avatar-slot img,
#my-avatar-slot .my-avatar-img {
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    object-fit: cover !important;
    border-radius: 50% !important;
}

#my-avatar-slot .my-avatar-fallback {
    width: 100% !important;
    height: 100% !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#my-status-dot {
    position: absolute !important;
    right: 3px !important;
    bottom: 3px !important;
    width: 13px !important;
    height: 13px !important;
    border-radius: 50% !important;
    border: 3px solid var(--bg, #08080d) !important;
    background: #4ade80;
    z-index: 3 !important;
}

#my-status-dot.online { background: #4ade80 !important; }
#my-status-dot.idle { background: #facc15 !important; }
#my-status-dot.dnd { background: #f87171 !important; }
#my-status-dot.invisible,
#my-status-dot.offline { background: #6b7280 !important; }

#upload-avatar-btn:hover #my-avatar-slot,
#my-profile-btn:hover #my-avatar-slot {
    filter: brightness(1.08);
}

/* =========================================================
   FINAL FIX: screen/camera panel resize, fullscreen and media scaling
   ========================================================= */

.screen-share-panel {
    position: fixed !important;
    right: 24px;
    bottom: 24px;
    width: min(960px, 76vw);
    height: min(620px, 72vh);
    min-width: 420px;
    min-height: 280px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    background: var(--surface, #11111b);
    border: 1px solid var(--line, rgba(255,255,255,.12));
    border-radius: var(--radius-lg, 14px);
    overflow: hidden;
    z-index: 3000;
    box-shadow: var(--shadow-lg, 0 24px 70px rgba(0,0,0,.45));
    resize: none;
}

.screen-share-panel[hidden],
.screen-share-panel[style*="display: none"] {
    display: none !important;
}

.screen-share-panel.minimized {
    width: 360px !important;
    height: 52px !important;
    min-width: 360px !important;
    min-height: 52px !important;
    max-height: 52px !important;
}

.screen-share-panel.minimized .screen-share-videos,
.screen-share-panel.minimized .screen-share-resize-handle {
    display: none !important;
}

.screen-share-panel.panel-fullscreen {
    left: 16px !important;
    top: 16px !important;
    right: auto !important;
    bottom: auto !important;
    width: calc(100vw - 32px) !important;
    height: calc(100vh - 32px) !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;
}

.screen-share-header {
    height: 48px !important;
    min-height: 48px !important;
    flex: 0 0 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px 0 16px;
    background: var(--surface-2, rgba(255,255,255,.04));
    border-bottom: 1px solid var(--line, rgba(255,255,255,.12));
    cursor: move;
    user-select: none;
}

.screen-share-header-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted, #a1a1aa);
}

.screen-share-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.screen-share-window-btn {
    width: 32px !important;
    min-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 !important;
    margin: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
}

.screen-share-videos {
    flex: 1 1 auto;
    min-height: 0;
    height: auto !important;
    max-height: none !important;
    display: grid !important;
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
    overflow: auto;
}

.screen-share-videos > video,
.screen-share-videos > .screen-video,
.screen-share-videos > .screen-video-wrap,
.screen-share-videos > .screen-share-block,
.screen-share-videos > .remote-screen-wrap,
.screen-share-videos > .remote-camera-wrap,
.screen-share-videos > .local-camera-wrap,
.screen-share-videos > .screen-placeholder,
.screen-share-videos > .camera-placeholder {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    align-self: stretch;
    justify-self: stretch;
}

.screen-video-wrap,
.screen-share-block,
.remote-screen-wrap,
.remote-camera-wrap,
.local-camera-wrap,
.screen-placeholder,
.camera-placeholder {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #000;
    border: 1px solid var(--line, rgba(255,255,255,.12));
    border-radius: var(--radius, 12px);
    overflow: hidden;
    padding: 0 !important;
}

.screen-video-label,
.screen-share-title,
.screen-share-owner {
    flex: 0 0 auto;
    padding: 8px 10px;
    margin: 0 !important;
    color: var(--muted, #a1a1aa);
    background: rgba(255,255,255,.04);
    font-size: 12px;
    font-weight: 700;
}

.screen-video,
.screen-share-video,
.local-screen-preview,
.remote-screen-video,
.remote-camera-video,
.local-camera-preview,
.camera-video {
    flex: 1 1 auto;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0;
    min-height: 0;
    max-width: none !important;
    max-height: none !important;
    background: #000;
    border-radius: 0 !important;
    object-fit: contain !important;
}

.local-screen-preview {
    opacity: 1 !important;
}

.screen-waiting {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: auto !important;
}

.screen-share-resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 28px !important;
    height: 28px !important;
    z-index: 20;
    cursor: nwse-resize;
}

.screen-share-resize-handle::before {
    content: "";
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 11px;
    height: 11px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    opacity: .75;
}

.screen-share-resize-handle:hover::before {
    opacity: 1;
    color: var(--accent, #a78bfa);
}

.resizing-screen-panel,
.dragging-screen-panel {
    user-select: none !important;
}

.resizing-screen-panel video,
.dragging-screen-panel video {
    pointer-events: none !important;
}


/* =========================================================
   FIX: не показывать пустой блок демонстрации, когда включена только камера
   ========================================================= */
.screen-share-videos > video.local-screen-preview:not(.active),
.local-screen-preview:not(.active),
.local-screen-preview[hidden] {
    display: none !important;
}

.local-camera-preview,
.remote-camera-video {
    object-fit: cover !important;
}

.local-screen-preview.active,
.remote-screen-video {
    object-fit: contain !important;
}


/* =========================================================
   THEMES
   ========================================================= */

/* ── Default: Dark Violet (built into :root above) ── */

/* ── AMOLED ── */
body[data-theme="amoled"] {
    --bg:           #000000;
    --surface:      #0a0a0a;
    --surface-2:    #111111;
    --surface-3:    #1a1a1a;
    --surface-4:    #222222;
    --line:         #1c1c1c;
    --line-strong:  #2a2a2a;
    --text:         #ffffff;
    --text-2:       #cccccc;
    --muted:        #888888;
    --muted-2:      #444444;
    --accent:       #e2e2e2;
    --accent-2:     #aaaaaa;
    --accent-hover: #ffffff;
    --accent-soft:  rgba(255,255,255,.06);
    --accent-line:  rgba(255,255,255,.15);
    --accent-glow:  rgba(255,255,255,.08);
}

/* ── Midnight Blue ── */
body[data-theme="midnight"] {
    --bg:           #060b18;
    --surface:      #0d1526;
    --surface-2:    #131d33;
    --surface-3:    #1a2641;
    --surface-4:    #223050;
    --line:         #1e2d4a;
    --line-strong:  #2a3e64;
    --text:         #e8eeff;
    --text-2:       #a8b8e8;
    --muted:        #6478aa;
    --muted-2:      #3a4a72;
    --accent:       #60a5fa;
    --accent-2:     #2563eb;
    --accent-hover: #93c5fd;
    --accent-soft:  rgba(96,165,250,.08);
    --accent-line:  rgba(96,165,250,.22);
    --accent-glow:  rgba(96,165,250,.15);
}

/* ── Emerald ── */
body[data-theme="emerald"] {
    --bg:           #060f0a;
    --surface:      #0d1a10;
    --surface-2:    #122016;
    --surface-3:    #18291d;
    --surface-4:    #1f3326;
    --line:         #1a2e1f;
    --line-strong:  #243f2c;
    --text:         #e8fff2;
    --text-2:       #9de8c4;
    --muted:        #5aaa88;
    --muted-2:      #2d6648;
    --accent:       #34d399;
    --accent-2:     #059669;
    --accent-hover: #6ee7b7;
    --accent-soft:  rgba(52,211,153,.08);
    --accent-line:  rgba(52,211,153,.22);
    --accent-glow:  rgba(52,211,153,.15);
}

/* ── Crimson ── */
body[data-theme="crimson"] {
    --bg:           #0f060a;
    --surface:      #1a0d11;
    --surface-2:    #211017;
    --surface-3:    #2a141e;
    --surface-4:    #341826;
    --line:         #2a1019;
    --line-strong:  #3d1726;
    --text:         #fff0f3;
    --text-2:       #f0aabc;
    --muted:        #a86080;
    --muted-2:      #6a2d44;
    --accent:       #f87171;
    --accent-2:     #dc2626;
    --accent-hover: #fca5a5;
    --accent-soft:  rgba(248,113,113,.08);
    --accent-line:  rgba(248,113,113,.22);
    --accent-glow:  rgba(248,113,113,.15);
}

/* ── Light ── */
body[data-theme="light"] {
    --bg:           #f2f2f8;
    --surface:      #ffffff;
    --surface-2:    #f8f8fe;
    --surface-3:    #ededf7;
    --surface-4:    #e4e4f0;
    --line:         #ddddf0;
    --line-strong:  #c8c8e0;
    --text:         #1a1a2e;
    --text-2:       #44446a;
    --muted:        #7070a0;
    --muted-2:      #a0a0c8;
    --accent:       #7c3aed;
    --accent-2:     #5b21b6;
    --accent-hover: #6d28d9;
    --accent-soft:  rgba(124,58,237,.08);
    --accent-line:  rgba(124,58,237,.22);
    --accent-glow:  rgba(124,58,237,.12);
    --shadow-sm:    0 2px 8px rgba(0,0,0,.1);
    --shadow:       0 8px 32px rgba(0,0,0,.14);
    --shadow-lg:    0 24px 64px rgba(0,0,0,.18);
    color-scheme: light;
}

/* =========================================================
   SETTINGS PANEL (sp-)
   ========================================================= */

.sp-overlay {
    position: fixed; inset: 0; z-index: 9000;
    background: rgba(0,0,0,.75);
    display: none;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
}
.sp-overlay.active { display: flex; }

.sp-dialog {
    display: flex;
    width: 100%; max-width: 940px;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    overflow: visible;
}

/* ── Nav ── */
.sp-nav {
    width: 232px;
    flex-shrink: 0;
    background: var(--surface);
    padding: 60px 8px 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    border-right: 1px solid var(--line);
}
.sp-nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.sp-nav-label {
    font-size: 11px; font-weight: 600; letter-spacing: .06em;
    text-transform: uppercase; color: var(--muted);
    padding: 10px 12px 4px;
}
.sp-nav-sep {
    height: 1px; background: var(--line);
    margin: 8px 12px;
}
.sp-nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius);
    font-size: 14px; font-weight: 400; color: var(--text-2);
    background: none; border: none; cursor: pointer;
    text-align: left; width: 100%;
    transition: background .15s, color .15s;
}
.sp-nav-item .ui-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.sp-nav-item:hover { background: var(--surface-3); color: var(--text); }
.sp-nav-item:hover .ui-icon { opacity: 1; }
.sp-nav-item.active {
    background: var(--surface-4);
    color: var(--text);
    font-weight: 600;
}
.sp-nav-item.active .ui-icon { opacity: 1; }
.sp-nav-danger { color: var(--danger); }
.sp-nav-danger:hover { background: var(--danger-soft); color: var(--danger-hover); }
.sp-nav-danger .ui-icon { color: var(--danger); }

/* ── Content ── */
.sp-content {
    flex: 1; min-width: 0;
    padding: 60px 40px 60px 40px;
    overflow-y: auto;
}

.sp-tab { display: none; }
.sp-tab.active { display: block; }

.sp-title {
    font-size: 20px; font-weight: 700;
    color: var(--text); margin-bottom: 28px;
    padding-bottom: 16px; border-bottom: 1px solid var(--line);
}

.sp-section {
    margin-bottom: 32px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}
.sp-section-title {
    font-size: 11px; font-weight: 700; letter-spacing: .07em;
    text-transform: uppercase; color: var(--muted);
    margin-bottom: 16px;
}
.sp-label {
    display: block; font-size: 12px; font-weight: 600;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: .04em; margin-bottom: 8px;
}
.sp-input {
    display: block; width: 100%;
    padding: 9px 12px; border-radius: var(--radius);
    background: var(--surface-3); border: 1px solid var(--line-strong);
    color: var(--text); font-size: 14px; font-family: var(--font);
    outline: none; transition: border .15s, box-shadow .15s;
}
.sp-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.sp-input-row {
    display: flex; gap: 10px; align-items: center;
}
.sp-input-row .sp-input { flex: 1; }
.sp-row { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.sp-row-info { flex: 1; }
.sp-row-label { font-size: 14px; font-weight: 600; color: var(--text); }
.sp-row-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Buttons in settings */
.sp-btn-primary {
    padding: 9px 20px; border-radius: var(--radius);
    background: var(--accent); color: #fff;
    font-size: 13px; font-weight: 600;
    border: none; cursor: pointer; white-space: nowrap;
    transition: background .15s, transform .1s;
}
.sp-btn-primary:hover { background: var(--accent-hover); }
.sp-btn-primary:active { transform: scale(.97); }
.sp-btn-danger {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 20px; border-radius: var(--radius);
    background: var(--danger); color: #fff;
    font-size: 13px; font-weight: 600;
    border: none; cursor: pointer; margin-top: 12px;
    transition: opacity .15s, transform .1s;
}
.sp-btn-danger:hover { opacity: .85; }
.sp-btn-danger:active { transform: scale(.97); }
.sp-btn-sm {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: var(--radius);
    background: var(--surface-3); border: 1px solid var(--line-strong);
    color: var(--text-2); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: background .15s, color .15s;
}
.sp-btn-sm:hover { background: var(--surface-4); color: var(--text); }
.sp-btn-sm .ui-icon { width: 13px; height: 13px; }

/* Select */
.sp-select {
    display: block; width: 100%;
    padding: 9px 12px; border-radius: var(--radius);
    background: var(--surface-3); border: 1px solid var(--line-strong);
    color: var(--text); font-size: 13px; font-family: var(--font);
    outline: none; cursor: pointer; margin-bottom: 12px;
    transition: border .15s;
}
.sp-select:focus { border-color: var(--accent); }

/* Mic level bar */
.sp-mic-test-bar {
    display: flex; align-items: center; gap: 10px;
}
.sp-mic-test-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sp-level-bar {
    flex: 1; height: 6px; border-radius: 99px;
    background: var(--surface-4);
    overflow: hidden;
}
.sp-level-fill {
    height: 100%; width: 0%;
    background: var(--accent);
    border-radius: 99px;
    transition: width .08s;
}

/* Out test */
.sp-out-test-row { display: flex; align-items: center; gap: 12px; }
.sp-hint { font-size: 12px; color: var(--muted); }
.sp-hint-warn { color: var(--warning); }

/* Sliders */
.sp-slider-row {
    display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.sp-slider-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--text-2); white-space: nowrap; min-width: 220px;
}
.sp-slider-label .ui-icon { width: 14px; height: 14px; opacity: .7; }
.sp-slider {
    flex: 1; height: 4px; border-radius: 99px;
    accent-color: var(--accent); cursor: pointer;
}
.sp-slider-val {
    font-size: 12px; color: var(--muted);
    min-width: 38px; text-align: right;
}

/* Toggles */
.sp-toggle-row {
    display: flex; align-items: flex-start; gap: 14px;
    margin-bottom: 16px; cursor: pointer; user-select: none;
}
.sp-toggle-row:last-child { margin-bottom: 0; }
.sp-toggle { display: none; }
.sp-toggle-track {
    flex-shrink: 0; margin-top: 2px;
    width: 38px; height: 22px; border-radius: 99px;
    background: var(--surface-4); border: 1px solid var(--line-strong);
    position: relative; transition: background .2s, border-color .2s;
}
.sp-toggle:checked ~ .sp-toggle-track {
    background: var(--accent);
    border-color: var(--accent);
}
.sp-toggle-thumb {
    position: absolute; top: 2px; left: 2px;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--muted); transition: transform .2s, background .2s;
}
.sp-toggle:checked ~ .sp-toggle-track .sp-toggle-thumb {
    transform: translateX(16px);
    background: #fff;
}
.sp-toggle-title { font-size: 14px; font-weight: 600; color: var(--text); }
.sp-toggle-desc  { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.5; }

/* Theme grid */
.sp-theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
}
.sp-theme-card {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 12px; border-radius: var(--radius-lg);
    background: var(--surface-2); border: 2px solid var(--line);
    cursor: pointer; transition: border-color .15s, transform .1s;
    font-size: 12px; font-weight: 600; color: var(--text-2);
}
.sp-theme-card:hover { border-color: var(--accent-line); color: var(--text); }
.sp-theme-card.active { border-color: var(--accent); color: var(--accent); }
.sp-theme-preview {
    width: 100%; height: 52px; border-radius: 6px;
    background: var(--p1);
    position: relative; overflow: hidden;
}
.sp-theme-preview::before {
    content: '';
    position: absolute; top: 0; left: 0; width: 36%; height: 100%;
    background: var(--p3);
}
.sp-theme-preview::after {
    content: '';
    position: absolute; bottom: 10px; right: 12px;
    width: 40%; height: 6px; border-radius: 99px;
    background: var(--p2);
}

/* Danger section */
.sp-section-danger { border-color: rgba(248,113,113,.25); }
.sp-danger-title {
    display: flex; align-items: center; gap: 6px;
    color: var(--danger) !important;
}
.sp-danger-title .ui-icon { width: 14px; height: 14px; }
.sp-danger-desc {
    font-size: 13px; color: var(--muted);
    margin-bottom: 16px; line-height: 1.6;
}

/* Close button — fixed so it's always visible and never clipped */
.sp-close {
    position: fixed;
    top: 16px;
    /* Offset from right edge of dialog; fallback for browsers without calc-anchor */
    right: calc((100vw - min(100vw, 940px)) / 2 - 60px);
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    width: 44px; background: none; border: none; cursor: pointer;
    color: var(--muted); transition: color .15s; z-index: 9010;
}
.sp-close:hover { color: var(--text); }
.sp-close .ui-icon { width: 22px; height: 22px; }
.sp-close span { font-size: 10px; font-weight: 700; letter-spacing: .04em; }

@media (max-width: 1010px) {
    .sp-close { right: 8px; top: 8px; }
}

/* Mobile settings */
@media (max-width: 640px) {
    .sp-overlay { align-items: flex-start; }
    .sp-dialog { flex-direction: column; min-height: 100%; width: 100%; max-width: 100%; }
    .sp-nav {
        width: 100%; padding: 48px 8px 8px;
        flex-direction: row; flex-wrap: wrap;
        border-right: none; border-bottom: 1px solid var(--line);
    }
    .sp-nav-group { flex-direction: row; flex-wrap: wrap; gap: 2px; margin: 0; }
    .sp-nav-label { display: none; }
    .sp-nav-sep { display: none; }
    .sp-nav-item { padding: 7px 10px; font-size: 12px; }
    .sp-nav-item .ui-icon { display: none; }
    .sp-content { padding: 20px 16px 40px; }
}


/* =========================================================
   PROFILE TAB — avatar + password
   ========================================================= */

/* Avatar section */
.sp-avatar-row {
    display: flex; align-items: center; gap: 20px;
}
.sp-avatar-preview {
    width: 80px; height: 80px; border-radius: 50%;
    background: var(--surface-3);
    border: 2px solid var(--line-strong);
    overflow: hidden; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    position: relative;
}
.sp-avatar-preview img {
    width: 100%; height: 100%; object-fit: cover;
}
.sp-avatar-placeholder {
    width: 36px; height: 36px; color: var(--muted-2);
}
.sp-avatar-actions {
    display: flex; flex-direction: column; gap: 8px;
}

/* Password strength indicator */
.sp-pass-strength {
    margin-bottom: 10px;
}
.sp-pass-bar {
    height: 4px; border-radius: 99px;
    background: var(--surface-4); overflow: hidden; margin-bottom: 4px;
}
.sp-pass-fill {
    height: 100%; border-radius: 99px; width: 0%;
    transition: width .3s, background-color .3s;
}

/* Output level bar — different colour */
.sp-level-fill-out {
    background: var(--green);
}

/* =========================================================
   DND BUTTON in footer
   ========================================================= */
#dnd-toggle-btn {
    position: relative;
}
#dnd-toggle-btn.dnd-active {
    color: var(--danger) !important;
}
#dnd-toggle-btn.dnd-active::after {
    content: '';
    position: absolute; bottom: 4px; right: 4px;
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--surface);
}

/* =========================================================
   PING BADGE in footer
   ========================================================= */
.footer-ping {
    display: flex; align-items: center; gap: 4px;
    padding: 0 6px; cursor: default;
    user-select: none;
}
.ping-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--muted-2);
    transition: background .4s;
    flex-shrink: 0;
}
.ping-dot.good   { background: var(--green); }
.ping-dot.medium { background: var(--warning); }
.ping-dot.bad    { background: var(--danger); }
.ping-val {
    font-size: 10px; font-weight: 700;
    color: var(--muted); letter-spacing: .02em;
    min-width: 28px;
    transition: color .4s;
}
.ping-val.good   { color: var(--green); }
.ping-val.medium { color: var(--warning); }
.ping-val.bad    { color: var(--danger); }
