:root {
    --bg: #1e1f22;
    --bg-elevated: #2b2d31;
    --bg-main: #313338;
    --bg-hover: #35373c;
    --bg-active: #404249;
    --bg-input: #1a1b1e;
    --border: #3f4147;
    --text: #dbdee1;
    --text-muted: #949ba4;
    --accent: #5865f2;
    --accent-hover: #4752c4;
    --ok: #23a55a;
    --danger: #f23f43;
    --radius: 8px;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
}

a {
    color: var(--accent);
}

code {
    font-family: Consolas, ui-monospace, monospace;
}

.boot {
    display: grid;
    place-content: center;
    min-height: 100vh;
    color: var(--text-muted);
}

/* Auth pages */

.auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 16px;
}

.card {
    width: min(100%, 440px);
    padding: 32px;
    background: var(--bg-elevated);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.35);
}

.card h1 {
    margin: 0 0 6px;
    font-size: 1.5rem;
    text-align: center;
}

.lede {
    margin: 0 0 24px;
    color: var(--text-muted);
    text-align: center;
}

/* Pages */

.page {
    max-width: 680px;
    margin: 0 auto;
    padding: 24px 16px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel {
    margin-top: 20px;
    padding: 20px;
    background: var(--bg-elevated);
    border-radius: var(--radius);
}

.panel h2 {
    margin: 0 0 12px;
    font-size: 1.1rem;
}

/* Forms */

.field {
    display: grid;
    gap: 6px;
    margin-bottom: 16px;
}

label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
}

input {
    width: 100%;
    padding: 10px;
    font: inherit;
    color: var(--text);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
}

select {
    width: 100%;
    padding: 9px 8px;
    font: inherit;
    color: var(--text);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
}

input:focus, select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Text or voice, when creating a channel. */
.kind-choice {
    min-width: 0;
    padding: 0;
    border: 0;
}

.kind-choice legend {
    margin-bottom: 6px;
    padding: 0;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.kind-option {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
    padding: 10px 12px;
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: normal;
    text-transform: none;
    color: var(--text);
    background: var(--bg-input);
    border-radius: 4px;
    cursor: pointer;
}

.kind-option:has(input:checked) {
    background: var(--bg-active);
}

.kind-option input {
    width: auto;
    margin: 0;
    accent-color: var(--accent);
}

.kind-option .kind-icon {
    width: 24px;
    font-size: 1.25rem;
    text-align: center;
    color: var(--text-muted);
}

.kind-option strong, .kind-option .hint {
    display: block;
}

.kind-option .hint {
    font-size: 0.8rem;
}

.copy-field {
    display: flex;
    gap: 8px;
    margin: 8px 0;
}

.copy-field input {
    font-family: Consolas, ui-monospace, monospace;
    font-size: 0.85rem;
}

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

.row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.grow {
    flex: 1;
    min-width: 0;
}

/* Buttons */

.btn {
    padding: 10px 16px;
    font: inherit;
    font-weight: 600;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    color: white;
    background: var(--accent);
}

.card .btn-primary {
    width: 100%;
}

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

.btn-secondary {
    color: var(--text);
    background: #4e5058;
}

.btn-danger {
    color: white;
    background: var(--danger);
}

/* Messages */

.hint {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.error, .validation-message {
    color: var(--danger);
    font-size: 0.875rem;
}

.notice {
    padding: 12px 16px;
    background: rgb(35 165 90 / 0.15);
    border-left: 4px solid var(--ok);
    border-radius: 4px;
}

.badge {
    margin-left: 6px;
    padding: 2px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--ok);
    border: 1px solid var(--ok);
    border-radius: 4px;
}

/* Passkey list */

.passkeys {
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
}

.passkeys li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

@media (max-width: 480px) {
    .card {
        padding: 24px 16px;
    }

    .passkeys li {
        flex-wrap: wrap;
    }
}

/* App shell: server rail | channel sidebar | chat | members */

.app {
    display: grid;
    grid-template-columns: 72px 240px minmax(0, 1fr) 240px;
    /* One viewport-tall row; each column scrolls inside it instead of growing the page. */
    grid-template-rows: minmax(0, 1fr);
    height: 100dvh;
    overflow: hidden;
}

.app.no-servers {
    grid-template-columns: 72px minmax(0, 1fr);
}

/* Direct messages: no member list. */
.app.no-members {
    grid-template-columns: 72px 240px minmax(0, 1fr);
}

.rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    overflow-y: auto;
    background: var(--bg);
}

