/* ============================================================================
 * Chat Panel — Phase 1 Real-time chat in History modal
 *
 * Design system: docs/DESIGN_SYSTEM.md
 * Spec: docs/CHAT_REALTIME_SPEC.md §8.11
 * UX deliverable: docs/UX_DELIVERABLES_CHAT_PHASE_1.md
 *
 * Naming convention: all new classes prefixed with `chat-*` to coexist with
 * legacy `.history-item-*` classes (backward compat for refreshLogs path).
 *
 * Tokens: 100% from styles/themes.css. Zero hardcoded colors.
 * Dark theme: works automatically via CSS variable cascade. No overrides.
 * ============================================================================ */

/* === Chat input row (form under timeline) === */

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    padding: var(--space-3);
    border-top: 1px solid var(--border-primary);
    background-color: var(--bg-secondary);
}

.chat-input-row__textarea {
    flex: 1;
    min-height: 38px;
    max-height: 120px;
    padding: var(--space-2) var(--space-3);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    resize: none;
    overflow-y: auto;
    transition: border-color var(--transition-fast);
}

.chat-input-row__textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
}

.chat-input-row__send-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background-color: var(--brand-primary);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.chat-input-row__send-btn:hover:not(:disabled) {
    background-color: var(--brand-primary-hover);
}

.chat-input-row__send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-input-row__send-btn .material-icons {
    font-size: 20px !important;
    width: 20px;
    height: 20px;
}

/* === U1: Empty state === */

.chat-empty-state {
    list-style: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-12) var(--space-6);
    text-align: center;
    color: var(--text-secondary);
}

.chat-empty-state__icon {
    font-size: 48px !important;
    width: 48px;
    height: 48px;
    color: var(--text-tertiary);
    margin-bottom: var(--space-2);
}

.chat-empty-state__title {
    margin: 0;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.chat-empty-state__hint {
    margin: 0;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    color: var(--text-secondary);
    max-width: 320px;
}

/* === Date separator === */

.chat-date-separator {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: var(--space-3) 0;
    color: var(--text-tertiary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    user-select: none;
}

.chat-date-separator::before,
.chat-date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background-color: var(--border-primary);
}

/* === Chat bubble base layout === */

.chat-bubble {
    list-style: none;
    display: flex;
    gap: var(--space-2);
    max-width: 85%;
    margin-top: var(--space-2);
    position: relative;
    word-wrap: break-word;
    align-self: flex-start;
}

.chat-bubble--own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Avatar */
.chat-bubble__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: var(--font-weight-semibold);
    color: white;
    flex-shrink: 0;
    align-self: flex-end;
}

/* Grouped messages: keep avatar space for alignment, use transparent placeholder */
.chat-bubble--grouped .chat-bubble__avatar {
    opacity: 0;
}

/* Agent avatar = rounded square */
.chat-bubble__avatar[data-is-agent='true'] {
    border-radius: var(--radius-md);
}

/* Content wrapper */
.chat-bubble__content {
    display: flex;
    flex-direction: column;
    padding: var(--space-2) var(--space-3);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    min-width: 60px;
}

.chat-bubble--own .chat-bubble__content {
    background-color: rgba(var(--brand-primary-rgb), 0.15);
    border-color: rgba(var(--brand-primary-rgb), 0.3);
}

/* Grouped messages: tighter spacing, no top-left radius */
.chat-bubble--grouped {
    margin-top: 2px;
}

.chat-bubble--grouped .chat-bubble__content {
    border-top-left-radius: var(--radius-sm);
}

.chat-bubble--own.chat-bubble--grouped .chat-bubble__content {
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-sm);
}

.chat-bubble__text {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    white-space: pre-wrap;
}

.chat-bubble__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-1);
    margin-top: 2px;
}

.chat-bubble__timestamp {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}

/* === U3: Failed message retry === */

.chat-bubble--failed .chat-bubble__content {
    border-color: var(--color-error);
    background-color: var(--color-error-bg);
}

.chat-bubble--failed .chat-bubble__text {
    color: var(--text-primary);
}

.chat-bubble__retry-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-error-light);
}

.chat-bubble__error-text {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--font-size-xs);
    color: var(--color-error);
}

.chat-bubble__error-text .material-icons {
    font-size: 14px !important;
    width: 14px;
    height: 14px;
}

