* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    margin: 0;
    font-family: Inter, system-ui, Arial, sans-serif;
    background: #111318;
    color: #e9eaf0;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
    border: 0;
}

.hidden {
    display: none !important;
}

/* =============================
   LANDING / AUTH
============================= */

.landing {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(
            circle at top,
            #272c3d,
            #101116 55%
        );
}

.auth-card {
    width: min(430px, 92vw);
    background: #181a21;
    border: 1px solid #2b2e39;
    border-radius: 22px;
    padding: 30px;
    box-shadow: 0 25px 80px #0008;
}

.brand {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 26px;
}

.brand span,
.logo {
    display: grid;
    place-items: center;
    background: #6c5ce7;
    color: white;
    border-radius: 13px;
    width: 48px;
    height: 48px;
    font-size: 24px;
}

.brand h1 {
    margin: 0;
}

.brand p {
    margin: 3px 0;
    color: #9297a8;
}

.tab {
    background: none;
    color: #8e93a5;
    padding: 12px 4px;
    margin-right: 20px;
}

.tab.active {
    color: white;
    border-bottom: 2px solid #7c6df2;
}

.auth-card label,
.modal-card label {
    display: block;
    color: #aeb3c2;
    font-size: 13px;
    margin: 16px 0;
}

.auth-card input,
.modal-card input,
.modal-card textarea,
.modal-card select,
.search-row input,
.composer input {
    width: 100%;
    margin-top: 7px;
    background: #0f1116;
    color: #fff;
    border: 1px solid #303441;
    border-radius: 10px;
    padding: 12px;
    outline: none;
}

.auth-card input:focus,
.modal-card input:focus,
.modal-card textarea:focus,
.modal-card select:focus,
.search-row input:focus,
.composer input:focus {
    border-color: #6c5ce7;
    box-shadow: 0 0 0 2px #6c5ce722;
}

.primary {
    background: #6c5ce7;
    color: white;
    padding: 11px 16px;
    border-radius: 10px;
    font-weight: 700;
}

.primary:hover {
    background: #7b6cf0;
}

.secondary {
    background: #292d37;
    color: #e8e9ee;
    padding: 10px 14px;
    border-radius: 10px;
}

.secondary:hover {
    background: #343946;
}

.wide {
    width: 100%;
    margin-top: 10px;
}

.small {
    padding: 8px 11px;
    font-size: 12px;
}

.guest-box {
    border-top: 1px solid #2a2d37;
    margin-top: 22px;
    padding-top: 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #8e93a5;
    font-size: 13px;
}

/* =============================
   APP
============================= */

.app {
    display: grid;
    grid-template-columns: 72px 250px minmax(0, 1fr);
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* =============================
   RAIL
============================= */

.rail {
    background: #0c0e12;
    padding: 14px 11px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.rail-btn {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: #1a1d25;
    color: #aab0c0;
    font-size: 20px;
    transition: 0.15s ease;
}

.rail-btn.active,
.rail-btn:hover {
    background: #6c5ce7;
    color: #fff;
    transform: translateY(-1px);
}

.rail-spacer {
    flex: 1;
}

/* =============================
   SIDEBAR
============================= */

.sidebar {
    background: #171920;
    border-right: 1px solid #292c35;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.side-top {
    height: 65px;
    min-height: 65px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #292c35;
}

.side-top button {
    background: #292d37;
    color: white;
    border-radius: 8px;
    font-size: 20px;
    width: 32px;
    height: 32px;
}

.side-top button:hover {
    background: #6c5ce7;
}

.side-label {
    font-size: 10px;
    color: #73798a;
    font-weight: 800;
    letter-spacing: 1px;
    padding: 18px 15px 8px;
}

.side-item {
    padding: 9px 13px;
    margin: 2px 8px;
    border-radius: 8px;
    color: #c8cad3;
    display: flex;
    gap: 9px;
    align-items: center;
    transition: 0.15s ease;
}

.side-item:hover {
    background: #252934;
    color: white;
}

.profile-mini {
    margin-top: auto;
    border-top: 1px solid #292c35;
    padding: 12px;
    display: flex;
    gap: 9px;
    align-items: center;
}

.profile-mini > div:nth-child(2) {
    flex: 1;
    min-width: 0;
}

.profile-mini small,
.info small {
    display: block;
    color: #7f8596;
    font-size: 11px;
}

.profile-mini button {
    background: none;
    color: #858b9c;
}

/* =============================
   AVATARS
============================= */

.avatar,
.message-avatar {
    display: grid;
    place-items: center;
    background: #6c5ce7;
    border-radius: 50%;
    font-weight: 800;
    color: white;
    flex-shrink: 0;
}

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

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

/* =============================
   MAIN
============================= */

.main {
    min-width: 0;
    min-height: 0;
    background: #111318;
    overflow: hidden;
}

.topbar {
    height: 65px;
    min-height: 65px;
    border-bottom: 1px solid #292c35;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.topbar small {
    color: #7e8494;
    margin-left: 8px;
}

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

.icon-btn {
    position: relative;
    background: #20232c;
    color: white;
    border-radius: 10px;
    padding: 10px;
}

.icon-btn:hover {
    background: #292d38;
}

.badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #f05b6d;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
}

/* =============================
   HOME
============================= */

.hero,
.page {
    padding: 40px;
    max-width: 1000px;
}

.hero {
    margin: auto;
    padding-top: 90px;
}

.eyebrow {
    font-size: 11px;
    color: #7c6df2;
    font-weight: 800;
    letter-spacing: 2px;
}

.hero h1 {
    font-size: 44px;
    margin: 10px 0;
}

.hero p,
.page p {
    color: #8e93a5;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-top: 35px;
}

.feature {
    text-align: left;
    background: #191c24;
    border: 1px solid #2b2f3b;
    border-radius: 15px;
    padding: 20px;
    color: white;
    transition: 0.15s ease;
}

.feature:hover {
    border-color: #6c5ce7;
    transform: translateY(-2px);
}

.feature span {
    display: block;
    color: #858b9b;
    font-size: 13px;
    margin-top: 8px;
}

/* =============================
   FRIENDS
============================= */

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.search-row {
    display: flex;
    gap: 8px;
    margin: 20px 0;
}

.stack {
    display: grid;
    gap: 8px;
}

.person-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #191c24;
    border: 1px solid #292d38;
    padding: 12px;
    border-radius: 12px;
}

