:root {
    --bg: #070a14;
    --bg-soft: #0c1222;
    --surface: rgba(12, 18, 34, 0.88);
    --surface-2: rgba(16, 23, 42, 0.96);
    --surface-3: rgba(22, 31, 56, 0.96);
    --surface-4: rgba(29, 39, 68, 0.98);
    --text: #eef3ff;
    --muted: #99a8d8;
    --line: rgba(126, 144, 255, 0.16);
    --line-strong: rgba(126, 144, 255, 0.28);
    --accent: #6881ff;
    --accent-2: #86a3ff;
    --accent-3: #4ab8ff;
    --success: #68d6a0;
    --warning: #ffd27a;
    --danger: #ff7d98;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
    --radius: 22px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top, rgba(104, 129, 255, 0.18), transparent 26%),
        radial-gradient(circle at bottom right, rgba(74, 184, 255, 0.10), transparent 22%),
        linear-gradient(180deg, #09101d 0%, #060910 100%);
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button:disabled, input:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }
input, textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: rgba(6, 10, 18, 0.82);
    color: var(--text);
    border-radius: 14px;
    padding: 13px 14px;
    outline: none;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input:focus, textarea:focus {
    border-color: var(--line-strong);
    box-shadow: 0 0 0 4px rgba(104, 129, 255, 0.14);
    background: rgba(10, 16, 28, 0.95);
}
textarea { resize: vertical; min-height: 90px; }
button {
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 14px 28px rgba(73, 103, 255, 0.2);
}
button:hover { filter: brightness(1.05); }
code {
    font-family: "Cascadia Code", "Consolas", monospace;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.06);
    color: #d7e1ff;
}