.chat-bubble__retry-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 4px 10px;
    background-color: var(--bg-secondary);
    color: var(--color-error);
    border: 1px solid var(--color-error);
    border-radius: var(--radius-md);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    /* [2026-09-18] Перечень вместо `all` (аудит Д1, закрытие хвоста).
       Ref: docs/AUDIT_UI_MOTION_2026-09-17.md Д1. Chat: ui-motion-fixes-2026-09-17. */
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast),
        box-shadow var(--transition-fast),
        transform var(--transition-fast);
}

.chat-bubble__retry-btn:hover {
    background-color: var(--color-error);
    color: var(--text-inverse);
}

.chat-bubble__retry-btn:active {
    transform: translateY(1px);
}

.chat-bubble__retry-btn .material-icons {
    font-size: 14px !important;
    width: 14px;
    height: 14px;
}

.chat-bubble__retry-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === U4: Status indicators === */

.chat-bubble__status {
    display: inline-flex;
    align-items: center;
    margin-left: var(--space-2);
    cursor: help;
}

.chat-bubble__status .material-icons {
    font-size: 16px !important;
    width: 16px;
    height: 16px;
    line-height: 1;
}

.chat-bubble__status--sent .material-icons,
.chat-bubble__status--saved .material-icons,
.chat-bubble__status--delivered .material-icons {
    color: var(--text-tertiary);
}

.chat-bubble__status--read .material-icons {
    color: var(--color-info);
}

.chat-bubble__status--failed .material-icons {
    color: var(--color-error);
}

/* === U5: Mention pill === */

.chat-mention {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    background-color: rgba(var(--brand-primary-rgb), 0.12);
    color: var(--brand-primary);
    border-radius: var(--radius-full);
    font-weight: var(--font-weight-medium);
    font-size: inherit;
    line-height: 1.4;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--transition-fast);
    white-space: nowrap;
}

.chat-mention:hover {
    background-color: rgba(var(--brand-primary-rgb), 0.2);
}

.chat-mention--self {
    background-color: var(--brand-primary);
    color: var(--text-inverse);
}

.chat-mention--self:hover {
    background-color: var(--brand-primary-hover);
}

.chat-mention--unresolved {
    background-color: var(--bg-tertiary);
    color: var(--text-tertiary);
    cursor: default;
}

/* === U6: New messages badge === */

.chat-new-messages-badge {
    position: absolute;
    bottom: var(--space-3);
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 6px var(--space-3);
    background-color: var(--brand-primary);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    z-index: 2;
    transition:
        opacity var(--transition-base),
        transform var(--transition-base);
}

.chat-new-messages-badge:hover {
    background-color: var(--brand-primary-hover);
    transform: translateX(-50%) translateY(-2px);
}

.chat-new-messages-badge.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(20px);
}

.chat-new-messages-badge .material-icons {
    font-size: 14px !important;
    width: 14px;
    height: 14px;
}

.chat-new-messages-badge__count {
    font-weight: var(--font-weight-semibold);
}

/* === U7: Mention autocomplete dropdown === */

.chat-mention-dropdown {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    right: 0;
    max-width: 360px;
    max-height: 240px;
    overflow-y: auto;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: var(--z-dropdown);
    padding: var(--space-1) 0;
}

.chat-mention-dropdown.hidden {
    display: none;
}

.chat-mention-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.chat-mention-item:hover,
.chat-mention-item.active {
    background-color: var(--bg-hover);
}

.chat-mention-item__body {
    display: flex;
    flex: 1;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    min-width: 0;
}

