body.page-chat main {
    width: var(--page-width);
    max-width: var(--page-max);
}

.chat-page-section {
    width: 100%;
    padding: 28px;
    overflow: hidden;
    direction: rtl;
}

.chat-page-heading {
    margin-bottom: 24px;
}

.chat-page-kicker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(52, 152, 219, 0.12);
    color: #10608f;
    font-size: 0.88rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.chat-page-heading h1 {
    font-size: clamp(1.9rem, 3vw, 2.7rem);
    margin-bottom: 8px;
}

.chat-page-heading p {
    color: rgba(15, 23, 42, 0.76);
    max-width: 62ch;
    line-height: 1.9;
}

.chat-shell {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 24px;
    min-height: 720px;
}

.chat-sidebar,
.chat-panel,
.chat-guest-card {
    border: 1px solid rgba(15, 23, 42, 0.08);
    background: rgba(255, 255, 255, 0.62);
    backdrop-filter: blur(16px) saturate(125%);
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

.chat-sidebar {
    border-radius: 26px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 720px;
}

.chat-sidebar-top h2,
.chat-thread-header h2 {
    font-size: 1.35rem;
    margin-bottom: 6px;
}

.chat-sidebar-top p,
.chat-thread-label,
.chat-thread-status,
.chat-composer-hint,
.chat-side-state,
.chat-message-meta {
    color: rgba(15, 23, 42, 0.64);
}

.chat-search {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    margin: 18px 0 14px;
    border-radius: 18px;
    border: 1px solid rgba(52, 152, 219, 0.18);
    background: rgba(255, 255, 255, 0.76);
}

.chat-search i {
    color: #3498db;
}

.chat-search input {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    outline: none;
}

.chat-users {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    min-height: 0;
    padding-left: 2px;
}

.chat-side-state {
    padding: 18px 8px;
    text-align: center;
    line-height: 1.8;
}

.chat-user-card {
    width: 100%;
    padding: 14px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(232, 244, 252, 0.85));
    color: var(--text);
    cursor: pointer;
    text-align: right;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.chat-user-card:hover,
.chat-user-card:focus-visible {
    transform: translateY(-2px);
    border-color: rgba(52, 152, 219, 0.34);
    box-shadow: 0 12px 24px rgba(52, 152, 219, 0.12);
    outline: none;
}

.chat-user-card.is-active {
    border-color: rgba(52, 152, 219, 0.42);
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.18), rgba(255, 255, 255, 0.95));
    box-shadow: 0 14px 28px rgba(52, 152, 219, 0.14);
}

.chat-user-top,
.chat-user-meta,
.chat-thread-header,
.chat-composer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chat-user-name {
    font-size: 1rem;
    font-weight: 700;
}

.chat-user-time {
    font-size: 0.82rem;
    white-space: nowrap;
}

.chat-user-unread {
    min-width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #3498db;
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
}

.chat-user-preview {
    margin-top: 10px;
    color: rgba(15, 23, 42, 0.72);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-panel {
    border-radius: 30px;
    min-height: 720px;
    overflow: hidden;
}

.chat-empty-state,
.chat-guest-card {
    min-height: 420px;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 40px 32px;
}

.chat-empty-state h2,
.chat-guest-card h2 {
    margin: 12px 0 10px;
    font-size: 1.5rem;
}

.chat-empty-state p,
.chat-guest-card p {
    max-width: 46ch;
    color: rgba(15, 23, 42, 0.72);
    line-height: 1.9;
}

.chat-empty-icon,
.chat-guest-icon {
    width: 76px;
    height: 76px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.14), rgba(255, 255, 255, 0.95));
    color: #3498db;
    font-size: 1.8rem;
}

.chat-guest-card {
    border-radius: 32px;
    gap: 10px;
}

.chat-guest-action {
    margin-top: 10px;
}

.chat-thread {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 720px;
}

.chat-thread-header {
    padding: 24px 26px 20px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    background:
        radial-gradient(circle at top right, rgba(52, 152, 219, 0.18), transparent 38%),
        rgba(255, 255, 255, 0.58);
}

.chat-thread-label {
    display: inline-block;
    margin-bottom: 6px;
    font-size: 0.86rem;
}

.chat-thread-status {
    font-size: 0.86rem;
    white-space: nowrap;
}

.chat-thread-status.is-error {
    color: var(--red);
}

.chat-messages {
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background:
        radial-gradient(circle at top left, rgba(52, 152, 219, 0.1), transparent 32%),
        linear-gradient(180deg, rgba(245, 250, 255, 0.9), rgba(255, 255, 255, 0.7));
}

