:root {
    --chat-primary: var(--nexus-accent);
    --chat-primary-rgb: var(--nexus-accent-rgb, 13, 110, 253);
    --chat-secondary: var(--nexus-accent-alt);
    --chat-surface: var(--nexus-surface);
    --chat-surface-strong: var(--nexus-surface-strong);
    --chat-border: var(--nexus-border);
    --chat-border-strong: var(--nexus-border-strong, rgba(82, 132, 255, 0.35));
    --chat-text: var(--nexus-text);
    --chat-muted: var(--nexus-text-muted);
    --chat-radius: 1.35rem;
    --chat-radius-sm: 1rem;
    --chat-shadow: var(--nexus-shadow);
}

body.dashboard-shell.theme-light {
    --chat-surface: rgba(255, 255, 255, 0.94);
    --chat-surface-strong: rgba(255, 255, 255, 0.98);
    --chat-border: rgba(15, 23, 42, 0.08);
    --chat-border-strong: rgba(15, 23, 42, 0.12);
    --chat-text: #1f2937;
    --chat-muted: rgba(55, 65, 81, 0.72);
    --chat-shadow: 0 28px 55px rgba(15, 23, 42, 0.12);
}

.nexus-chat-shell {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(210px, 252px) minmax(0, 1fr);
    min-height: 72vh;
    height: 100%;
    border: 1px solid var(--chat-border);
    border-radius: calc(var(--chat-radius) + .15rem);
    overflow: hidden;
    box-shadow: var(--chat-shadow);
    backdrop-filter: blur(14px);
}

.nexus-chat-shell--widget {
    min-height: min(82vh, 760px);
    height: min(82vh, 760px);
    grid-template-columns: minmax(210px, 248px) minmax(0, 1fr);
}

.nexus-chat-shell--page {
    height: 100%;
    min-height: 0;
    grid-template-columns: minmax(210px, 250px) minmax(0, 1fr);
}

.nexus-chat-sidebar {
    display: grid;
    grid-template-rows: auto minmax(0, .92fr) minmax(0, 1.08fr);
    border-right: 1px solid var(--chat-border);
    background:
        linear-gradient(180deg, rgba(var(--chat-primary-rgb), 0.08), transparent 18%),
        var(--chat-surface);
    min-height: 0;
}

.nexus-chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--chat-surface-strong);
    min-height: 0;
}

.nexus-chat-toolbar {
    padding: .78rem .78rem .65rem;
    border-bottom: 1px solid var(--chat-border);
}

.nexus-chat-shell--widget .nexus-chat-toolbar {
    padding: .68rem .68rem .58rem;
}

.nexus-chat-toolbar__title {
    font-weight: 700;
    letter-spacing: -.02em;
}

.nexus-chat-search {
    position: relative;
}

.nexus-chat-search .bi {
    position: absolute;
    left: .85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--chat-muted);
}

.nexus-chat-search input {
    padding-left: 2.2rem;
    padding-top: .38rem;
    padding-bottom: .38rem;
    border-radius: 999px;
    border: 1px solid var(--chat-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--chat-text);
    font-size: .78rem;
}

.nexus-chat-search input::placeholder {
    color: var(--chat-muted);
}

.nexus-chat-contact-list,
.nexus-chat-thread-list {
    padding: .48rem;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: .28rem;
    min-height: 0;
}

.nexus-chat-shell--widget .nexus-chat-contact-list,
.nexus-chat-shell--widget .nexus-chat-thread-list {
    padding: .42rem;
    gap: .24rem;
}

.nexus-chat-sidebar__section {
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    border-bottom: 1px solid var(--chat-border);
}

.nexus-chat-sidebar__section--contacts {
    border-bottom: 0;
}

.nexus-chat-sidebar__section-head {
    padding: .55rem .7rem .32rem;
    color: var(--chat-muted);
    border-bottom: 1px solid rgba(var(--chat-primary-rgb), 0.08);
    font-size: .68rem;
}

.nexus-chat-contact,
.nexus-chat-thread {
    border: 1px solid transparent;
    border-radius: var(--chat-radius-sm);
    padding: .48rem .52rem;
    display: flex;
    gap: .45rem;
    align-items: flex-start;
    color: inherit;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: .18s ease;
}

