:root {
    color-scheme: dark;
    --bg: #0d0f14;
    --bg-alt: #141924;
    --bg-elevated: #1d2330;
    --panel: #151b26;
    --border: #2a3242;
    --text: #f4f6fb;
    --muted: #9aa4b2;
    --accent: #5b8cff;
    --accent-strong: #7c98ff;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
    --radius: 18px;
    --radius-sm: 12px;
}

[data-theme='light'] {
    color-scheme: light;
    --bg: #f5f7fb;
    --bg-alt: #ffffff;
    --bg-elevated: #eef2f7;
    --panel: #f2f5fa;
    --border: #d7dee8;
    --text: #111827;
    --muted: #6b7280;
    --accent: #3b82f6;
    --accent-strong: #1d4ed8;
    --shadow: 0 18px 60px rgba(15, 23, 42, 0.15);
}

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

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
}

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

button {
    cursor: pointer;
    border: none;
    background: none;
}

input,
textarea,
select {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
}

textarea {
    resize: none;
}

.app {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) 320px;
    height: 100vh;
}

.sidebar {
    background: var(--panel);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    border-right: 1px solid var(--border);
}

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

.brand h1 {
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.brand p {
    font-size: 0.85rem;
    color: var(--muted);
}

.brand-badge {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 600;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.user-meta {
    flex: 1;
}

.user-name {
    font-weight: 600;
}

.user-status {
    font-size: 0.85rem;
    color: var(--muted);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: var(--accent);
    font-weight: 600;
}

.avatar.mini {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    font-size: 0.85rem;
}

.icon-button {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    transition: transform 0.2s ease;
}

.icon-button:hover {
    transform: translateY(-1px);
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--muted);
}

.channel-list,
.dm-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.channel-button,
.dm-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: transparent;
}

.channel-button.active,
.dm-button.active {
    background: var(--bg-elevated);
    border-color: var(--border);
}

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

.channel-pill {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(91, 140, 255, 0.16);
    color: var(--accent);
}

.chat-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.chat-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: var(--bg-alt);
}

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

.channel-badge {
    display: inline-flex;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: var(--bg-elevated);
    align-items: center;
    justify-content: center;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.chat-search {
    display: none;
    gap: 12px;
    align-items: center;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-alt);
}

.chat-search.active {
    display: flex;
}

.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.message.system .message-content {
    border-style: dashed;
    color: var(--muted);
}

.message-content {
    flex: none;
    max-width: 85%;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--muted);
}

.message-author {
    color: var(--text);
    font-weight: 600;
}

.message-badges {
    display: inline-flex;
    gap: 6px;
}

.badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge.owner {
    background: rgba(249, 115, 22, 0.2);
    color: #f97316;
}

.message-body {
    white-space: pre-wrap;
    line-height: 1.5;
}

.message-actions {
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.typing-indicator {
    padding: 0 24px 8px;
    min-height: 24px;
    color: var(--muted);
    font-size: 0.85rem;
}

.composer {
    padding: 16px 24px 20px;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    border-top: 1px solid var(--border);
    background: var(--panel);
}

.composer-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.composer-input {
    flex: 1;
    position: relative;
}

.composer-input textarea {
    width: 100%;
    min-height: 48px;
}

.send-button {
    background: var(--accent);
    color: #fff;
    padding: 12px 18px;
    border-radius: 12px;
    font-weight: 600;
}

.composer-footer {
    padding: 0 24px 16px;
    color: var(--muted);
    font-size: 0.8rem;
}

.detail-panel {
    background: var(--panel);
    border-left: 1px solid var(--border);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
}

.detail-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.member-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
}

.member-meta {
    flex: 1;
}

.member-name {
    font-weight: 600;
}

.member-status {
    font-size: 0.8rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: var(--muted);
}

.status-online {
    background: var(--success);
}

.status-away {
    background: var(--warning);
}

.status-dnd {
    background: var(--danger);
}

.status-invisible {
    background: var(--border);
}

.pinned-item,
.activity-item {
    background: var(--bg-elevated);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pinned-author {
    font-weight: 600;
}

.pinned-text {
    color: var(--muted);
}

.pinned-time,
.activity-time {
    font-size: 0.75rem;
    color: var(--muted);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    padding: 24px;
    z-index: 20;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-alt);
    border-radius: var(--radius);
    padding: 24px;
    width: min(520px, 100%);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal.wide {
    width: min(960px, 100%);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.modal-subtitle {
    color: var(--muted);
    font-size: 0.9rem;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.form-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-label {
    font-size: 0.85rem;
    color: var(--muted);
}

.helper-text {
    font-size: 0.85rem;
    color: var(--muted);
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
    gap: 8px;
}

.avatar-option {
    display: grid;
    place-items: center;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    font-size: 1.1rem;
}

.avatar-option.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.2);
}

.ghost-button,
.primary-button,
.danger-button {
    border-radius: 12px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: transparent;
    color: inherit;
}

.primary-button {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.danger-button {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.4);
}

.ghost-button.small,
.danger-button.small {
    font-size: 0.75rem;
    padding: 4px 8px;
}

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

.blocked-chip {
    border-radius: 999px;
    border: 1px solid var(--border);
    padding: 6px 10px;
    background: var(--bg-elevated);
    margin-right: 6px;
    margin-top: 6px;
}

.moderation-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.moderation-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.report-card,
.moderation-user-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.report-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.75rem;
    color: var(--muted);
}

.report-message {
    font-size: 0.85rem;
    color: var(--muted);
}

.report-actions,
.moderation-user-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.moderation-user-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 30;
}

.toast {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: 12px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.hide {
    opacity: 0;
    transform: translateY(10px);
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 30px 0;
}

.muted {
    color: var(--muted);
    font-size: 0.85rem;
}

body:not([data-role='owner']) .owner-only {
    display: none;
}

body[data-chat-density='compact'] .message-content {
    padding: 8px 10px;
}

body[data-chat-density='compact'] .message-list {
    gap: 10px;
}

@media (max-width: 1100px) {
    .app {
        grid-template-columns: 240px 1fr;
    }

    .detail-panel {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        width: 320px;
        transform: translateX(100%);
        transition: transform 0.2s ease;
        z-index: 15;
    }

    body.show-detail .detail-panel {
        transform: translateX(0);
    }
}

@media (max-width: 860px) {
    .sidebar {
        padding: 18px 14px;
    }

    .chat-header,
    .composer,
    .message-list {
        padding-left: 16px;
        padding-right: 16px;
    }
}

@media (max-width: 720px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
    }
}