.rail-item {
    position: relative;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--ok);
    font-size: 1.5rem;
    text-decoration: none;
    cursor: pointer;
    transition: border-radius 0.15s;
}

.rail-item:hover, .rail-item.active {
    border-radius: 16px;
}

/* Discord-style pill on the rail's left edge: short for unread, tall for the server you're in. */
.rail-item.unread::before, .rail-item.active::before {
    position: absolute;
    left: -12px;
    width: 4px;
    height: 8px;
    content: "";
    background: var(--text);
    border-radius: 0 4px 4px 0;
}

.rail-item.active::before {
    height: 40px;
}

.rail-item.active .avatar {
    border-radius: 16px;
    outline: 2px solid var(--text);
    outline-offset: 2px;
}

.rail-add {
    background: var(--bg-elevated);
}

.rail-dms {
    color: var(--text);
    background: var(--bg-elevated);
}

.rail-dms:hover, .rail-dms.active {
    color: white;
    background: var(--accent);
}

.rail-separator {
    flex: none;
    width: 32px;
    height: 2px;
    background: var(--bg-active);
    border-radius: 1px;
}

.rail-add:hover {
    color: white;
    background: var(--ok);
}

.rail-me {
    margin-top: auto;
}

.avatar {
    display: inline-grid;
    flex: none;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: hsl(var(--hue) 45% 42%);
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
    transition: border-radius 0.15s;
}

.avatar.server-icon {
    width: 48px;
    height: 48px;
    font-size: 1rem;
}

.rail-item:hover .server-icon {
    border-radius: 16px;
}

.sidebar, .members {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-elevated);
}

.sidebar-header {
    position: relative;
    border-bottom: 1px solid var(--bg);
}

.server-menu-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    height: 48px;
    padding: 0 16px;
    font: inherit;
    font-weight: 700;
    color: var(--text);
    text-align: left;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.server-menu-toggle:hover {
    background: var(--bg-hover);
}

.click-catcher {
    position: fixed;
    inset: 0;
    z-index: 9;
}

.menu {
    position: absolute;
    inset: 52px 8px auto 8px;
    z-index: 10;
    display: grid;
    gap: 2px;
    padding: 6px;
    background: var(--bg);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
}

.menu button {
    padding: 8px 10px;
    font: inherit;
    font-size: 0.9rem;
    color: var(--text);
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}

.menu button:hover {
    color: white;
    background: var(--accent);
}

.menu .menu-danger {
    color: var(--danger);
}

.menu .menu-danger:hover {
    background: var(--danger);
}

.channel-list, .members {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 8px 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
}

.channel-item {
    position: relative;
    display: flex;
    align-items: center;
    border-radius: 4px;
}

.channel-item.unread a {
    font-weight: 700;
    color: var(--text);
}

.channel-item.unread::before {
    position: absolute;
    left: -8px;
    width: 4px;
    height: 8px;
    content: "";
    background: var(--text);
    border-radius: 0 4px 4px 0;
}

/* A red count of unread mentions (or direct messages), at the end of a channel row or on a rail icon. */
.mention-count {
    flex: none;
    min-width: 16px;
    height: 16px;
    margin-right: 8px;
    padding: 0 4px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    color: #fff;
    background: var(--danger);
    border-radius: 8px;
}

.rail-item .mention-count {
    position: absolute;
    right: -4px;
    bottom: -4px;
    min-width: 22px;
    height: 22px;
    margin: 0;
    font-size: 0.75rem;
    line-height: 16px;
    border: 3px solid var(--bg);
    border-radius: 11px;
}

