/* =================================================================
   Disko — стили (тёмная тема в стиле Discord)
   ================================================================= */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background: #313338;
    color: #dbdee1;
    font-family: 'gg sans', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 15px;
    overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: #00a8fc; text-decoration: none; }
.hidden { display: none !important; }

/* ===================== Цвета и токены ===================== */
:root {
    --bg-primary:    #313338;
    --bg-secondary:  #2b2d31;
    --bg-tertiary:   #232428;
    --bg-elevated:   #1e1f22;
    --bg-overlay:    rgba(0,0,0,0.6);
    --bg-rail:       #1e1f22;
    --bg-channel:    #2b2d31;
    --bg-message-hover: rgba(0,0,0,0.06);
    --bg-input:      #383a40;

    --text-normal:   #dbdee1;
    --text-muted:    #949ba4;
    --text-header:   #f2f3f5;
    --text-link:     #00a8fc;

    --brand:         #5865F2;
    --brand-hover:   #4752c4;
    --green:         #23a55a;
    --yellow:        #f0b232;
    --red:           #f23f42;
    --red-deep:      #da373c;
    --mention:       #faa61a;

    --border-subtle: rgba(0,0,0,0.2);
    --scrollbar:     #1a1b1e;
    --scrollbar-hover: #111;

    --radius-sm: 4px;
    --radius:    8px;
    --radius-lg: 16px;
    --radius-pill: 999px;
}

