.chat-shell {
    direction: rtl;
}

.chat-layout {
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    min-height: 70vh;
    border: 1px solid #e9ecef;
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 16px 45px rgba(24, 33, 134, 0.08);
}

.chat-inbox {
    border-left: 1px solid #e9ecef;
    background: #f8f9fa;
}

.chat-panel-header,
.chat-thread-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem;
    border-bottom: 1px solid #e9ecef;
}

.chat-panel-header h1,
.chat-thread-header h2 {
    margin: 0;
    color: #182186;
    font-size: 1.35rem;
}

.chat-panel-header p,
.chat-thread-header p {
    margin: .25rem 0 0;
    color: #6c757d;
}

.chat-connection {
    border-radius: 999px;
    padding: .25rem .65rem;
    background: #fff3cd;
    color: #856404;
    font-size: .8rem;
    white-space: nowrap;
}

.chat-connection.is-connected {
    background: #d4edda;
    color: #155724;
}

.chat-inbox-list {
    max-height: 62vh;
    overflow-y: auto;
}

.chat-inbox-item {
    position: relative;
    display: block;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e9ecef;
    color: #212529;
}

.chat-inbox-item:hover,
.chat-inbox-item.is-active {
    color: #212529;
    background: #fff;
}

.chat-inbox-item.is-active {
    border-right: 4px solid #fbcd0b;
}

.chat-inbox-item__title,
.chat-inbox-item__participant,
.chat-inbox-item__preview,
.chat-inbox-item time {
    display: block;
}

.chat-inbox-item__title {
    font-weight: 700;
}

.chat-inbox-item__participant,
.chat-inbox-item__preview,
.chat-inbox-item time {
    color: #6c757d;
    font-size: .85rem;
}

.chat-thread-unread,
.chat-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    background: #dc3545;
    color: #fff;
    font-size: .75rem;
    font-weight: 700;
}

.chat-thread-unread {
    position: absolute;
    top: 1rem;
    left: 1rem;
}

.chat-unread-badge {
    margin-right: .35rem;
}

.chat-thread-unread--empty,
.chat-unread-badge--empty {
    display: none;
}

.chat-thread {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: linear-gradient(180deg, #ffffff 0%, #fffdf3 100%);
}

.chat-mobile-back {
    display: none;
    color: #182186;
    font-weight: 700;
}

.chat-typing {
    color: #28a745;
    font-size: .85rem;
}

.chat-messages {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
}

.chat-message {
    display: flex;
    margin-bottom: 1rem;
}

.chat-message--mine {
    justify-content: flex-start;
}

.chat-message--received {
    justify-content: flex-end;
}

.chat-message__bubble {
    max-width: min(620px, 78%);
    padding: .85rem 1rem;
    border-radius: 16px;
    background: #f1f3f5;
    color: #212529;
}

.chat-message--mine .chat-message__bubble {
    background: #182186;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message--received .chat-message__bubble {
    border-bottom-left-radius: 4px;
}

.chat-message--retracted .chat-message__body {
    font-style: italic;
    opacity: .75;
}

.chat-message__body {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-message__meta,
.chat-message__actions {
    display: flex;
    gap: .5rem;
    margin-top: .45rem;
    font-size: .75rem;
    opacity: .8;
}

.chat-message__actions button {
    border: 0;
    background: transparent;
    color: inherit;
    padding: 0;
    text-decoration: underline;
    cursor: pointer;
}

.chat-attachments {
    margin: .65rem 0 0;
    padding: 0;
    list-style: none;
}

.chat-attachments a {
    color: inherit;
    text-decoration: underline;
}

.chat-composer {
    padding: 1rem;
    border-top: 1px solid #e9ecef;
    background: #fff;
}

.chat-composer textarea {
    width: 100%;
    resize: vertical;
    border: 1px solid #ced4da;
    border-radius: 12px;
    padding: .85rem 1rem;
}

.chat-composer textarea:focus {
    outline: 0;
    border-color: #fbcd0b;
    box-shadow: 0 0 0 .2rem rgba(251, 205, 11, .2);
}

.chat-composer__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-top: .75rem;
}

.chat-attach-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    margin: 0;
    cursor: pointer;
    color: #182186;
    font-weight: 700;
}

.chat-composer input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.chat-attachment-previews {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: .5rem;
}

.chat-attachment-preview {
    border-radius: 999px;
    padding: .25rem .65rem;
    background: #f8f9fa;
    color: #495057;
    font-size: .85rem;
}

.chat-empty {
    padding: 2rem;
    text-align: center;
    color: #6c757d;
}

.chat-empty i {
    display: block;
    margin-bottom: .75rem;
    color: #fbcd0b;
    font-size: 2rem;
}

.chat-empty--thread {
    margin: auto;
}

.chat-read-region {
    min-height: 1.5rem;
    padding: 0 1.25rem .25rem;
    color: #6c757d;
    font-size: .85rem;
}

@media (max-width: 767.98px) {
    .chat-layout {
        display: block;
        min-height: 72vh;
    }

    .chat-layout[data-active-conversation=""] .chat-thread {
        display: none;
    }

    .chat-layout:not([data-active-conversation=""]) .chat-inbox {
        display: none;
    }

    .chat-inbox {
        border-left: 0;
    }

    .chat-mobile-back {
        display: inline-flex;
    }

    .chat-message__bubble {
        max-width: 88%;
    }

    .chat-composer__actions {
        align-items: stretch;
        flex-direction: column;
    }
}