.channel-item a {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    overflow: hidden;
    color: var(--text-muted);
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.channel-item:hover a, .channel-item.active a {
    color: var(--text);
}

.channel-item.active {
    background: var(--bg-active);
}

.channel-edit {
    visibility: hidden;
}

.conversation-item a {
    display: flex;
    align-items: center;
    gap: 10px;
}

.conversation-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-item.active .presence {
    border-color: var(--bg-active);
}

.chat-header .presence {
    border-color: var(--bg-main);
}

.sidebar-title {
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 8px 0 16px;
    font-weight: 700;
}

.sidebar-hint {
    padding: 8px;
}

.channel-item:hover .channel-edit, .channel-item.active .channel-edit {
    visibility: visible;
}

.hash {
    margin-right: 6px;
    color: var(--text-muted);
}

.channel-label {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    overflow: hidden;
    color: var(--text-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-channel .hash {
    font-size: 0.8rem;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    min-width: 28px;
    height: 28px;
    padding: 0 4px;
    font: inherit;
    color: var(--text-muted);
    text-decoration: none;
    background: transparent;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}

.icon-btn:hover {
    color: var(--text);
    background: var(--bg-active);
}

.user-panel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: #232428;
}

.user-name {
    overflow: hidden;
    font-size: 0.9rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-panel .hint, .member .hint {
    font-size: 0.75rem;
}

.sidebar-error {
    padding: 0 16px;
}

.chat {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-main);
}

/* Files dragged over the chat (uploads.js adds the class). */
.chat.dropping::after {
    position: absolute;
    inset: 8px;
    z-index: 30;
    display: grid;
    place-content: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    content: "Drop files to attach them";
    background: rgb(88 101 242 / 0.85);
    border: 2px dashed white;
    border-radius: 12px;
    pointer-events: none;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 16px;
    border-bottom: 1px solid var(--bg);
}

.chat-header h1 {
    margin: 0;
    font-size: 1rem;
    white-space: nowrap;
}

.topic {
    overflow: hidden;
    padding-left: 12px;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
    border-left: 1px solid var(--border);
}

.chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Short histories sit at the bottom, next to the composer, like any chat. */
.history {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: 100%;
    padding-bottom: 12px;
}

.history-top {
    padding: 16px 16px 0;
}

.day-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 20px 16px 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.day-divider::before, .day-divider::after {
    flex: 1;
    height: 1px;
    content: "";
    background: var(--border);
}

.day-divider + .message.first {
    margin-top: 4px;
}

.channel-start h2 {
    margin: 0 0 4px;
    font-size: 1.75rem;
}

.message {
    position: relative;
    padding: 2px 16px 2px 72px;
}

.message.first {
    margin-top: 16px;
}

.message:hover {
    background: rgb(0 0 0 / 0.08);
}

.message > .avatar {
    position: absolute;
    top: 4px;
    left: 16px;
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
}

.message-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.author {
    font-weight: 600;
}

.message-meta time, .edited {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.edited {
    margin-left: 4px;
}

.compact-time {
    position: absolute;
    left: 16px;
    width: 40px;
    padding-top: 3px;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: right;
    visibility: hidden;
}

.message:hover .compact-time {
    visibility: visible;
}

.message-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.4;
}

/* Markdown: blocks sit flush, like lines of chat, and "(edited)" follows the last line of text. */
.message-text p {
    margin: 0;
}

.message-text > p:has(+ .edited) {
    display: inline;
}

.message-text :is(h3, h4, h5) {
    margin: 6px 0 2px;
    line-height: 1.25;
    font-weight: 700;
}

.message-text h3 {
    font-size: 1.5rem;
}

.message-text h4 {
    font-size: 1.25rem;
}

.message-text h5 {
    font-size: 1rem;
}

.md-subtext {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.message-text blockquote {
    margin: 2px 0;
    padding-left: 12px;
    border-left: 4px solid var(--border);
}

.message-text :is(ul, ol) {
    margin: 2px 0;
    padding-left: 1.6em;
    white-space: normal;
}

.message-text li {
    white-space: pre-wrap;
}

.message-text code {
    padding: 0.1em 0.3em;
    font-size: 0.85em;
    background: var(--bg-elevated);
    border-radius: 4px;
}

.message-text pre {
    margin: 4px 0;
    padding: 8px 10px;
    max-width: 100%;
    overflow-x: auto;
    white-space: pre;
    overflow-wrap: normal;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.message-text pre code {
    padding: 0;
    font-size: 0.85rem;
    background: none;
}

.message-text a {
    color: #00a8fc;
}

.mention {
    padding: 0 2px;
    font-weight: 500;
    color: #c9cdfb;
    background: rgb(88 101 242 / 0.3);
    border-radius: 3px;
}

a.mention {
    color: #c9cdfb;
    text-decoration: none;
}

a.mention:hover {
    color: #fff;
    background: var(--accent);
}

.mention.me {
    color: #fff;
    background: rgb(88 101 242 / 0.6);
}

.mention.unknown {
    color: var(--text-muted);
    background: rgb(255 255 255 / 0.06);
}

/* Messages that mention you: tinted, with a bar down the left edge. */
.message.mentions-me {
    background: rgb(240 177 50 / 0.08);
}

.message.mentions-me:hover {
    background: rgb(240 177 50 / 0.12);
}

.message.mentions-me::before {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 2px;
    content: "";
    background: #f0b132;
}

/* Suggestions for @ and # while typing, above the box. */
.mention-suggest {
    position: absolute;
    right: 0;
    bottom: 100%;
    left: 0;
    z-index: 20;
    max-height: 300px;
    margin: 0 0 6px;
    padding: 6px;
    overflow-y: auto;
    list-style: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgb(0 0 0 / 0.35);
}

.mention-suggest li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.mention-suggest li.selected {
    background: var(--bg-active);
}

.mention-suggest .avatar {
    width: 24px;
    height: 24px;
    font-size: 0.65rem;
}

.mention-suggest .hash {
    width: 24px;
    text-align: center;
    color: var(--text-muted);
}

.suggest-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.spoiler {
    padding: 0 2px;
    background: rgb(255 255 255 / 0.1);
    border-radius: 3px;
}

.spoiler:not(.revealed) {
    color: transparent;
    background: var(--bg);
    cursor: pointer;
    user-select: none;
}

.spoiler:not(.revealed) * {
    visibility: hidden;
}

.spoiler:not(.revealed):hover {
    background: #17181a;
}

.message.sending .message-text {
    opacity: 0.5;
}

.message.failed .message-text {
    color: var(--danger);
}

.send-failed {
    font-size: 0.8rem;
    color: var(--danger);
}

.link-btn {
    padding: 0;
    font: inherit;
    color: var(--accent);
    background: none;
    border: 0;
    cursor: pointer;
    text-decoration: underline;
}

.message-actions {
    position: absolute;
    top: -14px;
    right: 16px;
    display: none;
    gap: 4px;
    padding: 2px;
    background: var(--bg-elevated);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.3);
}

.message-actions .btn {
    padding: 2px 8px;
    font-size: 0.8rem;
}

.message:hover .message-actions, .message-actions:focus-within {
    display: flex;
}

.message-edit textarea, .composer textarea {
    width: 100%;
    padding: 10px 14px;
    font: inherit;
    line-height: 1.4;
    color: var(--text);
    background: var(--bg-active);
    border: 0;
    border-radius: 8px;
    resize: none;
    field-sizing: content;
    max-height: 40vh;
}

.message-edit textarea:focus, .composer textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.composer {
    position: relative;
    /* Installed on a phone with a home indicator, keep the message box clear of it. */
    padding: 0 16px max(16px, env(safe-area-inset-bottom));
}

.composer > .mention-suggest {
    right: 16px;
    left: 16px;
}

.message-edit {
    position: relative;
}

.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.attach-btn {
    flex: none;
    width: 40px;
    height: 40px;
    font-size: 1.4rem;
    background: var(--bg-active);
    border-radius: 50%;
}

.composer-notice {
    margin: 0 0 6px;
    font-size: 0.85rem;
    color: #f0b232;
}

.upload-tray {
    display: flex;
    gap: 8px;
    margin: 0 0 8px;
    padding: 0 0 4px;
    overflow-x: auto;
    list-style: none;
}

.upload {
    position: relative;
    display: grid;
    flex: none;
    grid-template-rows: 96px auto auto;
    gap: 4px;
    width: 140px;
    padding: 8px;
    background: var(--bg-elevated);
    border-radius: 8px;
}

.upload.failed {
    outline: 1px solid var(--danger);
}

.upload-thumb {
    width: 100%;
    height: 96px;
    object-fit: cover;
    border-radius: 4px;
}

.upload-thumb.file-icon {
    display: grid;
    place-items: center;
    font-size: 2.5rem;
    background: var(--bg-active);
}

.upload-name {
    overflow: hidden;
    font-size: 0.8rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload .hint, .upload-error {
    font-size: 0.75rem;
}

.upload-error {
    color: var(--danger);
}

.upload progress {
    width: 100%;
    height: 6px;
    accent-color: var(--accent);
}

.upload-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    color: var(--text);
    background: rgb(0 0 0 / 0.6);
}

/* Attachments in messages */

.attachments {
    display: grid;
    /* One column as wide as the message, so long file names shrink and cut off instead of overflowing. */
    grid-template-columns: minmax(0, 1fr);
    justify-items: start;
    gap: 8px;
    margin: 4px 0;
}

.attachment-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 100%;
}

.attachment-image {
    position: relative;
    max-width: 100%;
    overflow: hidden;
    background: var(--bg-elevated);
    border-radius: 8px;
}

.attachment-open {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    background: none;
    border: 0;
    cursor: zoom-in;
}

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

/* The author's own attachments can be taken off the message; the button shows on hover, like message actions. */
.attachment-video, .attachment-card {
    position: relative;
}

.attachment-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    display: none;
    padding: 2px 8px;
    font-size: 0.8rem;
}

.attachment-image:hover .attachment-remove, .attachment-video:hover .attachment-remove,
.attachment-card:hover .attachment-remove, .attachment-remove:focus {
    display: block;
}

.attachment-video {
    max-width: 100%;
    margin: 0;
}

.attachment-video video {
    display: block;
    width: 100%;
    background: black;
    border-radius: 8px;
}

.attachment-video figcaption {
    margin-top: 2px;
}

.attachment-card {
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(400px, 100%);
    margin: 0;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.attachment-card .file-icon {
    font-size: 1.75rem;
}

.attachment-audio {
    flex-direction: column;
    align-items: stretch;
}

.attachment-audio audio {
    width: 100%;
}

.file-link {
    display: grid;
    min-width: 0;
}

.file-link a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-link .hint {
    font-size: 0.75rem;
}

.message.sending .attachments {
    opacity: 0.5;
}

/* Lightbox */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    justify-items: center;
    gap: 12px;
    padding: 16px 16px max(16px, env(safe-area-inset-bottom));
    background: rgb(0 0 0 / 0.85);
}

.lightbox:focus {
    outline: none;
}

/* As big as the screen allows (never past its own size), keeping its aspect ratio; Lightbox.razor sets both. */
.lightbox-image {
    position: relative;
    align-self: center;
    width: min(100%, var(--natural-width), calc((100dvh - 120px) * var(--ratio)));
}

/* Stacked: the original, later in the page, covers the preview once it has loaded. */
.lightbox-image img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.lightbox-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
    padding: 6px 10px;
    background: var(--bg-elevated);
    border-radius: 8px;
}