/* ===================== Авторизация ===================== */
.auth-screen {
    position: fixed; inset: 0;
    background: var(--bg-primary);
    display: flex; align-items: center; justify-content: center;
    background-image: linear-gradient(135deg, #5865F2 0%, #404EED 50%, #313338 100%);
}
.auth-box {
    width: 480px; max-width: 92vw;
    background: var(--bg-elevated);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo-icon { margin-bottom: 12px; }
.auth-logo h1 { font-size: 28px; color: var(--text-header); margin-bottom: 6px; }
.auth-logo p { color: var(--text-muted); font-size: 14px; }

.auth-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.auth-tab {
    flex: 1; padding: 10px; background: transparent; color: var(--text-muted);
    border: none; border-bottom: 2px solid transparent; font-size: 14px;
    font-weight: 600; transition: all 0.15s;
}
.auth-tab:hover { color: var(--text-normal); }
.auth-tab.active { color: var(--text-header); border-bottom-color: var(--brand); }

.auth-form { display: none; flex-direction: column; gap: 14px; }
.auth-form.active { display: flex; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; color: var(--text-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.auth-form .hint { text-transform: none; font-weight: 400; color: var(--text-muted); font-size: 11px; }
.auth-form input {
    padding: 11px 12px; background: var(--bg-input); border: 1px solid transparent;
    border-radius: var(--radius-sm); color: var(--text-normal); font-size: 14px;
    transition: border-color 0.15s;
}
.auth-form input:focus { outline: none; border-color: var(--brand); }

.auth-error { color: var(--red); font-size: 13px; min-height: 16px; }
.auth-hint { margin-top: 16px; color: var(--text-muted); font-size: 12px; text-align: center; }
.auth-hint p { background: var(--bg-tertiary); padding: 10px; border-radius: var(--radius-sm); }

/* ===================== Кнопки ===================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 11px 18px; border: none; border-radius: var(--radius-sm);
    background: var(--brand); color: #fff; font-weight: 600; font-size: 14px;
    transition: background 0.15s; user-select: none;
}
.btn:hover:not(:disabled) { background: var(--brand-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); }
.btn-small { padding: 6px 12px; font-size: 12px; }
.btn-danger { background: var(--red-deep); }
.btn-danger:hover:not(:disabled) { background: #a92d31; }
.btn-ghost { background: transparent; color: var(--text-normal); }
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.04); }

.icon-btn {
    width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
    background: transparent; color: var(--text-muted); border: none; border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.05); color: var(--text-normal); }
.icon-btn.active { color: var(--text-header); background: rgba(255,255,255,0.08); }
.icon-btn.danger { color: var(--red); }

/* ===================== Основное приложение (сетка) ===================== */
.app {
    display: grid;
    grid-template-columns: 72px 240px 1fr 240px;
    height: 100vh;
    width: 100vw;
}

/* ===================== Сервер-бар ===================== */
.server-rail {
    background: var(--bg-rail);
    display: flex; flex-direction: column; align-items: center;
    padding: 12px 0; gap: 8px; overflow-y: auto;
    scrollbar-width: thin;
}
.server-rail::-webkit-scrollbar { width: 4px; }
.server-rail::-webkit-scrollbar-thumb { background: var(--scrollbar); }

.server-rail-home,
.server-rail-item,
.server-rail-add {
    width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 24px; /* капля — превращается в круг при hover */
    background: var(--bg-tertiary);
    color: var(--text-normal);
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}
.server-rail-home { background: var(--brand); color: #fff; border-radius: 16px; }
.server-rail-item.active { border-radius: 16px; }
.server-rail-item:hover, .server-rail-add:hover, .server-rail-home:hover { border-radius: 16px; }
.server-rail-item::before,
.server-rail-home::before,
.server-rail-add::before {
    content: '';
    position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
    width: 4px; height: 8px; background: #fff; border-radius: 0 4px 4px 0;
    transition: all 0.2s;
    opacity: 0;
}
.server-rail-home.active::before,
.server-rail-item.active::before,
.server-rail-home:hover::before,
.server-rail-item:hover::before {
    opacity: 1; left: 0; height: 20px;
}
.server-rail-item .server-icon-letter {
    font-size: 16px; font-weight: 700; text-transform: uppercase;
}
.server-rail-item.has-unread::after {
    content: ''; position: absolute; right: -2px; top: 50%; transform: translateY(-50%);
    width: 4px; height: 8px; background: #fff; border-radius: 2px;
}
.server-rail-add {
    background: transparent; color: var(--green); border: 1px dashed var(--green);
    font-size: 28px; line-height: 1;
}
.server-rail-add:hover { background: var(--green); color: #fff; }
.server-rail-sep { width: 32px; height: 2px; background: rgba(255,255,255,0.06); border-radius: 1px; margin: 4px 0; }

/* Цветные иконки серверов */
.server-rail-item { color: #fff; }
.server-rail-item.color-0 { background: #5865F2; }
.server-rail-item.color-1 { background: #3BA55D; }
.server-rail-item.color-2 { background: #FAA61A; color: #1e1f22; }
.server-rail-item.color-3 { background: #ED4245; }
.server-rail-item.color-4 { background: #9B59B6; }
.server-rail-item.color-5 { background: #1ABC9C; }
.server-rail-item.color-6 { background: #E67E22; }
.server-rail-item.color-7 { background: #E91E63; }
.server-rail-item.color-8 { background: #00A8FC; }

/* ===================== Сайдбар каналов ===================== */
.channel-sidebar {
    background: var(--bg-secondary);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.channel-sidebar-header {
    height: 48px; padding: 0 16px;
    display: flex; align-items: center;
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 1px 0 rgba(0,0,0,0.2);
    flex-shrink: 0;
}
.channel-sidebar-header h2 {
    color: var(--text-header);
    font-size: 16px; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1;
}
.channel-sidebar-header .header-action {
    width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; color: var(--text-muted); border-radius: var(--radius-sm);
}
.channel-sidebar-header .header-action:hover { color: var(--text-normal); background: rgba(255,255,255,0.05); }

.channel-sidebar-body {
    flex: 1; overflow-y: auto;
    padding: 8px 0;
    scrollbar-width: thin;
}
.channel-sidebar-body::-webkit-scrollbar { width: 6px; }
.channel-sidebar-body::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
.channel-sidebar-body::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

.sidebar-section { padding: 16px 8px 0 8px; }
.sidebar-section-title {
    display: flex; align-items: center; gap: 4px;
    padding: 0 8px; margin-bottom: 4px;
    color: var(--text-muted); font-size: 12px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.5px;
    cursor: pointer; user-select: none;
}
.sidebar-section-title .collapse { transition: transform 0.15s; }
.sidebar-section-title.collapsed .collapse { transform: rotate(-90deg); }
.sidebar-section-title .add-btn {
    margin-left: auto; width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; color: var(--text-muted); border-radius: 3px; font-size: 18px; line-height: 1;
    opacity: 0; transition: opacity 0.15s;
}
.sidebar-section-title:hover .add-btn { opacity: 1; }
.sidebar-section-title .add-btn:hover { color: var(--text-header); }

.channel-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; margin: 1px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer; user-select: none;
    transition: all 0.1s;
}
.channel-item:hover { background: rgba(255,255,255,0.04); color: var(--text-normal); }
.channel-item.active { background: var(--bg-tertiary); color: var(--text-header); }
.channel-item .ch-icon { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; }
.channel-item .ch-name { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-item .ch-meta { font-size: 12px; color: var(--text-muted); }
.channel-item.voice .ch-icon { color: var(--text-muted); }
.channel-item.voice.active .ch-icon { color: var(--text-header); }
.channel-item.voice .voice-users { padding-left: 28px; margin-top: 2px; }
.channel-item.voice .voice-user {
    display: flex; align-items: center; gap: 6px;
    padding: 3px 8px; border-radius: 3px; font-size: 13px;
    color: var(--text-muted);
}
.channel-item.voice .voice-user.speaking { color: var(--green); }
.channel-item.voice .voice-user.muted { opacity: 0.6; }

/* ===================== Юзер-панель снизу ===================== */
.user-panel {
    height: 52px; background: var(--bg-elevated);
    display: flex; align-items: center; padding: 0 8px; gap: 8px;
    flex-shrink: 0;
}
.user-panel-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-panel-avatar { width: 32px; height: 32px; }
.user-panel-text { min-width: 0; line-height: 1.2; }
.user-panel-name { color: var(--text-header); font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel-status { color: var(--text-muted); font-size: 11px; }
.user-panel-controls { display: flex; gap: 2px; }
.user-panel-controls .icon-btn { width: 30px; height: 30px; }
.user-panel-controls .icon-btn.active { color: var(--green); background: rgba(35,165,90,0.1); }
.user-panel-controls .icon-btn.danger { color: var(--red); background: rgba(242,63,66,0.1); }

/* ===================== Аватары ===================== */
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: #fff; font-weight: 700;
    flex-shrink: 0;
    text-transform: uppercase;
    user-select: none;
}
.avatar.sm { width: 24px; height: 24px; font-size: 12px; }
.avatar.md { width: 32px; height: 32px; font-size: 14px; }
.avatar.lg { width: 80px; height: 80px; font-size: 32px; }
.avatar.xl { width: 120px; height: 120px; font-size: 48px; }
.avatar.speaking { box-shadow: 0 0 0 3px var(--green); }
.avatar.muted { opacity: 0.4; }

/* ===================== Основная зона ===================== */
.main-area {
    background: var(--bg-primary);
    display: flex; flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.main-header {
    height: 48px;
    display: flex; align-items: center; gap: 8px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 1px 0 rgba(0,0,0,0.2);
    flex-shrink: 0;
}
.main-header h2 { font-size: 16px; color: var(--text-header); font-weight: 600; }
.main-header-icon { color: var(--text-muted); display: inline-flex; }

/* ===================== Текстовый чат ===================== */
.chat-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.messages {
    flex: 1; overflow-y: auto;
    padding: 16px 0;
    scrollbar-width: thin;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }
.messages::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

.messages-empty {
    height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-muted); text-align: center; padding: 20px;
}

.message {
    display: flex; gap: 16px; padding: 4px 16px; margin-top: 8px;
    transition: background 0.1s;
}
.message:hover { background: rgba(4,4,5,0.07); }
.message.mentioned { background: rgba(250,166,26,0.05); border-left: 2px solid var(--mention); padding-left: 14px; }
.message-avatar { width: 40px; height: 40px; flex-shrink: 0; }
.message-body { flex: 1; min-width: 0; }
.message-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.message-author { color: var(--text-header); font-weight: 600; font-size: 15px; }
.message-time { color: var(--text-muted); font-size: 11px; }
.message-content { color: var(--text-normal); line-height: 1.4; word-wrap: break-word; }
.message-content a { color: var(--text-link); }
.message-edited { color: var(--text-muted); font-size: 10px; margin-left: 4px; }

.message-continuation { margin-top: 2px; padding-top: 0; }
.message-continuation .message-header { display: none; }
.message-continuation .message-avatar { visibility: hidden; height: 0; }
.message-continuation .message-body { padding-top: 0; }

/* Превью старого сообщения при скролле вверх */
.message-history-divider {
    position: relative; text-align: center; margin: 16px 0;
    color: var(--text-muted); font-size: 12px;
}
.message-history-divider::before, .message-history-divider::after {
    content: ''; position: absolute; top: 50%; width: 35%; height: 1px;
    background: var(--border-subtle);
}
.message-history-divider::before { left: 0; }
.message-history-divider::after { right: 0; }

.message-composer {
    margin: 0 16px 24px;
    background: var(--bg-input);
    border-radius: var(--radius);
    display: flex; align-items: center;
    padding: 0 12px;
}
.message-composer input {
    flex: 1; background: transparent; border: none; color: var(--text-normal);
    padding: 12px 0; font-size: 15px;
}
.message-composer input:focus { outline: none; }
.message-composer input:disabled { color: var(--text-muted); cursor: not-allowed; }
.composer-btn {
    background: transparent; border: none; color: var(--text-muted);
    width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
}
.composer-btn:hover:not(:disabled) { color: var(--text-header); }
.composer-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===================== Голосовая зона ===================== */
.voice-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.voice-stage {
    flex: 1; min-height: 0; padding: 20px; overflow-y: auto;
    display: flex; flex-direction: column; align-items: center;
    scrollbar-width: thin;
}
.voice-empty { text-align: center; color: var(--text-muted); padding: 60px 20px; }
.voice-empty p { margin: 4px 0; }
.voice-empty .hint { font-size: 13px; }

.voice-user-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px 20px;
    width: 240px; height: 200px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; margin: 8px;
    position: relative;
    transition: box-shadow 0.2s;
}
.voice-user-card.speaking { box-shadow: 0 0 0 3px var(--green), 0 0 20px rgba(35,165,90,0.3); }
.voice-user-card .avatar { transition: box-shadow 0.2s; }
.voice-user-card.speaking .avatar { box-shadow: 0 0 0 4px var(--green); }
.voice-user-card .voice-user-name { color: var(--text-header); font-weight: 600; font-size: 15px; }
.voice-user-card .voice-user-icons { display: flex; gap: 6px; min-height: 18px; }
.voice-user-card .badge-icon { color: var(--text-muted); font-size: 14px; }
.voice-user-card .badge-icon.danger { color: var(--red); }
.voice-user-card .volume-slider {
    width: 100%; margin-top: 8px;
    -webkit-appearance: none; appearance: none;
    background: transparent;
}
.voice-user-card .volume-slider::-webkit-slider-runnable-track {
    height: 4px; background: var(--bg-tertiary); border-radius: 2px;
}
.voice-user-card .volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 14px; height: 14px; background: var(--text-header); border-radius: 50%;
    margin-top: -5px; cursor: pointer;
}
.voice-user-card .volume-slider::-moz-range-track {
    height: 4px; background: var(--bg-tertiary); border-radius: 2px;
}
.voice-user-card .volume-slider::-moz-range-thumb {
    width: 14px; height: 14px; background: var(--text-header); border-radius: 50%;
    cursor: pointer; border: none;
}

.voice-grid { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; flex: 1; }
.voice-controls {
    border-top: 1px solid var(--border-subtle);
    padding: 12px 16px;
    display: flex; align-items: center; justify-content: center; gap: 12px;
    background: var(--bg-secondary);
    flex-shrink: 0;
}
.voice-control-btn {
    width: 44px; height: 44px; border-radius: 50%;
    border: none; display: inline-flex; align-items: center; justify-content: center;
    background: var(--bg-tertiary); color: var(--text-normal);
    transition: all 0.15s;
}
.voice-control-btn:hover { background: var(--bg-elevated); }
.voice-control-btn.muted { background: var(--red); color: #fff; }
.voice-control-btn.muted:hover { background: var(--red-deep); }
.voice-control-btn.deafened { background: var(--red-deep); color: #fff; }
.voice-control-btn.disconnect { background: var(--red); color: #fff; }
.voice-control-btn.disconnect:hover { background: var(--red-deep); }
.voice-control-btn svg { width: 20px; height: 20px; }

.voice-status {
    text-align: center; color: var(--text-muted); font-size: 13px;
    padding: 8px 0;
}

/* ===================== Сайдбар участников ===================== */
.members-sidebar {
    background: var(--bg-secondary);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.members-sidebar-body {
    flex: 1; overflow-y: auto;
    padding: 16px 8px;
    scrollbar-width: thin;
}
.members-sidebar-body::-webkit-scrollbar { width: 6px; }
.members-sidebar-body::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

.members-section-title {
    padding: 0 8px; margin: 16px 0 4px 0;
    color: var(--text-muted); font-size: 12px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.members-section-title:first-child { margin-top: 0; }

.member-item {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 8px; border-radius: var(--radius-sm);
    cursor: pointer; transition: background 0.1s;
    color: var(--text-muted);
}
.member-item:hover { background: rgba(255,255,255,0.04); color: var(--text-normal); }
.member-item.offline { opacity: 0.5; }
.member-item .member-name { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-item .member-actions { opacity: 0; transition: opacity 0.1s; display: flex; gap: 2px; }
.member-item:hover .member-actions { opacity: 1; }
.member-item .member-actions .icon-btn { width: 24px; height: 24px; }

/* ===================== Модалки ===================== */
.modal {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
}
.modal-backdrop {
    position: absolute; inset: 0; background: var(--bg-overlay);
    backdrop-filter: blur(2px);
}
.modal-window {
    position: relative; z-index: 1;
    background: var(--bg-elevated);
    border-radius: var(--radius);
    padding: 24px;
    width: 540px; max-width: 92vw; max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-window.small { width: 420px; }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.modal-header h2 { font-size: 20px; color: var(--text-header); font-weight: 700; }
.modal-close {
    background: transparent; border: none; color: var(--text-muted);
    width: 32px; height: 32px; border-radius: var(--radius-sm);
    font-size: 28px; line-height: 1;
}
.modal-close:hover { color: var(--text-header); background: rgba(255,255,255,0.05); }

.modal-tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.modal-tab {
    flex: 1; padding: 10px; background: var(--bg-tertiary); color: var(--text-muted);
    border: none; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
    transition: all 0.15s;
}
.modal-tab:hover { color: var(--text-normal); }
.modal-tab.active { background: var(--brand); color: #fff; }

.modal-pane { display: none; flex-direction: column; gap: 14px; }
.modal-pane.active { display: flex; }

.modal-window label {
    display: flex; flex-direction: column; gap: 6px;
    color: var(--text-muted); font-size: 12px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.modal-window .hint { text-transform: none; font-weight: 400; font-size: 11px; }
.modal-window input, .modal-window select, .modal-window textarea {
    padding: 11px 12px; background: var(--bg-input); border: 1px solid transparent;
    border-radius: var(--radius-sm); color: var(--text-normal); font-size: 14px;
}
.modal-window input:focus, .modal-window select:focus, .modal-window textarea:focus {
    outline: none; border-color: var(--brand);
}
.modal-row { display: flex; gap: 12px; }
.radio-row {
    flex: 1; flex-direction: row; align-items: center; gap: 8px;
    text-transform: none; font-weight: 400; font-size: 14px; color: var(--text-normal);
    background: var(--bg-tertiary); padding: 12px; border-radius: var(--radius-sm);
    cursor: pointer;
}
.radio-row input { width: auto; }

/* ===================== Инвайт ===================== */
.invite-code-box {
    display: flex; gap: 8px; align-items: center;
    background: var(--bg-tertiary); padding: 12px; border-radius: var(--radius-sm);
}
.invite-code-box code {
    flex: 1; font-family: 'Consolas', monospace; font-size: 18px;
    color: var(--brand); font-weight: 700; letter-spacing: 2px;
}

/* ===================== Друзья ===================== */
.friends-search { margin-bottom: 16px; }
.friends-search input {
    width: 100%; padding: 10px 12px; background: var(--bg-input);
    border: 1px solid transparent; border-radius: var(--radius-sm);
    color: var(--text-normal);
}
.friends-search input:focus { outline: none; border-color: var(--brand); }
.friends-results { margin-bottom: 16px; max-height: 200px; overflow-y: auto; }
.friends-results:empty { display: none; }
.friends-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.friends-list:empty { display: none; }
.friends-list h3 { display: flex; align-items: center; gap: 8px; }

.badge {
    background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
    padding: 2px 6px; border-radius: 10px; min-width: 20px; text-align: center;
}
.badge:empty, .badge[data-count="0"] { display: none; }

.friend-item, .request-item, .search-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px; border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
}
.friend-item .name, .request-item .name, .search-item .name { flex: 1; color: var(--text-header); font-weight: 500; }
.friend-item .name .sub, .request-item .name .sub { color: var(--text-muted); font-size: 12px; font-weight: 400; }
.friend-item .actions, .request-item .actions, .search-item .actions { display: flex; gap: 4px; }

/* ===================== DM ===================== */
.dm-list { display: flex; flex-direction: column; gap: 4px; }
.dm-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px; border-radius: var(--radius-sm);
    background: var(--bg-tertiary); cursor: pointer;
    transition: background 0.1s;
}
.dm-item:hover { background: rgba(255,255,255,0.04); }
.dm-item .name { flex: 1; }
.dm-item .preview { color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dm-messages {
    height: 360px; overflow-y: auto; padding: 16px;
    background: var(--bg-tertiary); border-radius: var(--radius-sm);
    display: flex; flex-direction: column; gap: 4px;
    scrollbar-width: thin;
}
.dm-messages::-webkit-scrollbar { width: 6px; }
.dm-messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
.dm-msg { padding: 4px 0; }
.dm-msg .from { font-weight: 600; color: var(--text-header); font-size: 13px; }
.dm-msg .text { color: var(--text-normal); }
.dm-msg .time { color: var(--text-muted); font-size: 11px; margin-left: 6px; }
.dm-msg.own { text-align: right; }
.dm-msg.own .from { color: var(--brand); }

.dm-composer { display: flex; gap: 8px; margin-top: 12px; }
.dm-composer input { flex: 1; }

/* ===================== Настройки ===================== */
.settings-section { margin-bottom: 24px; }
.settings-section h3 { color: var(--text-header); font-size: 14px; margin-bottom: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.mic-test { height: 6px; background: var(--bg-tertiary); border-radius: 3px; margin-top: 12px; overflow: hidden; }
.mic-test-bar { height: 100%; width: 0%; background: var(--green); transition: width 0.05s; }

/* ===================== Тосты ===================== */
.toast-stack {
    position: fixed; bottom: 24px; right: 24px; z-index: 200;
    display: flex; flex-direction: column-reverse; gap: 8px;
    pointer-events: none;
}
.toast {
    background: var(--bg-elevated); color: var(--text-header);
    padding: 12px 16px; border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    min-width: 240px; max-width: 360px;
    border-left: 3px solid var(--brand);
    animation: toast-in 0.3s;
    pointer-events: auto;
    cursor: pointer;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
.toast.warn { border-left-color: var(--yellow); }
.toast .title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.toast .body { color: var(--text-muted); font-size: 13px; }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===================== Мобильный топбар ===================== */
.mobile-topbar {
    display: none;
    grid-column: 1 / -1;
    grid-row: 1;
    height: 48px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
    align-items: center;
    padding: 0 8px;
    gap: 8px;
    z-index: 10;
}
.mobile-hamburger, .mobile-user-btn {
    width: 40px; height: 40px;
    background: transparent; color: var(--text-normal);
    border: none; border-radius: var(--radius-sm);
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.mobile-hamburger:hover, .mobile-user-btn:hover { background: rgba(255,255,255,0.05); }
.mobile-title {
    flex: 1; color: var(--text-header);
    font-size: 16px; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    margin: 0;
}
.mobile-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 49;
}
body.mobile-nav-open .mobile-backdrop { display: block; }

/* ===================== Адаптив (узкие экраны) ===================== */
@media (max-width: 1100px) {
    .app { grid-template-columns: 72px 220px 1fr; }
    .members-sidebar { display: none; }
}
@media (max-width: 760px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: 48px 1fr;
        height: 100vh;
    }
    /* Прячем обычные десктопные панели */
    .server-rail,
    .channel-sidebar {
        display: none;
    }
    /* Показываем мобильный топбар */
    .mobile-topbar { display: flex; }
    /* Главная зона на весь экран */
    .main-area { grid-row: 2; }
    .members-sidebar { display: none; }

    /* Когда открыто мобильное меню — показываем как overlay */
    body.mobile-nav-open .server-rail {
        display: flex;
        position: fixed;
        top: 0; left: 0;
        width: 60px; height: 100vh;
        z-index: 50;
        border-right: 1px solid var(--border-subtle);
        background: var(--bg-rail);
    }
    body.mobile-nav-open .channel-sidebar {
        display: flex;
        position: fixed;
        top: 0; left: 60px;
        width: 240px; height: 100vh;
        max-width: calc(100vw - 60px);
        z-index: 50;
        border-right: 1px solid var(--border-subtle);
        background: var(--bg-secondary);
    }
    body.mobile-nav-open .mobile-backdrop {
        display: block;
        z-index: 49;
    }
}

/* Очень узкие экраны — каналы скрываются только частично, оставляя юзер-панель */
@media (max-width: 480px) {
    body.mobile-nav-open .channel-sidebar {
        width: calc(100vw - 60px);
        left: 60px;
    }
}

/* ===================== Мобильный голос ===================== */
@media (max-width: 760px) {
    /* Прибиваем кнопки к низу экрана на мобиле, чтобы они ВСЕГДА были видны */
    .voice-controls {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 30;
        padding: 12px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        gap: 12px;
        border-top: 1px solid var(--border-subtle);
        background: var(--bg-secondary);
    }
    .voice-control-btn {
        width: 56px; height: 56px;
    }
    .voice-control-btn svg {
        width: 22px; height: 22px;
    }
    .voice-user-card {
        width: 100%;
        max-width: 320px;
        height: auto;
        min-height: 200px;
        padding: 20px 16px;
        margin: 8px 0;
    }
    .voice-grid {
        width: 100%;
    }
    .voice-connect-wrap {
        padding: 20px 16px;
    }
    .voice-connect-title {
        font-size: 20px;
        text-align: center;
        color: var(--text-header);
        margin-bottom: 8px;
    }
    .voice-connect-sub {
        color: var(--text-muted);
        text-align: center;
        margin-bottom: 24px;
        font-size: 14px;
    }
    .voice-connect-btn {
        width: 100%;
        max-width: 320px;
        padding: 18px 24px !important;
        font-size: 17px !important;
    }

    /* Чтобы контент голосового stage не уезжал под зафиксированные кнопки */
    .voice-stage {
        padding-bottom: 100px !important;
    }

    /* Сообщения и комposер на мобиле */
    .message {
        padding: 4px 12px;
        gap: 12px;
    }
    .message-avatar { width: 32px; height: 32px; }
    .message-composer {
        margin: 0 8px 12px;
        padding: 0 8px;
    }
    .message-composer input {
        font-size: 16px; /* предотвращает зум в iOS */
    }
}