.chat-message {
    max-width: min(76%, 560px);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-message.is-own {
    align-self: flex-start;
}

.chat-message:not(.is-own) {
    align-self: flex-end;
}

.chat-bubble {
    padding: 14px 16px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
    line-height: 1.95;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-message.is-own .chat-bubble {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.2), rgba(255, 255, 255, 0.96));
    border-bottom-left-radius: 10px;
}

.chat-message:not(.is-own) .chat-bubble {
    border-bottom-right-radius: 10px;
}

.chat-message-meta {
    font-size: 0.8rem;
    padding: 0 6px;
}

.chat-message-empty {
    margin: auto;
    padding: 18px 20px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
    color: rgba(15, 23, 42, 0.68);
}

.chat-composer {
    padding: 18px 20px 20px;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    background: rgba(255, 255, 255, 0.74);
}

.chat-composer-field {
    display: block;
    padding: 14px 16px;
    border-radius: 22px;
    border: 1px solid rgba(52, 152, 219, 0.16);
    background: rgba(255, 255, 255, 0.94);
}

.chat-composer textarea {
    width: 100%;
    min-height: 68px;
    max-height: 180px;
    border: none;
    outline: none;
    resize: vertical;
    background: transparent;
    color: var(--text);
    font: inherit;
    line-height: 1.9;
}

.chat-composer-actions {
    margin-top: 12px;
    flex-wrap: wrap;
}

.chat-composer-hint {
    font-size: 0.84rem;
}

.chat-send-btn:disabled {
    opacity: 0.65;
    cursor: wait;
}

body.dark .chat-page-kicker,
body.dark .chat-sidebar,
body.dark .chat-panel,
body.dark .chat-guest-card,
body.dark .chat-search,
body.dark .chat-user-card,
body.dark .chat-thread-header,
body.dark .chat-messages,
body.dark .chat-bubble,
body.dark .chat-composer,
body.dark .chat-composer-field,
body.dark .chat-message-empty {
    color: var(--text);
}

body.dark .chat-page-kicker {
    background: rgba(52, 152, 219, 0.18);
    color: #9ad5ff;
}

body.dark .chat-page-heading p,
body.dark .chat-sidebar-top p,
body.dark .chat-empty-state p,
body.dark .chat-guest-card p,
body.dark .chat-user-preview,
body.dark .chat-thread-label,
body.dark .chat-thread-status,
body.dark .chat-composer-hint,
body.dark .chat-side-state,
body.dark .chat-message-meta {
    color: rgba(231, 240, 255, 0.72);
}

body.dark .chat-sidebar,
body.dark .chat-panel,
body.dark .chat-guest-card {
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(11, 22, 33, 0.72);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
}

body.dark .chat-search,
body.dark .chat-thread-header,
body.dark .chat-composer {
    background: rgba(10, 17, 26, 0.65);
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark .chat-user-card {
    background: linear-gradient(180deg, rgba(13, 23, 35, 0.92), rgba(17, 37, 52, 0.88));
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark .chat-user-card.is-active {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.28), rgba(13, 23, 35, 0.95));
}

body.dark .chat-search input,
body.dark .chat-composer textarea {
    color: var(--text);
}

body.dark .chat-messages {
    background:
        radial-gradient(circle at top left, rgba(52, 152, 219, 0.16), transparent 32%),
        linear-gradient(180deg, rgba(8, 15, 24, 0.88), rgba(11, 19, 29, 0.8));
}

body.dark .chat-bubble {
    background: rgba(15, 27, 40, 0.92);
    box-shadow: 0 10px 18px rgba(0, 0, 0, 0.22);
}

body.dark .chat-message.is-own .chat-bubble {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.32), rgba(15, 27, 40, 0.94));
}

body.dark .chat-composer-field,
body.dark .chat-message-empty {
    background: rgba(15, 27, 40, 0.9);
    border-color: rgba(255, 255, 255, 0.08);
}

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

    .chat-sidebar,
    .chat-panel,
    .chat-thread {
        min-height: auto;
    }

    .chat-users {
        max-height: 320px;
    }
}

@media (max-width: 768px) {
    .chat-page-section {
        padding: 20px 16px;
    }

    .chat-sidebar,
    .chat-panel,
    .chat-guest-card {
        border-radius: 22px;
    }

    .chat-thread-header,
    .chat-messages,
    .chat-composer {
        padding-left: 16px;
        padding-right: 16px;
    }

    .chat-thread-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .chat-message {
        max-width: 88%;
    }
}

@media (max-width: 576px) {
    .chat-page-heading h1 {
        font-size: 1.65rem;
    }

    .chat-user-top,
    .chat-user-meta,
    .chat-composer-actions {
        align-items: flex-start;
        flex-direction: column;
    }

    .chat-user-meta {
        width: 100%;
    }

    .chat-thread-status {
        white-space: normal;
    }
}