.nexus-chat-shell--widget .nexus-chat-contact,
.nexus-chat-shell--widget .nexus-chat-thread {
    padding: .42rem .46rem;
    gap: .42rem;
    border-radius: .75rem;
}

.nexus-chat-contact:hover,
.nexus-chat-thread:hover,
.nexus-chat-contact.is-active,
.nexus-chat-thread.is-active {
    border-color: rgba(var(--chat-primary-rgb), 0.24);
    background: rgba(var(--chat-primary-rgb), 0.1);
    transform: translateY(-1px);
}

.nexus-chat-avatar {
    width: 1.85rem;
    height: 1.85rem;
    flex: 0 0 1.85rem;
    border-radius: .72rem;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 700;
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.nexus-chat-shell--widget .nexus-chat-avatar {
    width: 1.7rem;
    height: 1.7rem;
    flex-basis: 1.7rem;
    border-radius: .66rem;
    font-size: .68rem;
}

.nexus-chat-presence {
    position: absolute;
    right: -.12rem;
    bottom: -.12rem;
    width: .56rem;
    height: .56rem;
    border-radius: 50%;
    border: 1.5px solid var(--chat-surface-strong);
    background: #94a3b8;
}

.nexus-chat-presence--online { background: #22c55e; }
.nexus-chat-presence--ausente { background: #f59e0b; }
.nexus-chat-presence--offline { background: #94a3b8; }

.nexus-chat-contact__meta,
.nexus-chat-thread__meta {
    min-width: 0;
    flex: 1;
}

.nexus-chat-contact__name,
.nexus-chat-thread__name {
    font-weight: 700;
    color: var(--chat-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .74rem;
    line-height: 1.2;
}

.nexus-chat-contact__role,
.nexus-chat-thread__preview,
.nexus-chat-contact__status {
    color: var(--chat-muted);
    font-size: .66rem;
    line-height: 1.2;
}

.nexus-chat-thread__time {
    color: var(--chat-muted);
    font-size: .62rem;
    white-space: nowrap;
}

.nexus-chat-thread__badge {
    min-width: 1.2rem;
    height: 1.2rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 .32rem;
    font-size: .68rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, rgba(var(--chat-primary-rgb), .96), rgba(var(--chat-primary-rgb), .76));
}

.nexus-chat-shell--widget .nexus-chat-contact__name,
.nexus-chat-shell--widget .nexus-chat-thread__name {
    font-size: .7rem;
}

.nexus-chat-shell--widget .nexus-chat-contact__role,
.nexus-chat-shell--widget .nexus-chat-thread__preview,
.nexus-chat-shell--widget .nexus-chat-contact__status,
.nexus-chat-shell--widget .nexus-chat-thread__time {
    font-size: .62rem;
}

.nexus-chat-main__header {
    padding: .72rem .88rem;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.nexus-chat-shell--widget .nexus-chat-main__header {
    padding: .6rem .7rem;
}

.nexus-chat-main__empty,
.nexus-chat-empty-state {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--chat-muted);
    text-align: center;
}

.nexus-chat-main__body {
    flex: 1;
    overflow: auto;
    padding: .78rem .82rem .68rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    background:
        radial-gradient(circle at top right, rgba(var(--chat-primary-rgb), 0.07), transparent 22%),
        linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,0));
    min-height: 0;
}

.nexus-chat-shell--widget .nexus-chat-main__body {
    padding: .6rem .64rem .58rem;
}

.nexus-chat-day {
    align-self: center;
    font-size: .72rem;
    color: var(--chat-muted);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--chat-border);
    padding: .35rem .75rem;
    border-radius: 999px;
}

.nexus-chat-message {
    display: flex;
    gap: .42rem;
    align-items: flex-end;
    max-width: min(82%, 720px);
}

.nexus-chat-message--self {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.nexus-chat-bubble {
    display: flex;
    flex-direction: column;
    gap: .24rem;
    padding: .5rem .62rem;
    border-radius: .86rem;
    border: 1px solid var(--chat-border);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 16px 30px rgba(15, 23, 42, 0.08);
}

.nexus-chat-message--self .nexus-chat-bubble {
    color: #fff;
    background: linear-gradient(135deg, rgba(var(--chat-primary-rgb), .95), rgba(var(--chat-primary-rgb), .78));
    border-color: rgba(var(--chat-primary-rgb), 0.35);
}

.nexus-chat-bubble__author {
    font-size: .62rem;
    font-weight: 700;
    color: var(--chat-muted);
}

.nexus-chat-message--self .nexus-chat-bubble__author {
    color: rgba(255,255,255,.82);
}

.nexus-chat-bubble__text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.3;
    font-size: .76rem;
}

.nexus-chat-bubble__meta {
    display: inline-flex;
    justify-content: flex-end;
    gap: .4rem;
    align-items: center;
    font-size: .58rem;
    color: var(--chat-muted);
}

.nexus-chat-message--self .nexus-chat-bubble__meta {
    color: rgba(255,255,255,.82);
}

.nexus-chat-attachment {
    display: flex;
    gap: .75rem;
    align-items: center;
    padding: .7rem;
    border-radius: 1rem;
    border: 1px solid rgba(var(--chat-primary-rgb), 0.18);
    background: rgba(var(--chat-primary-rgb), 0.08);
    color: inherit;
    text-decoration: none;
}

.nexus-chat-attachment:hover {
    background: rgba(var(--chat-primary-rgb), 0.13);
}

.nexus-chat-attachment__thumb {
    width: 3.4rem;
    height: 3.4rem;
    border-radius: .9rem;
    background: rgba(var(--chat-primary-rgb), 0.14);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex: 0 0 3.4rem;
}

.nexus-chat-attachment__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.nexus-chat-attachment__name {
    font-weight: 700;
    line-height: 1.35;
}

.nexus-chat-attachment__meta {
    font-size: .78rem;
    color: var(--chat-muted);
}

.nexus-chat-message--self .nexus-chat-attachment {
    background: rgba(255,255,255,.12);
    border-color: rgba(255,255,255,.2);
}

.nexus-chat-typing {
    padding: 0 1.2rem .55rem;
    min-height: 1.6rem;
    color: var(--chat-muted);
    font-size: .8rem;
}

.nexus-chat-composer {
    padding: .7rem .82rem .86rem;
    border-top: 1px solid var(--chat-border);
    background: rgba(255,255,255,.03);
}

.nexus-chat-shell--widget .nexus-chat-composer {
    padding: .5rem .56rem .6rem;
}

.nexus-chat-composer__box {
    display: flex;
    align-items: end;
    gap: .48rem;
    padding: .62rem .72rem;
    border: 1px solid var(--chat-border);
    border-radius: 1rem;
    background: rgba(255,255,255,.04);
    width: 100%;
}

.nexus-chat-composer textarea {
    min-height: 64px;
    max-height: 172px;
    resize: none;
    border: 0;
    box-shadow: none !important;
    background: transparent;
    color: var(--chat-text);
    font-size: .84rem;
    line-height: 1.45;
    padding: .2rem 0;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
}

.nexus-chat-composer textarea::placeholder {
    color: var(--chat-muted);
}

.nexus-chat-composer__actions {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex: 0 0 auto;
}

.nexus-chat-composer__file {
    position: relative;
    overflow: hidden;
}

.nexus-chat-composer__file input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.nexus-chat-file-chip {
    margin-top: .65rem;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    padding: .55rem .75rem;
    border-radius: 999px;
    border: 1px solid rgba(var(--chat-primary-rgb), 0.18);
    background: rgba(var(--chat-primary-rgb), 0.08);
    color: var(--chat-text);
    font-size: .82rem;
}

.nexus-chat-file-chip.is-visible {
    display: flex;
}

.nexus-chat-widget-launcher {
    position: fixed;
    right: 1.2rem;
    bottom: 1.2rem;
    z-index: 1040;
    width: 3.8rem;
    height: 3.8rem;
    border-radius: 1.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(var(--chat-primary-rgb), 0.18);
    background: linear-gradient(135deg, rgba(var(--chat-primary-rgb), .98), rgba(var(--chat-primary-rgb), .82));
    color: #fff;
    box-shadow: 0 1rem 2.25rem rgba(var(--chat-primary-rgb), 0.24);
}

.nexus-chat-widget-launcher__badge {
    position: absolute;
    top: -.1rem;
    right: -.1rem;
    min-width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    padding: 0 .3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: var(--chat-primary);
    font-size: .72rem;
    font-weight: 700;
}

.nexus-chat-widget-launcher__badge:empty {
    display: none;
}

.nexus-chat-widget.offcanvas {
    --bs-offcanvas-width: min(1120px, calc(100vw - 1rem));
    width: min(1120px, calc(100vw - 1rem));
    max-width: min(1120px, calc(100vw - 1rem));
}

.nexus-chat-widget .offcanvas-body {
    padding: 0;
    height: 100%;
    min-height: 0;
    display: flex;
}

.nexus-chat-widget .offcanvas-header {
    border-bottom: 1px solid var(--chat-border);
}

#nexus-chat-widget-root,
.chat-page-host {
    height: 100%;
    min-height: 0;
    display: flex;
    flex: 1 1 auto;
    overflow: hidden;
}

#nexus-chat-widget-root > .nexus-chat-shell,
.chat-page-host > .nexus-chat-shell {
    flex: 1 1 auto;
    min-height: 0;
}

.chat-page-screen {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    overflow: hidden;
}

.chat-page-topbar {
    flex: 0 0 auto;
    min-height: 0;
}

.chat-page-host {
    height: 100%;
    min-height: 0;
    flex: 1 1 auto;
}

body.dashboard-shell .main-content:has(.chat-page-screen) {
    overflow: hidden;
    padding-bottom: .4rem;
}

body.dashboard-shell:has(.chat-page-screen) .app-footer {
    display: none;
}

body.chat-page-active .main-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 100vh;
    height: 100vh;
    padding-bottom: .45rem;
}