.lightbox-bar .btn {
    padding: 4px 10px;
    font-size: 0.85rem;
}

.lightbox-name {
    overflow: hidden;
    max-width: 40ch;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.typing {
    height: 20px;
    padding: 0 16px;
    overflow: hidden;
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    text-overflow: ellipsis;
}

.connection-banner {
    padding: 6px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #1e1f22;
    background: #f0b232;
}

.avatar-with-status {
    position: relative;
    display: inline-grid;
}

.presence {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 14px;
    height: 14px;
    background: var(--text-muted);
    border: 3px solid var(--bg-elevated);
    border-radius: 50%;
}

.presence.online {
    background: var(--ok);
}

.member.offline .avatar, .member.offline .user-name {
    opacity: 0.5;
}

.chat-error {
    padding: 0 16px;
}

.back-btn, .members-toggle, .drawer-backdrop {
    display: none;
}

.members-toggle {
    margin-left: auto;
}

.member {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 4px;
}

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

.member-menu {
    display: grid;
    gap: 2px;
    margin: 0 8px 8px 50px;
    padding: 4px;
    background: var(--bg);
    border-radius: 6px;
}

.member-menu button {
    padding: 6px 8px;
    font: inherit;
    font-size: 0.85rem;
    color: var(--text);
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}

.member-menu button:hover {
    color: white;
    background: var(--accent);
}

.member-menu .menu-danger {
    color: var(--danger);
}

.member-menu .menu-danger:hover {
    background: var(--danger);
}

.invites {
    margin: 0;
    padding: 0;
    list-style: none;
}

.invites li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.empty-state {
    display: grid;
    place-content: center;
    justify-items: center;
    padding: 24px;
    text-align: center;
    background: var(--bg-main);
}

.empty-state h1 {
    margin: 0;
}

/* Voice */

.voice-icon {
    flex: none;
    vertical-align: middle;
}

.voice-icon-slash, .voice-icon-off {
    color: var(--danger);
}

.voice-icon-off {
    opacity: 0.8;
}

.hash.voice-icon {
    margin: -2px 6px 0 0;
}

.voice-toggle.off {
    color: var(--danger);
}

.channel-item.voice-channel.connected a {
    color: var(--text);
}

/* Who's in a voice channel, under it in the channel list. */
.voice-people {
    margin: 0 0 4px;
    padding: 0 0 0 28px;
    list-style: none;
}

.voice-person {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 8px;
    font-size: 0.875rem;
    color: var(--text-muted);
    border-radius: 4px;
}

.voice-person:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.voice-person-avatar.avatar {
    width: 24px;
    height: 24px;
    font-size: 0.6rem;
}

.voice-person-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-flag {
    display: inline-flex;
    color: var(--text-muted);
}

/* A green ring while someone talks. */
.voice-person.speaking .avatar, .voice-tile.speaking .avatar {
    box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--ok);
}