.person-card .info {
    flex: 1;
    min-width: 0;
}

.actions {
    display: flex;
    gap: 6px;
}

.actions button {
    padding: 7px 10px;
    border-radius: 8px;
}

/* =============================
   DM / ROOM
============================= */

.view {
    width: 100%;
    height: calc(100vh - 65px);
    min-height: 0;
    overflow: hidden;
}

.dm-layout,
.room-layout {
    display: grid;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.dm-layout {
    grid-template-columns: 240px minmax(0, 1fr);
}

.dm-list,
.members {
    min-width: 0;
    min-height: 0;
    border-right: 1px solid #292c35;
    padding: 18px;
    overflow-y: auto;
}

.dm-list h3,
.members h3 {
    margin-top: 0;
    margin-bottom: 14px;
}

.dm-chat,
.room-chat {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* =============================
   MESSAGE SCROLLER
============================= */

.messages {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: 0;

    overflow-x: hidden;
    overflow-y: auto;

    padding: 16px;

    display: block;
}

.messages::-webkit-scrollbar,
.dm-list::-webkit-scrollbar,
.members::-webkit-scrollbar {
    width: 7px;
}

.messages::-webkit-scrollbar-track,
.dm-list::-webkit-scrollbar-track,
.members::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb,
.dm-list::-webkit-scrollbar-thumb,
.members::-webkit-scrollbar-thumb {
    background: #303440;
    border-radius: 10px;
}

/* =============================
   NORMAL ROOM MESSAGE
============================= */

.message {
    display: grid;

    grid-template-columns: 36px minmax(0, 1fr);

    column-gap: 10px;

    width: 100%;
    height: auto;
    min-height: 0;

    margin: 0 0 18px 0;
    padding: 0;

    align-items: start;
}

.message:last-child {
    margin-bottom: 0;
}

/* =============================
   DM MESSAGE — HARD FIX
============================= */

#dm-messages {
    display: block !important;
    padding: 16px !important;

    /* NEVER distribute messages */
    justify-content: normal !important;
    align-content: normal !important;
    align-items: normal !important;
}

#dm-messages > .message,
.dm-chat #dm-messages > .message {
    display: grid !important;

    grid-template-columns: 36px minmax(0, 1fr) !important;

    grid-template-rows: auto !important;

    column-gap: 10px !important;
    row-gap: 0 !important;

    width: 100% !important;

    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;

    margin: 0 0 9px 0 !important;
    padding: 0 !important;

    align-items: start !important;
    align-content: start !important;
    justify-content: start !important;
}

#dm-messages > .message:last-child {
    margin-bottom: 0 !important;
}

/* =============================
   DM AVATAR
============================= */

#dm-messages .message-avatar {
    grid-column: 1 !important;
    grid-row: 1 !important;

    width: 36px !important;
    height: 36px !important;

    min-width: 36px !important;
    max-width: 36px !important;

    min-height: 36px !important;
    max-height: 36px !important;

    margin: 0 !important;
    padding: 0 !important;

    align-self: start !important;
}

