:root {
    color-scheme: dark;
    --bg: #101214;
    --surface: #171b1f;
    --surface-2: #1e242a;
    --surface-3: #263039;
    --line: #313a43;
    --text: #f3f6f8;
    --muted: #9aa8b3;
    --primary: #45b7a6;
    --primary-strong: #38a08f;
    --accent: #f0b35b;
    --danger: #ee6a6a;
    --success: #58c986;
    --shadow: 0 20px 50px rgba(0, 0, 0, .28);
    --radius: 8px;
    --radius-sm: 6px;
    --content: 1040px;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 8%, rgba(69, 183, 166, .12), transparent 30%),
        linear-gradient(135deg, #101214 0%, #15181b 48%, #111315 100%);
    font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 64px;
    padding: 0 22px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    background: rgba(16, 18, 20, .88);
    backdrop-filter: blur(16px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 800;
    font-size: 18px;
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    color: #08110f;
    background: linear-gradient(135deg, var(--primary), var(--accent));
}

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

.nav-link,
.side-link {
    text-decoration: none;
}

.nav-link {
    min-height: 36px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--muted);
}

.nav-link:hover {
    color: var(--text);
    background: rgba(255, 255, 255, .06);
}

.app-body {
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr);
    min-height: calc(100vh - 64px);
}

.sidebar {
    position: sticky;
    top: 64px;
    height: calc(100vh - 64px);
    padding: 18px 14px;
    border-right: 1px solid rgba(255, 255, 255, .08);
    background: rgba(17, 20, 23, .72);
}

.side-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    margin-bottom: 6px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--muted);
}

.side-link:hover,
.side-link.is-active {
    color: var(--text);
    background: var(--surface-2);
}

.side-link.is-active {
    box-shadow: inset 3px 0 0 var(--primary);
}

.side-icon {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    color: var(--primary);
}

.content {
    width: 100%;
    min-width: 0;
    padding: 28px;
}

.page,
.profile-page,
.feed-page,
.users-page,
.admin-page,
.auth-page {
    width: min(100%, var(--content));
    margin: 0 auto;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}

.page-title {
    margin: 0;
    font-size: 28px;
    line-height: 1.12;
}

.card > .page-title,
.auth-card h2 {
    font-size: 24px;
}

.page-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.45;
}

.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(300px, .9fr);
    gap: 18px;
    align-items: start;
}

.section-stack {
    margin-top: 18px;
}

.card,
.profile-card,
.post-card,
.user-card,
.auth-card,
.admin-card {
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.015)), var(--surface);
    box-shadow: var(--shadow);
}

.card,
.auth-card,
.admin-card {
    padding: 20px;
}

.profile-card {
    padding: 22px;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 18px;
}

.profile-avatar-container,
.avatar-wrap {
    flex: 0 0 auto;
}

.avatar {
    display: block;
    width: 88px;
    height: 88px;
    border: 2px solid rgba(255, 255, 255, .12);
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-3);
}

.avatar-sm {
    width: 48px;
    height: 48px;
}

.profile-info {
    min-width: 0;
}

.profile-info h2,
.profile-info h1 {
    margin: 0 0 8px;
    font-size: 26px;
    line-height: 1.15;
}

.profile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    color: var(--muted);
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: var(--radius-sm);
    color: var(--muted);
    background: rgba(255, 255, 255, .04);
    font-size: 13px;
}

.profile-description,
.empty-state {
    margin-top: 16px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: var(--radius);
    color: var(--muted);
    background: rgba(255, 255, 255, .035);
    line-height: 1.5;
}

.actions,
.button-container,
.edit-buttons,
.post-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.btn,
.button,
.action-button,
.submit-button,
.search-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text);
    background: var(--surface-3);
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
    transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.btn:hover,
.button:hover,
.action-button:hover,
.submit-button:hover,
.search-button:hover {
    transform: translateY(-1px);
    background: #303b45;
}

.btn-primary,
.submit-button,
.search-button {
    color: #07110f;
    background: var(--primary);
}

.btn-primary:hover,
.submit-button:hover,
.search-button:hover {
    background: var(--primary-strong);
}

.btn-secondary {
    border-color: rgba(255, 255, 255, .1);
    background: rgba(255, 255, 255, .06);
}

.btn-danger,
.delete-post-button {
    background: rgba(238, 106, 106, .18);
    color: #ffdede;
}

.btn-sm {
    min-height: 34px;
    padding: 8px 11px;
    font-size: 14px;
}

.form-card,
.edit-form,
.post-form,
.login-form,
.registration-form,
.search-form {
    display: grid;
    gap: 12px;
}

.form-group {
    display: grid;
    gap: 7px;
}

label {
    color: var(--muted);
    font-size: 14px;
}