.flash {
    padding: 14px 16px;
    border-radius: 16px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
}
.flash--success { background: rgba(104, 214, 160, 0.12); color: #ceffe2; }
.flash--error { background: rgba(255, 125, 152, 0.12); color: #ffd3dd; }
.text-link { color: var(--accent-2); }
.button-secondary {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    box-shadow: none;
    border: 1px solid var(--line);
}
.button-danger, .button-icon--danger { background: linear-gradient(135deg, #e16080, #ff7d98); }
.button-link-danger {
    background: transparent;
    color: var(--danger);
    padding: 0;
    box-shadow: none;
    border-radius: 0;
}
.button-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: grid;
    place-items: center;
    box-shadow: none;
}

.auth-shell,
.page-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
}
.auth-card,
.page-card {
    width: min(100%, 620px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: var(--shadow);
    padding: 30px;
    backdrop-filter: blur(18px);
}
.profile-card { width: min(100%, 760px); }
.brand-block,
.profile-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}
.brand-mark,
.server-badge,
.avatar,
.mini-avatar {
    display: grid;
    place-items: center;
    font-weight: 800;
}
.brand-mark {
    width: 54px;
    height: 54px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-3));
}
.brand-title { font-size: 1.2rem; font-weight: 800; }
.brand-subtitle,
.auth-text,
.auth-switch,
.sidebar-subtitle,
.sidebar-group-title,
.message-meta span,
.user-meta span,
.chat-header p,
.text-link,
.member-sidebar__header span,
.nav-stack-text small,
.meta-card span,
.empty-messages,
.checkbox-row span,
.message-state { color: var(--muted); }
.auth-form, .settings-form, .inline-grid-form, .mini-form { display: grid; gap: 14px; }
.auth-form label, .settings-form label, .mini-form label, .inline-grid-form label { display: grid; gap: 8px; }
.auth-switch { margin-top: 16px; }
.auth-switch a { color: var(--accent-2); }
.avatar {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    flex: 0 0 auto;
}
.avatar--large { width: 88px; height: 88px; border-radius: 24px; font-size: 1.4rem; }
.mini-avatar { width: 30px; height: 30px; border-radius: 10px; font-size: .74rem; flex: 0 0 auto; }

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 86px 320px minmax(0, 1fr);
}
.server-rail {
    padding: 18px 14px;
    border-right: 1px solid var(--line);
    background: rgba(4, 7, 14, 0.74);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.rail-spacer { flex: 1; }
.server-badge {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: rgba(255,255,255,0.06);
    transition: transform .16s ease, background .16s ease;
}
.server-badge:hover { transform: translateY(-2px); }
.server-badge.is-active,
.server-badge--home,
.server-badge--action:hover { background: linear-gradient(135deg, var(--accent), var(--accent-3)); }
.server-badge--action { border: 1px dashed var(--line-strong); }

.channel-sidebar {
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: rgba(8, 12, 22, 0.92);
    border-right: 1px solid var(--line);
    min-height: 0;
}
.sidebar-top,
.user-panel,
.member-sidebar__header {
    padding: 18px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.user-panel { border-top: 1px solid var(--line); border-bottom: 0; }
.sidebar-title { font-size: 1rem; font-weight: 800; }
.sidebar-tools, .user-actions, .member-actions { display: flex; gap: 8px; }
.icon-link {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: rgba(255,255,255,0.05);
}
.sidebar-scroll { min-height: 0; overflow: auto; }
.sidebar-group { padding: 16px 12px; }
.sidebar-group + .sidebar-group { border-top: 1px solid rgba(255,255,255,0.03); }
.sidebar-group-title {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.74rem;
    margin-bottom: 10px;
    padding: 0 8px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 14px;
    margin-bottom: 4px;
}
.nav-item:hover, .nav-item.is-active { background: rgba(104, 129, 255, 0.16); }
.nav-item--stack { align-items: flex-start; }
.nav-stack-text {
    display: grid;
    gap: 2px;
    min-width: 0;
    flex: 1;
}
.nav-stack-text strong, .nav-stack-text small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-badge {
    margin-left: auto;
    font-size: .72rem;
    color: var(--warning);
}
.meta-card {
    display: grid;
    gap: 8px;
    padding: 14px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--line);
    border-radius: 16px;
    margin-top: 12px;
}
.user-meta {
    display: grid;
    flex: 1;
    min-width: 0;
}

.chat-main {
    display: grid;
    grid-template-rows: auto 1fr;
    min-width: 0;
}
.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(9, 12, 22, 0.72);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}
.chat-header h1 { margin: 0 0 4px; font-size: 1.12rem; }
.chat-header p { margin: 0; }
.header-inline-form { flex: 0 0 auto; }
.chat-area {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
}
.chat-column {
    min-height: 0;
    display: grid;
    grid-template-rows: auto 1fr auto;
}
.channel-admin-box {
    padding: 16px 24px 0;
}
.inline-grid-form {
    grid-template-columns: 1.2fr 1.2fr auto auto;
    align-items: end;
    padding: 14px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--line);
    border-radius: 18px;
}
.checkbox-row {
    display: flex !important;
    align-items: center;
    gap: 10px;
    height: 100%;
}
.checkbox-row input { width: auto; }
.messages {
    min-height: 0;
    overflow: auto;
    padding: 22px 24px;
}
.empty-messages {
    padding: 12px 0;
}
.message-row {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 14px;
    margin-bottom: 16px;
    align-items: start;
}
.message-bubble {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 18px;
    padding: 14px 16px;
}
.message-meta {
    display: flex;
    gap: 12px;
    align-items: baseline;
    margin-bottom: 6px;
    flex-wrap: wrap;
}
.message-content { line-height: 1.58; word-break: break-word; }
.message-actions { margin-top: 10px; }
.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    padding: 18px 24px 24px;
    border-top: 1px solid var(--line);
    background: rgba(9, 12, 22, 0.76);
}
.member-sidebar {
    border-left: 1px solid var(--line);
    background: rgba(8, 12, 22, 0.78);
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 0;
}
.member-list {
    min-height: 0;
    overflow: auto;
    padding: 14px;
}
.member-row {
    padding: 10px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.04);
    background: rgba(255,255,255,0.02);
    margin-bottom: 10px;
}
.member-main {
    display: flex;
    align-items: center;
    gap: 10px;
}
.member-actions { margin-top: 10px; justify-content: flex-end; }
.member-sidebar__empty {
    padding: 18px;
    color: var(--muted);
}
.empty-state {
    display: grid;
    place-items: center;
    padding: 30px;
}
.empty-state-card {
    max-width: 440px;
    text-align: center;
    background: var(--surface-2);
    padding: 32px;
    border-radius: 24px;
    border: 1px solid var(--line);
}
.empty-icon { font-size: 2rem; margin-bottom: 12px; }

@media (max-width: 1320px) {
    .chat-area { grid-template-columns: 1fr; }
    .member-sidebar { display: none; }
}

@media (max-width: 1040px) {
    .app-shell { grid-template-columns: 72px 280px minmax(0, 1fr); }
    .inline-grid-form { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 72px minmax(0, 1fr); }
    .channel-sidebar { display: none; }
    .auth-shell, .page-shell { padding: 18px; }
    .chat-header { padding: 16px; }
    .messages { padding: 16px; }
    .composer { padding: 16px; }
}