/* =============================
   DM BODY
============================= */

#dm-messages .message-body {
    grid-column: 2 !important;
    grid-row: 1 !important;

    display: block !important;

    width: 100% !important;

    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;

    margin: 0 !important;
    padding: 0 !important;

    align-self: start !important;
}

/* =============================
   DM HEADER
============================= */

#dm-messages .message-head {
    display: flex !important;

    flex-direction: row !important;

    align-items: baseline !important;
    justify-content: flex-start !important;

    width: 100% !important;

    height: 18px !important;
    min-height: 18px !important;
    max-height: 18px !important;

    margin: 0 !important;
    padding: 0 !important;

    gap: 8px !important;

    line-height: 18px !important;
}

#dm-messages .message-head b {
    display: inline !important;

    margin: 0 !important;
    padding: 0 !important;

    height: 18px !important;

    line-height: 18px !important;

    color: #fff;
}

#dm-messages .message-head time {
    display: inline !important;

    margin: 0 !important;
    padding: 0 !important;

    height: 16px !important;

    font-size: 11px;
    line-height: 16px !important;

    color: #707687;
}

/* =============================
   DM TEXT
============================= */

#dm-messages .message-text {
    display: block !important;

    width: 100% !important;

    height: auto !important;
    min-height: 19px !important;
    max-height: none !important;

    margin: 1px 0 0 0 !important;
    padding: 0 !important;

    white-space: pre-wrap !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;

    color: #d9dbe2;

    font-size: 14px;
    line-height: 19px !important;

    text-align: left !important;
}

/* =============================
   DM ACTIONS
============================= */

#dm-messages .message-actions {
    display: flex !important;

    flex-direction: row !important;

    align-items: center !important;
    justify-content: flex-start !important;

    width: 100% !important;

    height: 20px !important;
    min-height: 20px !important;
    max-height: 20px !important;

    margin: 1px 0 0 0 !important;
    padding: 0 !important;

    gap: 2px !important;
}

#dm-messages .message-actions button {
    display: inline-flex !important;

    align-items: center !important;
    justify-content: center !important;

    width: auto !important;

    height: 20px !important;
    min-height: 20px !important;
    max-height: 20px !important;

    margin: 0 !important;
    padding: 1px 4px !important;

    background: transparent;

    color: #7f8495;

    font-size: 12px;
    line-height: 18px !important;
}

#dm-messages .message-actions button:hover {
    background: #242832;
    color: white;
}

/* =============================
   REACTIONS
============================= */

.reactions {
    display: flex;
    gap: 5px;
    margin-top: 5px;
    flex-wrap: wrap;
}

.reaction {
    background: #242833;
    border: 1px solid #353a47;
    border-radius: 9px;
    padding: 3px 7px;
    font-size: 12px;
}

/* =============================
   REPLIES
============================= */

.reply-preview {
    border-left: 2px solid #6c5ce7;
    color: #8f95a7;
    font-size: 12px;
    padding-left: 8px;
    margin: 4px 0;
}

.reply-bar {
    margin: 0 16px;
    padding: 8px 10px;
    background: #1c1f28;
    border-left: 3px solid #6c5ce7;
    color: #aeb3c0;
    font-size: 12px;
}

.reply-bar button {
    float: right;
    background: none;
    color: white;
    font-size: 18px;
}

/* =============================
   COMPOSER
============================= */

.composer {
    flex: 0 0 auto;

    width: 100%;

    padding: 12px 16px;

    border-top: 1px solid #292c35;

    display: flex;
    gap: 8px;
    align-items: center;

    background: #111318;
}

.composer input {
    margin: 0;
    flex: 1;
    min-width: 0;
}

.composer button {
    flex: 0 0 auto;
}

.composer span {
    font-size: 10px;
    color: #676d7d;
    white-space: nowrap;
}

.typing {
    height: 22px;
    min-height: 22px;
    padding: 0 20px;
    color: #858b9a;
    font-size: 12px;
}

/* =============================
   EMPTY
============================= */

.empty-state {
    margin: auto;
    text-align: center;
    color: #7f8595;
    padding: 30px;
}

.empty-state h2 {
    color: white;
}

.muted {
    color: #747a8b;
    font-size: 13px;
}

/* =============================
   MODALS
============================= */

.modal {
    position: fixed;
    inset: 0;

    background: #0009;

    display: grid;
    place-items: center;

    z-index: 10;
    padding: 20px;
}

.modal-card {
    position: relative;

    background: #191c24;
    border: 1px solid #303441;
    border-radius: 16px;

    padding: 25px;

    width: min(450px, 92vw);
    max-height: 90vh;

    overflow-y: auto;
}

.modal-card h2 {
    margin-top: 0;
}