input[type="text"],
input[type="password"],
input[type="color"],
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    background: rgba(255, 255, 255, .055);
    outline: none;
}

textarea {
    min-height: 118px;
    resize: vertical;
    line-height: 1.45;
}

input:focus,
textarea:focus {
    border-color: rgba(69, 183, 166, .8);
    box-shadow: 0 0 0 3px rgba(69, 183, 166, .14);
}

.color-inputs {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
}

.avatar-form {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.post-list,
.user-list,
.chat-list {
    display: grid;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.post-card {
    padding: 16px;
}

.post-card:hover,
.user-card:hover {
    border-color: rgba(69, 183, 166, .3);
}

.post-header,
.user-info-link,
.chat-user-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.post-user-info,
.user-info,
.chat-user-info {
    min-width: 0;
}

.username-link,
.user-name {
    color: var(--text);
    font-weight: 800;
    text-decoration: none;
}

.username-link:hover {
    color: var(--primary);
}

.timestamp,
.user-id {
    color: var(--muted);
    font-size: 13px;
}

.post-content {
    margin-top: 12px;
    color: #dfe7eb;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.user-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px;
}

.search-form {
    grid-template-columns: minmax(0, 1fr) auto;
    margin-bottom: 18px;
}

.auth-page {
    display: grid;
    min-height: calc(100vh - 120px);
    place-items: center;
}

.auth-card {
    width: min(100%, 420px);
}

.auth-card h2 {
    margin: 0 0 18px;
    font-size: 26px;
}

.auth-link {
    display: block;
    margin-top: 14px;
    color: var(--primary);
    text-align: center;
    text-decoration: none;
}

.auth-link:hover {
    text-decoration: underline;
}

.flash-stack {
    width: min(100%, var(--content));
    margin: 0 auto 16px;
}

.flash {
    margin-bottom: 10px;
    padding: 12px 14px;
    border-radius: var(--radius);
    color: var(--text);
}

.flash.success {
    background: rgba(88, 201, 134, .18);
    border: 1px solid rgba(88, 201, 134, .32);
}

.flash.danger {
    background: rgba(238, 106, 106, .18);
    border: 1px solid rgba(238, 106, 106, .32);
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.admin-list {
    display: grid;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.admin-form {
    display: grid;
    gap: 10px;
}

.chat-page {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: calc(100vh - 120px);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: var(--radius);
    background: var(--surface);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    background: var(--surface-2);
}

#chat-window {
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
}

#chat-messages {
    display: grid;
    gap: 10px;
}

.msg {
    max-width: min(72%, 620px);
    padding: 12px 14px;
    border-radius: var(--radius);
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.sent {
    justify-self: end;
    color: #07110f;
    background: var(--primary);
}

.received {
    justify-self: start;
    background: var(--surface-3);
}

#chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, .08);
    background: var(--surface-2);
}

#message-input {
    min-height: 46px;
    max-height: 140px;
}

#attachment-name,
.media-name {
    grid-column: 1 / -1;
    min-height: 18px;
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.attachment {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    margin-top: 8px;
    color: var(--text);
    text-decoration: none;
    overflow-wrap: anywhere;
}

.attachment-file {
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .06);
}

.attachment img,
.attachment video,
.post-image,
.post-video {
    display: block;
    max-width: min(100%, 520px);
    max-height: 420px;
    border-radius: var(--radius);
    object-fit: contain;
}

.attachment audio,
.post-audio {
    width: min(100%, 520px);
}

.post-media {
    margin-top: 12px;
}

.post-meta {
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
}

.post-comments {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.comment-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .05);
}

.comment-header {
    margin-bottom: 4px;
    font-weight: 800;
}

.comment-timestamp {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.comment-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-top: 12px;
}

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

    .sidebar {
        position: sticky;
        top: 64px;
        z-index: 15;
        display: flex;
        gap: 8px;
        height: auto;
        padding: 10px 14px;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid rgba(255, 255, 255, .08);
    }

    .side-link {
        flex: 0 0 auto;
        margin-bottom: 0;
    }

    .content {
        padding: 18px;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 620px) {
    .topbar {
        height: auto;
        min-height: 64px;
        padding: 12px 14px;
        align-items: flex-start;
    }

    .topnav {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .page-header,
    .profile-header,
    .user-card {
        align-items: flex-start;
        flex-direction: column;
    }

    .search-form,
    #chat-form,
    .comment-form {
        grid-template-columns: 1fr;
    }

    .btn,
    .button,
    .action-button,
    .submit-button,
    .search-button {
        width: 100%;
    }

    .avatar {
        width: 76px;
        height: 76px;
    }

    .avatar-sm {
        width: 48px;
        height: 48px;
    }

    .msg {
        max-width: 88%;
    }
}