.chat-mention-item__name {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-mention-item__meta {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-mention-empty {
    padding: var(--space-4);
    text-align: center;
    color: var(--text-tertiary);
    font-size: var(--font-size-sm);
    font-style: italic;
}

/* === U8: Task event styling === */

.chat-event {
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-3);
    margin: var(--space-1) 0;
    background-color: var(--bg-tertiary);
    border-left: 2px solid var(--border-primary);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    line-height: 1.4;
}

.chat-event__icon {
    font-size: 14px !important;
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-event__text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-event__user {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.chat-event__step {
    font-style: normal;
    color: var(--text-primary);
}

.chat-event__time {
    flex-shrink: 0;
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}

/* Per-kind colored left border */
.chat-event--assigned {
    border-left-color: var(--color-info);
}
.chat-event--assigned .chat-event__icon {
    color: var(--color-info);
}

.chat-event--started {
    border-left-color: var(--color-warning);
}
.chat-event--started .chat-event__icon {
    color: var(--color-warning);
}

.chat-event--finished {
    border-left-color: var(--color-success);
}
.chat-event--finished .chat-event__icon {
    color: var(--color-success);
}

.chat-event--rejected {
    border-left-color: var(--color-error);
}
.chat-event--rejected .chat-event__icon {
    color: var(--color-error);
}

.chat-event--returned {
    border-left-color: var(--color-warning);
}
.chat-event--returned .chat-event__icon {
    color: var(--color-warning);
}

.chat-event--revoked,
.chat-event--skipped,
.chat-event--cancelled {
    border-left-color: var(--text-tertiary);
}
.chat-event--revoked .chat-event__icon,
.chat-event--skipped .chat-event__icon,
.chat-event--cancelled .chat-event__icon {
    color: var(--text-tertiary);
}

/* === U9: Avatar (reuses AvatarHelpers for color + initials) === */

.chat-avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    color: var(--text-inverse);
    font-size: 10px;
    font-weight: var(--font-weight-semibold);
    flex-shrink: 0;
    user-select: none;
    /* background-color set inline via AvatarHelpers.getAvatarColor() */
}

.chat-avatar__initials {
    line-height: 1;
}

.chat-avatar--lg {
    width: 64px;
    height: 64px;
    font-size: 24px;
}

.chat-avatar--md {
    width: 40px;
    height: 40px;
    font-size: 16px;
}

.chat-avatar--agent {
    border: 2px solid var(--brand-primary);
}

.chat-avatar__agent-badge {
    position: absolute;
    bottom: -3px;
    right: -3px;
    width: 12px;
    height: 12px;
    background-color: var(--brand-primary);
    color: var(--text-inverse);
    border-radius: var(--radius-full);
    border: 1.5px solid var(--bg-secondary);
    font-size: 8px !important;
    line-height: 12px;
    text-align: center;
}

.chat-avatar--lg .chat-avatar__agent-badge {
    width: 20px;
    height: 20px;
    font-size: 14px !important;
    line-height: 20px;
    bottom: 0;
    right: 0;
    border-width: 2px;
}

/* === Timeline list layout (override .history-list flex direction for chat) === */

#history-modal-list.chat-timeline {
    display: flex;
    flex-direction: column;
    padding: var(--space-3);
    max-height: 480px;
    overflow-y: auto;
    background-color: var(--bg-primary);
    list-style: none;
    margin: 0;
}

/* === Mention Dropdown === */

.mention-dropdown {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
}

.mention-dropdown__item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary, #111);
}