body.chat-page-active .main-content > *:not(.chat-page-screen) {
    flex: 0 0 auto;
}

body.chat-page-active .chat-page-screen {
    flex: 1 1 auto;
    min-height: 0;
}

body.chat-page-active .chat-page-host,
body.chat-page-active .nexus-chat-shell--page,
body.chat-page-active .nexus-chat-main,
body.chat-page-active .nexus-chat-main__body {
    min-height: 0;
}

body.chat-page-active .app-footer {
    display: none !important;
}

.nexus-chat-toast-container {
    position: fixed;
    right: 1.15rem;
    bottom: 5.5rem;
    z-index: 1085;
    display: flex;
    flex-direction: column;
    gap: .65rem;
    pointer-events: none;
}

.nexus-chat-toast {
    min-width: min(380px, calc(100vw - 2rem));
    max-width: min(420px, calc(100vw - 2rem));
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .88rem 1rem;
    border: 1px solid rgba(var(--chat-primary-rgb), 0.18);
    border-radius: 1rem;
    background: var(--chat-surface-strong);
    color: var(--chat-text);
    box-shadow: 0 1.2rem 2.8rem rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(18px);
    pointer-events: auto;
}

.nexus-chat-toast__icon {
    width: 2.35rem;
    height: 2.35rem;
    flex: 0 0 2.35rem;
    border-radius: .85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(var(--chat-primary-rgb), .95), rgba(var(--chat-primary-rgb), .75));
    color: #fff;
    font-size: 1rem;
    box-shadow: 0 .8rem 1.6rem rgba(var(--chat-primary-rgb), 0.26);
}