.modal-card textarea {
    min-height: 100px;
    resize: vertical;
}

.x {
    position: absolute;
    right: 12px;
    top: 12px;

    background: none;
    color: #8f95a5;

    font-size: 22px;
}

.x:hover {
    color: white;
}

.check {
    display: flex !important;
    align-items: center;
    gap: 9px;
}

.check input {
    width: auto !important;
    margin: 0 !important;
}

/* =============================
   NOTIFICATIONS
============================= */

.popover {
    position: fixed;

    right: 18px;
    top: 62px;

    width: 340px;
    max-height: 70vh;

    overflow: auto;

    background: #191c24;

    border: 1px solid #303441;
    border-radius: 14px;

    z-index: 9;

    box-shadow: 0 15px 50px #0008;
}

.popover-head {
    padding: 12px 14px;

    border-bottom: 1px solid #2b2e38;

    display: flex;
    justify-content: space-between;
}

.popover-head button {
    background: none;
    color: #8d93a4;
    font-size: 11px;
}

.notification {
    padding: 12px 14px;
    border-bottom: 1px solid #292c35;
    font-size: 13px;
}

.notification.unread {
    background: #202431;
}

.notification small {
    display: block;
    color: #717789;
    margin-top: 5px;
}

.error {
    color: #ff7282;
    font-size: 12px;
    min-height: 16px;
}

/* =============================
   LIGHT THEME
============================= */

[data-theme="light"] {
    background: #f2f3f7;
    color: #171920;
}

[data-theme="light"] .main,
[data-theme="light"] .landing {
    background: #eef0f5;
}

[data-theme="light"] .sidebar,
[data-theme="light"] .auth-card,
[data-theme="light"] .feature,
[data-theme="light"] .person-card,
[data-theme="light"] .modal-card,
[data-theme="light"] .popover {
    background: #fff;
    color: #171920;
}

[data-theme="light"] .topbar,
[data-theme="light"] .side-top,
[data-theme="light"] .profile-mini,
[data-theme="light"] .composer,
[data-theme="light"] .dm-list,
[data-theme="light"] .members {
    border-color: #dfe1e8;
}

[data-theme="light"] input,
[data-theme="light"] textarea,
[data-theme="light"] select {
    background: #f3f4f7;
    color: #171920;
    border-color: #d7d9e1;
}

[data-theme="light"] .message-head b,
[data-theme="light"] .empty-state h2 {
    color: #171920;
}

[data-theme="light"] .message-text {
    color: #383c47;
}

[data-theme="light"] .side-item:hover {
    background: #eef0f5;
}

[data-theme="light"] .feature {
    border-color: #dfe1e8;
}

[data-theme="light"] .reaction {
    background: #eef0f5;
    border-color: #d8dbe3;
}

[data-theme="light"] .reply-bar {
    background: #f1f2f6;
}

[data-theme="light"] .composer {
    background: #eef0f5;
}

/* =============================
   MIDNIGHT
============================= */

[data-theme="midnight"] {
    background: #080a10;
}

[data-theme="midnight"] .main {
    background: #090b11;
}

[data-theme="midnight"] .sidebar {
    background: #0d0f16;
}

[data-theme="midnight"] .rail {
    background: #05060a;
}

[data-theme="midnight"] .feature,
[data-theme="midnight"] .person-card,
[data-theme="midnight"] .modal-card,
[data-theme="midnight"] .popover {
    background: #10131c;
}

/* =============================
   MOBILE
============================= */

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

    .sidebar {
        display: none;
    }

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

    .hero {
        padding: 35px 20px;
    }

    .hero h1 {
        font-size: 34px;
    }

    .members {
        display: none;
    }

    .dm-layout {
        grid-template-columns: 170px minmax(0, 1fr);
    }

    .dm-list {
        padding: 12px;
    }

    .messages {
        padding: 14px;
    }
}

@media (max-width: 600px) {
    .rail {
        padding: 10px 7px;
    }

    .rail-btn {
        width: 42px;
        height: 42px;
    }

    .topbar {
        padding: 0 12px;
    }

    .page {
        padding: 20px;
    }

    .hero h1 {
        font-size: 29px;
    }

    .dm-layout {
        grid-template-columns: 125px minmax(0, 1fr);
    }

    .dm-list h3 {
        font-size: 14px;
    }

    .side-item {
        margin-left: 2px;
        margin-right: 2px;
        padding: 8px;
        font-size: 12px;
    }

    .side-item .avatar {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }

    .composer {
        padding: 9px;
        gap: 5px;
    }

    .composer span {
        display: none;
    }

    .composer button {
        padding: 10px;
    }

    .popover {
        right: 10px;
        width: calc(100vw - 20px);
    }
}