.mention-dropdown__item:hover,
.mention-dropdown__item--active {
    background: var(--bg-tertiary, #f3f4f6);
}

.mention-dropdown__name {
    flex: 1;
}

.mention-dropdown__agent-badge {
    color: var(--brand-primary, #3b82f6);
}

/* ============================================================================
 * ChatPanel — Floating panel component
 *
 * Uses design system tokens exclusively. No hardcoded colors.
 * Dark theme: automatic via CSS variable cascade.
 * ============================================================================ */

/* === Toggle button (inline in footer bar) === */

.chat-panel-toggle {
    /* 2026-05-03: footbar removed in step-by-step → toggle floats free,
       sticky bottom-right of viewport. Personal AI sidebar uses --z-fixed
       (1020); chat toggle sits above (1022) so it's clickable when sidebar
       is open. Modals/popovers (1040+) still cover it. */
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 1022;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background-color: var(--brand-primary);
    border: none;
    color: var(--text-inverse);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    transition:
        background-color var(--transition-fast),
        transform var(--transition-fast);
    flex-shrink: 0;
}

.chat-panel-toggle:hover {
    background-color: var(--brand-primary-hover);
    transform: translateY(-2px);
}

/* Shift the toggle when Personal AI sidebar is pinned so it doesn't
   hide behind the sidebar. Width var owned by PersonalAIPanel.css. */
html.has-personal-ai-sidebar .chat-panel-toggle {
    right: calc(var(--personal-ai-sidebar-w, 340px) + 16px);
}

.chat-panel-toggle.active {
    background-color: var(--brand-primary-dark);
}

.chat-panel-toggle .material-symbols-outlined {
    font-size: 22px;
}

/* === Panel container === */

.chat-panel-container {
    position: fixed;
    bottom: 100px;
    right: var(--space-6);
    width: 380px;
    height: 450px;
    min-width: 280px;
    min-height: 250px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 80px);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-popover);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.chat-panel-container > .chat-panel-header,
.chat-panel-container > .chat-panel-main,
.chat-panel-container > .chat-panel-footer {
    overflow: hidden;
}

/* === Resize handles: full-perimeter grab zones with direction cursors === */
.chat-panel-resize {
    position: absolute;
    z-index: 10;
    pointer-events: auto;
    background: transparent;
}

/* Edges — thin strips along each side */
.chat-panel-resize--t {
    top: -4px;
    left: 8px;
    right: 8px;
    height: 8px;
    cursor: ns-resize;
}
.chat-panel-resize--b {
    bottom: -4px;
    left: 8px;
    right: 8px;
    height: 8px;
    cursor: ns-resize;
}
.chat-panel-resize--l {
    left: -4px;
    top: 8px;
    bottom: 8px;
    width: 8px;
    cursor: ew-resize;
}
.chat-panel-resize--r {
    right: -4px;
    top: 8px;
    bottom: 8px;
    width: 8px;
    cursor: ew-resize;
}

/* Corners — small squares, diagonal cursors */
.chat-panel-resize--tl {
    top: -4px;
    left: -4px;
    width: 12px;
    height: 12px;
    cursor: nwse-resize;
}
.chat-panel-resize--br {
    bottom: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    cursor: nwse-resize;
}
.chat-panel-resize--tr {
    top: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    cursor: nesw-resize;
}
.chat-panel-resize--bl {
    bottom: -4px;
    left: -4px;
    width: 12px;
    height: 12px;
    cursor: nesw-resize;
}

.chat-panel-container.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Drag state — disable text selection and transitions during drag */
.chat-panel-container.dragging {
    user-select: none;
    cursor: grabbing;
}

.chat-panel-container.dragging * {
    pointer-events: none;
}

/* === Header === */

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-primary);
    background-color: var(--bg-secondary);
    cursor: grab;
    user-select: none;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
}

.chat-panel-header:active {
    cursor: grabbing;
}

.chat-panel-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.chat-panel-title .material-symbols-outlined {
    font-size: 20px;
    color: var(--brand-primary);
}

.chat-panel-close {
    background: none;
    border: none;
    padding: var(--space-1);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background-color var(--transition-fast),
        color var(--transition-fast);
}

.chat-panel-close:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.chat-panel-close .material-symbols-outlined {
    font-size: 20px;
}

/* === Header action buttons (collapse-all, search, date-range) === */

.chat-panel-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.chat-panel-header-btn {
    background: none;
    border: none;
    padding: var(--space-1);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background-color var(--transition-fast),
        color var(--transition-fast);
}

.chat-panel-header-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.chat-panel-header-btn.active {
    background-color: var(--color-primary);
    color: var(--color-primary-contrast, #fff);
}

.chat-panel-header-btn .material-symbols-outlined {
    font-size: 20px;
}

/* === Toolbar row (search / date filter) === */

.chat-panel-toolbar {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
}

.chat-panel-toolbar-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.chat-panel-toolbar-icon {
    font-size: 18px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-panel-toolbar-input {
    flex: 1;
    min-width: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast);
}

.chat-panel-toolbar-input:focus {
    border-color: var(--color-primary);
}

.chat-panel-toolbar-date {
    flex: 1;
    min-width: 0;
}

.chat-panel-toolbar-clear {
    background: none;
    border: none;
    padding: var(--space-1);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast);
}

.chat-panel-toolbar-clear:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* [2026-08-16] Кнопка × закрытия окошка поиска/дат (как явный close у Personal AI).
   Прижата вправо в своей строке (flex-shrink:0), не растягивается. Ref:
   docs/GUIDE_EMBED_UNIVERSAL_SIDEBAR_CHAT_2026-08-16.md §5. Chat: universal-sidebar-embed-2026-08-16. */