.nexus-chat-toast__content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .18rem;
    text-align: left;
}

.nexus-chat-toast__content strong {
    display: block;
    font-size: .86rem;
    line-height: 1.15;
    color: var(--chat-text);
}

.nexus-chat-toast__content span {
    display: block;
    font-size: .75rem;
    line-height: 1.35;
    color: var(--chat-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nexus-chat-toast__count {
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 .4rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, rgba(var(--chat-primary-rgb), 1), rgba(var(--chat-primary-rgb), .82));
}

.nexus-chat-load-more {
    align-self: center;
}

@media (max-width: 991.98px) {
    .chat-page-screen {
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .nexus-chat-shell,
    .nexus-chat-shell--widget {
        grid-template-columns: 1fr;
        min-height: 68vh;
        height: auto;
    }

    .nexus-chat-sidebar {
        grid-template-rows: auto minmax(220px, .9fr) minmax(240px, 1fr);
        border-right: 0;
        border-bottom: 1px solid var(--chat-border);
        max-height: 45vh;
    }

    .nexus-chat-message {
        max-width: 100%;
    }

    .nexus-chat-toast-container {
        right: .8rem;
        left: .8rem;
        bottom: 5rem;
    }

    .nexus-chat-toast {
        min-width: 0;
        max-width: none;
        width: 100%;
    }
}
