:root {
    color-scheme: dark;
    --bg: #101214;
    --panel: #171a1f;
    --panel-2: #1f242b;
    --text: #eef2f6;
    --muted: #9aa4b2;
    --line: #303740;
    --accent: #35b89d;
    --accent-dark: #23927c;
    --mine: #16352f;
    --error: #ff8f85;
    --success: #84d99a;
    --input-bg: #101418;
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f6f7f8;
    --panel: #ffffff;
    --panel-2: #f0f3f5;
    --text: #202327;
    --muted: #667085;
    --line: #d8dde3;
    --accent: #1f7a68;
    --accent-dark: #15594c;
    --mine: #e7f4ef;
    --error: #b42318;
    --success: #157347;
    --input-bg: #ffffff;
}

* {
    box-sizing: border-box;
}

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

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

button,
.ghost-button {
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    padding: 0 18px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

button:hover,
.ghost-button:hover {
    background: var(--accent-dark);
}

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

input[type="file"] {
    color: var(--muted);
}

textarea {
    min-height: 92px;
    resize: vertical;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-panel {
    width: min(100%, 420px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
}

.auth-logo {
    display: block;
    height: 132px;
    margin: 0 auto 24px;
    object-fit: contain;
    width: 132px;
}

.auth-panel h1,
.topbar h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.1;
}

.stack {
    display: grid;
    gap: 14px;
    margin-top: 20px;
}

.stack label {
    display: grid;
    gap: 8px;
    font-weight: 700;
}

.muted,
.switch,
.status,
.file-name {
    color: var(--muted);
}

.notice {
    border-radius: 8px;
    margin-top: 18px;
    padding: 12px;
}

.notice.error {
    background: #341b1d;
    color: var(--error);
}

.notice.success {
    background: #183323;
    color: var(--success);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    padding: 18px clamp(16px, 4vw, 48px);
}

.brand-block {
    align-items: center;
    display: flex;
    gap: 12px;
    min-width: 0;
}

.topbar-logo {
    height: 48px;
    object-fit: contain;
    width: 48px;
}

.top-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.status-select-label {
    align-items: center;
    display: flex;
    gap: 8px;
}

.status-select-label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.status-select {
    min-height: 42px;
    padding: 0 36px 0 12px;
    width: auto;
}

.topbar p {
    margin: 6px 0 0;
}

.ghost-button {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
}

.theme-toggle {
    align-items: center;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    height: 44px;
    justify-content: center;
    min-height: 44px;
    padding: 0;
    position: fixed;
    bottom: 18px;
    right: 18px;
    width: 44px;
    z-index: 30;
}

.webmail-button {
    align-items: center;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    bottom: 18px;
    color: var(--text);
    display: inline-flex;
    height: 44px;
    justify-content: center;
    position: fixed;
    right: 72px;
    text-decoration: none;
    width: 44px;
    z-index: 30;
}

.webmail-button:hover {
    background: var(--line);
}

.webmail-button::before {
    content: "✉";
    font-size: 21px;
    line-height: 1;
}

.theme-toggle:hover {
    background: var(--line);
}

.theme-toggle::before {
    content: "☀";
    font-size: 22px;
    line-height: 1;
}

:root[data-theme="light"] .theme-toggle::before {
    content: "☾";
}

.chat-layout {
    width: min(100%, 1180px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 16px;
    padding: 16px;
}

.chat-main {
    display: grid;
    gap: 16px;
    grid-template-rows: auto 1fr;
    min-width: 0;
}

.app-tabs {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 6px;
    padding: 6px;
}

.tab-button {
    background: transparent;
    border-radius: 8px;
    color: var(--muted);
    min-height: 38px;
    padding: 0 14px;
}

.tab-button:hover,
.tab-button.is-active {
    background: var(--panel-2);
    color: var(--text);
}

.tab-panel {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.tab-panel[hidden] {
    display: none;
}

.conversation {
    min-height: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.messages {
    height: calc(100vh - 250px);
    min-height: 360px;
    overflow: auto;
    padding: 18px;
}

.online-panel {
    align-self: start;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.online-panel-head {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    padding: 14px;
}

.online-panel-head h2 {
    font-size: 16px;
    margin: 0;
}

.online-panel-head span {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    display: inline-grid;
    font-size: 13px;
    min-width: 28px;
    padding: 3px 8px;
    place-items: center;
}

.online-users {
    display: grid;
    gap: 6px;
    padding: 10px;
}

.online-users.is-empty::before {
    content: attr(data-empty);
    color: var(--muted);
    display: block;
    padding: 14px 4px;
    text-align: center;
}

.online-user {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    display: grid;
    gap: 10px;
    grid-template-columns: 38px 1fr;
    min-height: auto;
    padding: 8px;
    text-align: left;
    width: 100%;
}

.online-user:hover {
    background: var(--panel-2);
}

.online-user strong,
.online-user small {
    display: block;
    overflow-wrap: anywhere;
}

.online-user small {
    color: var(--muted);
    margin-top: 2px;
}

.online-user .online-status,
.profile-status {
    align-items: center;
    display: inline-flex;
    gap: 9px;
}

.online-user .online-status::before,
.profile-status::before {
    border-radius: 50%;
    content: "";
    display: inline-block;
    height: 8px;
    width: 8px;
}

.online-user .online-status {
    margin-top: 7px;
}

.profile-status {
    color: var(--muted);
    font-weight: 700;
    margin: 10px 0 0;
}

.status-online::before {
    background: #36d399;
}

.status-away::before {
    background: #fbbf24;
}

.status-dnd::before {
    background: #f87171;
}

.status-focused::before {
    background: #60a5fa;
}

.online-avatar {
    background: #26323b;
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--accent);
    display: grid;
    font-size: 14px;
    font-weight: 800;
    height: 38px;
    object-fit: cover;
    overflow: hidden;
    place-items: center;
    width: 38px;
}

.messages.is-empty::before {
    content: attr(data-empty);
    color: var(--muted);
    display: block;
    padding: 24px 0;
    text-align: center;
}

.message {
    width: min(76%, 640px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    margin-bottom: 12px;
    padding: 12px;
}

.message.mine {
    margin-left: auto;
    background: var(--mine);
}

.message-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

.message-meta strong {
    color: var(--text);
}

.message-meta strong span {
    color: var(--muted);
    font-weight: 600;
}

.message-head {
    align-items: flex-start;
    display: grid;
    gap: 10px;
    grid-template-columns: 42px 1fr;
}

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

.message-avatar,
.profile-avatar {
    background: #26323b;
    border: 1px solid var(--line);
    color: var(--accent);
    display: grid;
    font-weight: 800;
    overflow: hidden;
    place-items: center;
}

.profile-trigger,
.profile-name {
    background: transparent;
    border: 0;
    color: inherit;
    cursor: pointer;
    display: inline;
    font: inherit;
    min-height: auto;
    padding: 0;
    text-align: left;
}

.profile-trigger {
    border-radius: 50%;
    display: grid;
    height: 42px;
    place-items: center;
    width: 42px;
}

.profile-name:hover strong,
.profile-trigger:hover + .message-main .profile-name strong {
    color: var(--accent);
}

.profile-trigger:hover,
.profile-name:hover {
    background: transparent;
}

.message-avatar {
    border-radius: 50%;
    height: 42px;
    width: 42px;
}

img.message-avatar,
.profile-avatar img {
    object-fit: cover;
}

.message p {
    margin: 10px 0 0;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.attachment {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    margin-top: 10px;
    padding: 10px;
    text-decoration: none;
}

.attachment:hover {
    border-color: var(--accent);
}

.attachment-icon {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: #203b36;
    color: var(--accent);
    display: grid;
    font-size: 11px;
    font-weight: 800;
    place-items: center;
}

.attachment strong,
.attachment small {
    display: block;
    overflow-wrap: anywhere;
}

.attachment small {
    color: var(--muted);
    margin-top: 3px;
}

.composer {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.panel-box,
.topic-form,
.document-form {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.topic-form,
.document-form {
    display: grid;
    gap: 12px;
}

.topic-form label,
.document-form label {
    display: grid;
    gap: 8px;
    font-weight: 700;
}

.panel-head {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: -14px -14px 14px;
    padding: 14px;
}

.panel-head h2 {
    font-size: 18px;
    margin: 0;
}

.compact-button {
    min-height: 34px;
    padding: 0 12px;
}

.item-list {
    display: grid;
    gap: 10px;
}

.item-list.is-empty::before {
    content: attr(data-empty);
    color: var(--muted);
    display: block;
    padding: 20px 4px;
    text-align: center;
}

.list-item {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.list-title,
.list-item h3 {
    color: var(--text);
    font-size: 17px;
    font-weight: 800;
    margin: 0;
    overflow-wrap: anywhere;
    text-decoration: none;
}

.list-title:hover {
    color: var(--accent);
}

.list-item p {
    line-height: 1.45;
    margin: 8px 0 0;
    overflow-wrap: anywhere;
}

.muted-link {
    color: var(--muted);
    display: inline-flex;
    margin-top: 8px;
}

.profile-layout {
    width: min(100%, 980px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(280px, 380px) 1fr;
    gap: 16px;
    padding: 16px;
}

.profile-preview,
.profile-form-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.profile-form-panel {
    padding: 18px;
}

.profile-banner {
    background: linear-gradient(135deg, #23313b, #173d36);
    background-position: center;
    background-size: cover;
    height: 150px;
}

.profile-card-body {
    padding: 0 18px 22px;
}

.profile-avatar {
    border-radius: 16px;
    height: 96px;
    margin-top: -48px;
    width: 96px;
}

.profile-avatar img {
    height: 100%;
    width: 100%;
}

.profile-avatar span {
    font-size: 42px;
}

.profile-card-body h2 {
    margin: 14px 0 4px;
}

.profile-description {
    border-top: 1px solid var(--line);
    line-height: 1.5;
    margin: 18px 0 0;
    overflow-wrap: anywhere;
    padding-top: 16px;
}

.profile-modal[hidden] {
    display: none;
}

.profile-modal {
    inset: 0;
    position: fixed;
    z-index: 40;
}

.profile-modal-backdrop {
    background: rgba(0, 0, 0, 0.66);
    inset: 0;
    position: absolute;
}

.profile-modal-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    left: 50%;
    max-height: calc(100vh - 40px);
    overflow: auto;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 560px);
}

.profile-modal-banner {
    height: 190px;
}

.profile-modal-avatar {
    height: 112px;
    margin-top: -56px;
    width: 112px;
}

.modal-close {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    height: 36px;
    position: absolute;
    right: 12px;
    top: 12px;
    width: 36px;
    z-index: 2;
}

.modal-close:hover {
    background: var(--panel-2);
}

.modal-open {
    overflow: hidden;
}

.composer-actions {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-top: 12px;
}

.file-picker input {
    clip: rect(0 0 0 0);
    height: 1px;
    overflow: hidden;
    position: absolute;
    width: 1px;
}

.file-picker span {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
}

.file-name,
.status {
    min-height: 20px;
    margin-top: 8px;
    font-size: 14px;
}

@media (max-width: 680px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .top-actions {
        width: 100%;
    }

    .app-tabs {
        overflow-x: auto;
    }

    .tab-button {
        flex: 1 0 auto;
    }

    .status-select-label {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .status-select {
        width: 100%;
    }

    .messages {
        height: calc(100vh - 320px);
        min-height: 300px;
        padding: 12px;
    }

    .chat-layout {
        grid-template-columns: 1fr;
    }

    .online-panel {
        order: -1;
    }

    .message {
        width: 100%;
    }

    .message-head {
        grid-template-columns: 36px 1fr;
    }

    .message-avatar {
        height: 36px;
        width: 36px;
    }

    .profile-trigger {
        height: 36px;
        width: 36px;
    }

    .composer-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .file-picker span,
    button,
    .ghost-button {
        width: 100%;
    }

    .theme-toggle {
        width: 44px;
    }

    .webmail-button {
        width: 44px;
    }

    .modal-close {
        width: 36px;
    }

    .profile-trigger {
        width: 36px;
    }

    .profile-name {
        width: auto;
    }

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