.chat-panel-toolbar-close {
    flex-shrink: 0;
    margin-left: auto;
    background: none;
    border: none;
    padding: var(--space-1);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast);
}
.chat-panel-toolbar-close:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
.chat-panel-toolbar-close .material-symbols-outlined {
    font-size: 18px;
}

/* === Body (messages area) === */

.chat-panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-panel-messages {
    list-style: none;
    padding: var(--space-3);
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    overflow-y: auto;
    flex: 1;
    min-height: 200px;
}

/* === Input area === */

.chat-panel-input-area {
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--border-primary);
}

.chat-panel-form {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.chat-panel-input {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    resize: none;
    outline: none;
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color var(--transition-fast);
}

.chat-panel-input::placeholder {
    color: var(--text-tertiary);
}

.chat-panel-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.chat-panel-send-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--brand-primary);
    color: var(--text-inverse);
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast);
}

.chat-panel-send-btn:hover {
    background-color: var(--brand-primary-hover);
}

/* [2026-08-22] Селектор переведён на `material-icons` вслед за разметкой кнопки
   (ChatThreadPanel.js): иконка отправки приведена к канону проекта ради
   единообразия трёх композеров. Без этой правки правило стало бы мёртвым, а
   иконка потеряла бы заданный размер. Ref: DESIGN.md.
   Chat: chat-composers-uniformity-2026-08-22. */
.chat-panel-send-btn .material-icons {
    font-size: 18px;
}

.chat-filter-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition:
        color var(--transition-fast),
        background-color var(--transition-fast);
}

.chat-filter-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-hover);
}

.chat-filter-btn.active {
    color: var(--text-primary);
    background-color: var(--bg-hover);
}

.chat-filter-btn .material-symbols-outlined {
    font-size: 18px;
}

/* === States === */

.chat-panel-empty,
.chat-panel-loading,
.chat-panel-error {
    text-align: center;
    padding: var(--space-6);
    color: var(--text-tertiary);
    font-size: var(--font-size-sm);
}

.chat-panel-error {
    color: var(--color-error);
}

/* === Bubble additions for ChatPanel === */

.chat-bubble__name {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--brand-primary);
    margin-bottom: 2px;
}

/* Hide name on grouped messages (same author consecutive) */
.chat-bubble--grouped .chat-bubble__name {
    display: none;
}

.chat-bubble__time {
    font-size: 11px;
    color: var(--text-tertiary);
}

.chat-bubble--pending {
    opacity: 0.6;
}

/* === Dark theme === */

[data-theme='dark'] .chat-panel-container {
    box-shadow: var(--shadow-xl);
    border-color: var(--border-primary);
}

[data-theme='dark'] .chat-panel-header {
    border-bottom: none;
}

[data-theme='dark'] .chat-panel-input-area {
    border-top-color: var(--border-primary);
}

/* === Mobile responsive === */

@media (max-width: 480px) {
    .chat-panel-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        max-height: 70vh;
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    }

    /* toggle is inline in footer bar, no mobile override needed */
}

/* === Message status icons === */

