.chat {
    width: 100%;
    margin: 0;
    color: var(--theme-text-primary);
}

.chat.chat--flat {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 360px;
}

.chat-messages {
    list-style: none;
    margin: 0;
    padding: var(--theme-space-sm, 12px);
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--theme-space-sm, 12px);
    background: var(--theme-bg-secondary, #f5f5f5);
    border-radius: var(--theme-radius-md, 10px);
}

.chat-messages-empty {
    margin: auto;
    padding: var(--theme-space-md, 16px);
    text-align: center;
    color: var(--theme-text-secondary);
    font-style: italic;
}

.chat-messages-divider {
    display: flex;
    align-items: center;
    gap: var(--theme-space-sm, 12px);
    margin: var(--theme-space-xs, 6px) 0;
    color: var(--theme-color-danger, #dc3545);
    font-size: 0.7em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.chat-messages-divider::before,
.chat-messages-divider::after {
    content: '';
    flex: 1 1 auto;
    height: 1px;
    background: var(--theme-color-danger, #dc3545);
    opacity: 0.5;
}

.chat-messages-divider-label {
    flex: 0 0 auto;
}

.chat-message {
    display: flex;
    align-items: flex-start;
    gap: var(--theme-space-sm, 12px);
}

.chat-message--mine {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    overflow: hidden;
    background: var(--theme-bg-tertiary, #ececec);
    color: var(--theme-text-secondary);
    font-weight: 600;
    font-size: 0.95em;
}

.chat-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-avatar--placeholder {
    background: var(--theme-color-primary, #2e7df1);
    color: var(--theme-text-inverse, #fff);
}

.chat-author-trigger {
    cursor: pointer;
    transition: filter 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.chat-author-trigger:hover,
.chat-author-trigger:focus-visible {
    outline: none;
    filter: brightness(1.05);
}

.chat-message-author.chat-author-trigger:hover,
.chat-message-author.chat-author-trigger:focus-visible {
    color: var(--theme-color-primary, #2e7df1);
    text-decoration: underline;
}

.chat-avatar.chat-author-trigger:active {
    transform: scale(0.96);
}

.chat-message-bubble {
    flex: 0 1 auto;
    min-width: 0;
    max-width: min(560px, 78%);
    display: flex;
    flex-direction: column;
    gap: var(--theme-space-xs, 6px);
    padding: var(--theme-space-sm, 12px) var(--theme-space-md, 16px);
    background: var(--theme-bg-primary, #fff);
    border-radius: var(--theme-radius-md, 10px);
    border: 1px solid var(--theme-border-subtle, #e4e4e7);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.chat-message--mine .chat-message-bubble {
    background: var(--theme-color-primary-soft, rgba(46, 125, 241, 0.12));
    border-color: var(--theme-color-primary-soft, rgba(46, 125, 241, 0.18));
}

.chat-message-bubble.is-editing {
    border-color: var(--theme-color-primary, #2e7df1);
    box-shadow: 0 0 0 2px var(--theme-color-primary-soft, rgba(46, 125, 241, 0.18));
}

.chat-message-header {
    display: flex;
    align-items: center;
    gap: var(--theme-space-sm, 12px);
}

.chat-message-meta {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-message-author {
    font-weight: 600;
    color: var(--theme-text-primary);
    font-size: 0.9em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-message-time {
    font-size: 0.75em;
    color: var(--theme-text-secondary);
    line-height: 1.3;
}

.chat-edited {
    font-style: italic;
    color: var(--theme-text-secondary);
}

.chat-message-read {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    vertical-align: middle;
}

.chat-message-read.is-read {
    color: var(--theme-text-secondary);
    opacity: 0.7;
}

.chat-message-read.is-unread {
    color: var(--theme-color-primary);
}

.chat-message-body {
    margin: 0;
    color: var(--theme-text-primary);
    font-size: 0.95em;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-message-footer {
    display: flex;
    align-items: center;
    gap: var(--theme-space-xs, 6px);
}

.chat-reaction {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--theme-text-secondary);
    font-size: 0.8em;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.chat-reaction:hover:not(:disabled),
.chat-reaction:focus-visible:not(:disabled) {
    background: var(--theme-bg-secondary, #f5f5f5);
    border-color: var(--theme-border-subtle, #e4e4e7);
    outline: none;
}

.chat-reaction:active:not(:disabled) {
    transform: scale(0.96);
}

.chat-reaction:disabled {
    cursor: default;
    opacity: 0.55;
}

.chat-reaction--like.is-active {
    background: var(--theme-color-success-soft, rgba(34, 178, 99, 0.15));
    color: var(--theme-color-success, #22b263);
    border-color: transparent;
}

.chat-reaction--dislike.is-active {
    background: var(--theme-color-danger-soft, rgba(220, 53, 69, 0.15));
    color: var(--theme-color-danger, #dc3545);
    border-color: transparent;
}

.chat-reaction-count {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.chat-menu {
    position: relative;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}

.chat-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--theme-text-secondary);
    transition: background 0.15s ease, color 0.15s ease;
}

.chat-menu-button:hover,
.chat-menu-button:focus-visible {
    background: var(--theme-bg-secondary, #f5f5f5);
    color: var(--theme-text-primary);
    outline: none;
}

.chat-menu-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 180px;
    margin: 0;
    padding: var(--theme-space-xs, 6px) 0;
    list-style: none;
    background: var(--theme-bg-primary);
    border: 1px solid var(--theme-border-subtle, #e4e4e7);
    border-radius: var(--theme-radius-md, 10px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 20;
}

.chat-menu-option {
    padding: var(--theme-space-xs, 6px) var(--theme-space-sm, 12px);
    font-size: 0.9em;
    color: var(--theme-text-primary);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s ease;
}

.chat-menu-option:hover {
    background: var(--theme-bg-secondary, #f5f5f5);
}

.chat-menu-option--danger {
    color: var(--theme-color-danger, #dc3545);
}

.chat-composer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: var(--theme-space-xs, 6px);
    padding: var(--theme-space-sm, 12px);
    background: var(--theme-bg-primary);
    border-top: 1px solid var(--theme-border-subtle, #e4e4e7);
}

.chat-composer-edit-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--theme-space-sm, 12px);
    padding: 6px 10px;
    border-radius: var(--theme-radius-sm, 6px);
    background: var(--theme-color-primary-soft, rgba(46, 125, 241, 0.12));
    color: var(--theme-text-primary);
    font-size: 0.85em;
}

.chat-composer-edit-banner[hidden] {
    display: none;
}

.chat-composer-edit-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.chat-composer-edit-cancel {
    border: none;
    background: transparent;
    padding: 4px 8px;
    border-radius: var(--theme-radius-sm, 6px);
    cursor: pointer;
    color: var(--theme-color-primary, #2e7df1);
    font: inherit;
    font-size: 0.9em;
    font-weight: 600;
    transition: background 0.12s ease;
}

.chat-composer-edit-cancel:hover,
.chat-composer-edit-cancel:focus-visible {
    background: var(--theme-bg-secondary, #f5f5f5);
    outline: none;
}

.chat-composer-row {
    display: flex;
    align-items: flex-end;
    gap: var(--theme-space-sm, 12px);
    padding: var(--theme-space-xs, 6px) var(--theme-space-sm, 12px);
    border-radius: 999px;
    background: var(--theme-bg-secondary, #f5f5f5);
    border: 1px solid var(--theme-border-subtle, #e4e4e7);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-composer-row:focus-within {
    border-color: var(--theme-color-primary, #2e7df1);
    box-shadow: 0 0 0 3px var(--theme-color-primary-soft, rgba(46, 125, 241, 0.15));
}

.chat-composer-textarea {
    flex: 1 1 auto;
    min-height: 24px;
    max-height: 180px;
    padding: 6px 4px;
    border: none;
    background: transparent;
    color: var(--theme-text-primary);
    font: inherit;
    font-size: 0.95em;
    line-height: 1.4;
    resize: none;
    outline: none;
    overflow-y: auto;
}

.chat-composer-textarea::placeholder {
    color: var(--theme-text-secondary);
}

.chat-composer-button {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--theme-color-primary, #2e7df1);
    color: var(--theme-text-inverse, #fff);
    border: none;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.1s ease;
    box-shadow: 0 2px 6px rgba(46, 125, 241, 0.25);
}

.chat-composer-button:hover,
.chat-composer-button:focus-visible {
    filter: brightness(1.08);
    outline: none;
}

.chat-composer-button:active {
    transform: scale(0.96);
}

.chat-composer-notice {
    margin: 0;
    padding: var(--theme-space-sm, 12px);
    border-radius: var(--theme-radius-sm, 6px);
    background: var(--theme-bg-secondary, #f5f5f5);
    color: var(--theme-text-secondary);
    font-size: 0.9em;
    text-align: center;
    font-style: italic;
    width: 100%;
}

.chat-messages > :last-child {
    margin-bottom: var(--theme-space-sm, 12px);
}

@media (max-width: 560px) {
    .chat.chat--flat {
        min-height: 0;
    }
    .chat-message-bubble {
        max-width: 88%;
        padding: var(--theme-space-xs, 6px) var(--theme-space-sm, 12px);
    }
    .chat-composer {
        padding: var(--theme-space-xs, 6px);
    }
}