/* "Voice connected", above the user panel. */
.voice-panel {
    padding: 8px 8px 8px 12px;
    background: #232428;
    border-bottom: 1px solid var(--border);
}

.voice-panel-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.voice-status {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 700;
}

.voice-status.good {
    color: var(--ok);
}

.voice-status.pending {
    color: #f0b232;
}

.voice-status.bad {
    color: var(--danger);
}

.voice-where {
    display: block;
    overflow: hidden;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-where:hover {
    color: var(--text);
    text-decoration: underline;
}

.voice-leave:hover {
    color: white;
    background: var(--danger);
}

.voice-error {
    margin: 6px 0 0;
    font-size: 0.8rem;
    color: var(--danger);
}

.voice-allow {
    width: 100%;
    margin-top: 8px;
}

.voice-panel-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* A voice channel's page. */
.voice-stage {
    display: grid;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
}

.voice-empty {
    align-self: center;
    justify-self: center;
    text-align: center;
}

.voice-empty h2 {
    margin: 0 0 4px;
}

.voice-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
    align-content: center;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.voice-tile-button {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    width: 100%;
    min-height: 136px;
    aspect-ratio: 16 / 10;
    padding: 12px;
    font: inherit;
    color: var(--text);
    background: var(--bg-elevated);
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
}

.voice-tile-button:disabled {
    cursor: default;
}

.voice-tile-button:hover:not(:disabled) {
    background: var(--bg-hover);
}

.voice-tile.speaking .voice-tile-button {
    box-shadow: inset 0 0 0 2px var(--ok);
}

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

.voice-tile-name {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-controls {
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 16px 16px max(16px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--bg);
}

.voice-control-row {
    display: flex;
    gap: 16px;
}

.voice-control {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    color: var(--text);
    background: var(--bg-active);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.voice-control:hover {
    background: #4e5058;
}

.voice-control.off {
    color: var(--danger);
}

.voice-control.leave {
    color: white;
    background: var(--danger);
}

.voice-control.leave:hover {
    background: #da373c;
}

.voice-join {
    min-width: 200px;
    padding: 12px 24px;
    font-size: 1rem;
}

/* Someone's volume, opened from them. */
.volume-menu {
    position: fixed;
    z-index: 10;
    display: grid;
    gap: 8px;
    width: 240px;
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
}

.volume-menu-title {
    font-weight: 700;
}

.volume-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.volume-row input {
    flex: 1;
    padding: 0;
    accent-color: var(--accent);
    background: transparent;
    border: 0;
}

.volume-value {
    width: 3.5em;
    font-size: 0.85rem;
    text-align: right;
    color: var(--text-muted);
}

/* Phones only (see below): the voice connection under a full-screen chat's header. */
.voice-strip {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 4px 8px 4px 16px;
    background: #232428;
    border-bottom: 1px solid var(--bg);
}

.voice-strip-link {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--ok);
    text-decoration: none;
}

.voice-strip-name {
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-strip .voice-status {
    overflow: hidden;
    font-weight: 400;
    color: var(--text-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-strip .voice-status.pending {
    color: #f0b232;
}

.device-names {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

/* A setting that's on or off. */
.switch-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: normal;
    text-transform: none;
    color: var(--text);
    cursor: pointer;
}

.switch-row input {
    flex: none;
    width: 18px;
    height: 18px;
    margin: 2px 0 0;
    accent-color: var(--accent);
}

.switch-row strong, .switch-row .hint {
    display: block;
}

.switch-row .hint {
    margin-top: 2px;
    font-size: 0.85rem;
}

/* Dialogs */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgb(0 0 0 / 0.6);
}

.modal {
    width: min(100%, 460px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 20px 24px;
    background: var(--bg-main);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgb(0 0 0 / 0.5);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.people {
    display: grid;
    gap: 2px;
    max-height: 50dvh;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
}

.person {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 6px 8px;
    font: inherit;
    color: var(--text);
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}

.person:hover:not(:disabled) {
    background: var(--bg-hover);
}

.person .user-name, .person .hint {
    display: block;
}

.person .hint {
    font-size: 0.75rem;
}

.person .presence {
    border-color: var(--bg-main);
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.push-left {
    margin-right: auto;
}

.input-prefix {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.input-prefix span {
    color: var(--text-muted);
}

.input-prefix input {
    border: 0;
}

.optional {
    font-weight: 400;
    text-transform: none;
}

/* Narrow screens: the member list becomes a drawer from the right, and a dimmed backdrop behind it closes it
   when tapped. Phones (700px and below, the width chat.js's watchPhone tells Viewport about) show one screen at a
   time. */

@media (max-width: 1000px) {
    .app {
        grid-template-columns: 72px 240px minmax(0, 1fr);
    }

    .members {
        position: fixed;
        inset: 0 0 0 auto;
        z-index: 20;
        width: min(280px, 85vw);
        transform: translateX(110%);
        transition: transform 0.2s;
        box-shadow: -8px 0 24px rgb(0 0 0 / 0.4);
    }

    .app.members-open .members {
        transform: none;
    }

    .members-toggle {
        display: inline-grid;
    }

    .app.members-open .drawer-backdrop {
        position: fixed;
        inset: 0;
        z-index: 15;
        display: block;
        background: rgb(0 0 0 / 0.5);
    }
}

@media (max-width: 700px) {
    /* A smaller tray leaves room for the conversation above the keyboard. */
    .upload {
        grid-template-rows: 56px auto auto;
        width: 112px;
    }

    .upload-thumb {
        height: 56px;
    }

    /* The rail and a list (the server's channels, or your conversations) fill the screen... */
    .app, .app.no-members {
        grid-template-columns: 72px minmax(0, 1fr);
    }

    .app:not(.chat-open) > .chat {
        display: none;
    }

    /* ...until a channel or conversation opens, full screen, with a back button to its list. */
    .app.chat-open {
        grid-template-columns: minmax(0, 1fr);
    }

    .app.chat-open > :is(.rail, .sidebar) {
        display: none;
    }

    .back-btn {
        display: inline-grid;
        flex: none;
        width: 40px;
        height: 40px;
        margin-left: -12px;
    }

    .members-toggle {
        flex: none;
        width: 40px;
        height: 40px;
        margin-right: -8px;
    }

    /* Just the name, as in Discord's app: a long one cuts off before the members button, and the topic stays out. */
    .chat-header h1 {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topic {
        display: none;
    }

    /* Nothing to hover on a touch screen, and no channel open beside the list: show every channel's ⚙. */
    .channel-edit {
        visibility: visible;
    }

    .voice-strip {
        display: flex;
    }

    /* Someone's volume opens as a sheet at the bottom, within thumb's reach. */
    .volume-menu {
        inset: auto 8px max(8px, env(safe-area-inset-bottom)) 8px !important;
        width: auto;
        transform: none !important;
    }

    .voice-tiles {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    /* Room for the conversation above the on-screen keyboard. */
    .mention-suggest {
        max-height: min(300px, 40dvh);
    }

    /* Installed on a phone with a home indicator, keep the rail and the user panel clear of it. */
    .rail {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .user-panel {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    padding: 0.75rem 1.25rem;
    background: var(--danger);
    color: white;
    z-index: 1000;
}

#blazor-error-ui .reload {
    color: white;
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 1rem;
    cursor: pointer;
}