.chat-bubble__status {
    display: inline-flex;
    margin-left: 4px;
    color: var(--text-tertiary, #9ca3af);
}

.chat-bubble__status .material-icons {
    font-size: 14px;
}

.chat-bubble__status--read {
    color: var(--brand-primary, #3b82f6);
}

.chat-bubble__edited {
    font-size: 11px;
    color: var(--text-tertiary, #9ca3af);
    margin-left: 4px;
    font-style: italic;
}

/* R20 soft-deleted message body — neutral muted placeholder. */
.chat-bubble__deleted {
    color: var(--text-tertiary, #9ca3af);
    font-style: italic;
    user-select: none;
}

/* R20 reply-quote preview when the quoted message is soft-deleted. */
.chat-bubble__reply-text--deleted {
    color: var(--text-tertiary, #9ca3af);
    font-style: italic;
    opacity: 0.85;
}

/* R20 active reply composer when target is soft-deleted. */
.chat-reply-bar__text--deleted {
    color: var(--text-tertiary, #9ca3af);
    font-style: italic;
}

/* R20 (edited) badge becomes interactive — clicking opens history popover. */
.chat-bubble__edited[data-action='show-history'] {
    cursor: pointer;
}
.chat-bubble__edited[data-action='show-history']:hover,
.chat-bubble__edited[data-action='show-history']:focus {
    color: var(--text-secondary, #6b7280);
    outline: none;
}

/* R20 inline edit-history popover anchored under the bubble. */
.chat-bubble__history {
    position: absolute;
    bottom: -4px;
    left: 0;
    transform: translateY(100%);
    background: var(--bg-elevated, #ffffff);
    border: 1px solid var(--border-subtle, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    padding: 8px 10px;
    min-width: 200px;
    max-width: 320px;
    z-index: 10;
    font-size: 12px;
}
.chat-bubble__history-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-secondary, #6b7280);
}
.chat-bubble__history ol {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 4px;
}
.chat-bubble__history-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px;
    align-items: baseline;
}
.chat-bubble__history-ts {
    color: var(--text-tertiary, #9ca3af);
    font-size: 10px;
}
.chat-bubble__history-text {
    word-break: break-word;
}
.chat-bubble__history-empty {
    color: var(--text-tertiary, #9ca3af);
    font-style: italic;
}

/* === Context menu on hover === */

.chat-bubble__menu {
    display: none;
    position: absolute;
    top: -4px;
    right: 36px; /* offset past avatar */
    gap: 2px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    padding: 2px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.chat-bubble:hover .chat-bubble__menu {
    display: flex;
}

.chat-bubble {
    position: relative;
}

.chat-bubble__menu-btn {
    border: none;
    background: none;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    color: var(--text-tertiary, #9ca3af);
    display: flex;
    align-items: center;
}

.chat-bubble__menu-btn:hover {
    background: var(--bg-tertiary, #f3f4f6);
    color: var(--text-primary, #111);
}

.chat-bubble__menu-btn .material-icons {
    font-size: 16px;
}

/* === Reply bar above input === */

.chat-reply-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--bg-tertiary, #f3f4f6);
    border-left: 3px solid var(--brand-primary, #3b82f6);
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
}

.chat-reply-bar__text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-reply-bar__close {
    border: none;
    background: none;
    cursor: pointer;
    padding: 2px;
    color: var(--text-tertiary, #9ca3af);
}

.chat-reply-bar__close .material-icons {
    font-size: 16px;
}

/* === Reply quote in bubble === */

.chat-bubble__reply {
    padding: 4px 8px;
    margin-bottom: 4px;
    background: rgba(0, 0, 0, 0.04);
    border-left: 2px solid var(--brand-primary, #3b82f6);
    border-radius: 4px;
    font-size: 12px;
}

.chat-bubble__reply-name {
    font-weight: 600;
    color: var(--brand-primary, #3b82f6);
    margin-right: 4px;
}

.chat-bubble__reply-text {
    color: var(--text-tertiary, #9ca3af);
}

/* === Inline edit === */

.chat-edit-input {
    width: 100%;
    min-height: 40px;
    padding: 6px 8px;
    border: 1px solid var(--brand-primary, #3b82f6);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
}

/* Kill the browser default 3px white focus outline — it stacks on
   top of the brand-blue border and reads as a thick white frame on
   dark themes. The brand border IS the focus indicator (textarea is
   always focused while the editor is open), so a separate outline
   is redundant. UX 2026-05-16. */
.chat-edit-input:focus,
.chat-edit-input:focus-visible {
    outline: none;
}

.chat-edit-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    justify-content: flex-end;
}

.chat-edit-save,
.chat-edit-cancel {
    padding: 4px 12px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.chat-edit-save {
    background: var(--brand-primary, #3b82f6);
    color: #fff;
}

.chat-edit-cancel {
    background: var(--bg-tertiary, #f3f4f6);
    color: var(--text-secondary, #6b7280);
}

/* [2026-08-22] УДАЛЕНО правило `.chat-node--composer` — отдельного редактора
   ответа больше нет. PO 2026-08-22 (со скрином): «reply использует собственное
   поле для ввода текста при том, что есть основное в общем чате, нужно сделать
   одно поле». Ответ пишется в общее поле панели, адресат показывается полосой
   `.chat-reply-bar` над ним. Класс не ставит никто — по канону это мёртвая
   разметка, поэтому стиль удалён, а не оставлен «на всякий случай».
   Ref: docs/QA_CHAT_COMPOSERS_UNIFORMITY_2026-08-22.md. Chat: chat-single-input-reply-2026-08-22. */
