/* ============================================
   UnifiedChat — Единый дизайн мессенджера
   Стиль: современный, Telegram/WhatsApp-inspired
   Namespace: .uc-*
   @version 1.2.0
   ============================================ */

:root {
    --uc-bg: #e8edf2;
    --uc-own-bg: #3b82f6;
    --uc-own-text: #ffffff;
    --uc-other-bg: #ffffff;
    --uc-other-text: #1e293b;
    --uc-bubble-radius: 18px;
    --uc-bubble-tail: 4px;
    --uc-input-bg: #ffffff;
    --uc-input-border: #e2e8f0;
    --uc-header-bg: #ffffff;
    --uc-sidebar-bg: #f8fafc;
    --uc-avatar-size: 28px;
    --uc-avatar-size-sm: 24px;
    --uc-accent: #3b82f6;
    --uc-accent-hover: #2563eb;
    --uc-danger: #ef4444;
    --uc-muted: #94a3b8;
    --uc-border: #e2e8f0;
    --uc-shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --uc-shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --uc-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Полноэкранный мессенджер — Макет
   ============================================ */

.uc-messenger {
    display: flex;
    height: calc(100vh - 56px);
    background: var(--uc-bg);
    overflow: hidden;
    border-radius: 12px;
    box-shadow: var(--uc-shadow-md);
    margin: 0;
}

/* --- Панель контактов --- */

.uc-contacts-panel {
    width: 340px;
    min-width: 300px;
    background: var(--uc-sidebar-bg);
    border-right: 1px solid var(--uc-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.uc-contacts-header {
    padding: 16px;
    background: var(--uc-header-bg);
    border-bottom: 1px solid var(--uc-border);
}

.uc-contacts-header h5 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
}

.uc-search-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--uc-border);
    border-radius: 24px;
    font-size: 14px;
    background: #f1f5f9;
    transition: var(--uc-transition);
    outline: none;
}

.uc-search-input:focus {
    border-color: var(--uc-accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.uc-contacts-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.uc-contacts-list::-webkit-scrollbar {
    width: 4px;
}

.uc-contacts-list::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 4px;
}

/* --- Элемент контакта --- */

.uc-contact-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--uc-transition);
    text-decoration: none;
    color: inherit;
    margin-bottom: 2px;
    position: relative;
}

.uc-contact-item:hover {
    background: #e2e8f0;
    text-decoration: none;
    color: inherit;
}

.uc-contact-item.active,
.uc-contact-item--active {
    background: var(--uc-accent);
    color: #fff;
}

.uc-contact-item.active .uc-contact-name,
.uc-contact-item--active .uc-contact-name {
    color: #fff;
}

.uc-contact-item.active .uc-contact-preview,
.uc-contact-item--active .uc-contact-preview,
.uc-contact-item.active .uc-contact-time,
.uc-contact-item--active .uc-contact-time {
    color: rgba(255,255,255,0.8);
}

.uc-contact-avatar {
    width: var(--uc-avatar-size);
    height: var(--uc-avatar-size);
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    flex-shrink: 0;
}

.uc-contact-avatar--placeholder {
    width: var(--uc-avatar-size);
    height: var(--uc-avatar-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--uc-accent), #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 11px;
    margin-right: 12px;
    flex-shrink: 0;
}

.uc-contact-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.uc-contact-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.uc-contact-name {
    font-weight: 600;
    font-size: 14px;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.uc-contact-time {
    font-size: 11px;
    color: var(--uc-muted);
    white-space: nowrap;
    margin-left: 8px;
}

.uc-contact-bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2px;
}

.uc-contact-preview {
    font-size: 13px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.uc-contact-badge {
    background: var(--uc-danger);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    margin-left: 8px;
    flex-shrink: 0;
}

.uc-contact-badge.d-none {
    display: none !important;
}

.uc-contact-online-dot {
    position: absolute;
    bottom: 12px;
    left: 40px;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid var(--uc-sidebar-bg);
}

/* --- Панель чата --- */

.uc-chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--uc-bg);
}

.uc-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--uc-header-bg);
    border-bottom: 1px solid var(--uc-border);
    box-shadow: var(--uc-shadow-sm);
    z-index: 10;
    flex-shrink: 0;
}

.uc-chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.uc-chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
}

.uc-chat-header-avatar-placeholder {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--uc-accent), #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
}

.uc-chat-header-info {
    min-width: 0;
}

.uc-chat-header-name {
    font-weight: 700;
    font-size: 16px;
    color: #1e293b;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.uc-chat-header-status {
    font-size: 12px;
    color: var(--uc-muted);
}

.uc-chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.uc-header-btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--uc-border);
    background: #fff;
    color: #475569;
    font-size: 13px;
    cursor: pointer;
    transition: var(--uc-transition);
    white-space: nowrap;
}

.uc-header-btn:hover {
    background: #f1f5f9;
    border-color: var(--uc-accent);
    color: var(--uc-accent);
}

.uc-back-btn {
    display: none;
    padding: 8px;
    border: none;
    background: none;
    color: var(--uc-accent);
    font-size: 18px;
    cursor: pointer;
}

.uc-search-bar .uc-back-btn {
    display: flex;
}

.uc-chat-header-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
}

.uc-search-bar {
    display: none;
    align-items: center;
    width: 100%;
    gap: 8px;
}

.uc-search-input-header {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--uc-border);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    background: #fff;
}

.uc-search-input-header:focus {
    border-color: var(--uc-accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.uc-search-count {
    font-size: 13px;
    color: var(--uc-muted);
    white-space: nowrap;
    padding: 4px 8px;
    background: #f1f5f9;
    border-radius: 12px;
}

.uc-search-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
}

.uc-search-nav-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--uc-border);
    background: #fff;
    color: var(--uc-accent);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.uc-search-nav-btn:hover {
    background: var(--uc-accent);
    color: #fff;
    border-color: var(--uc-accent);
}

.uc-search-highlight {
    background: #fef08a;
    color: #000;
    padding: 0 2px;
    border-radius: 2px;
}

.uc-header-icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--uc-accent);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--uc-transition);
}

.uc-header-icon-btn:hover {
    background: rgba(59, 130, 246, 0.1);
}

.uc-header-dropdown {
    position: relative;
}

.uc-dropdown-toggle {
    position: relative;
}

.uc-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 180px;
    background: #fff;
    border: 1px solid var(--uc-border);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 6px 0;
    display: none;
    z-index: 100;
    margin-top: 8px;
}

.uc-dropdown-menu.show {
    display: block;
    animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.uc-dropdown-item {
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    text-align: left;
    font-size: 14px;
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--uc-transition);
}

.uc-dropdown-item:hover {
    background: #f1f5f9;
    color: var(--uc-accent);
}

.uc-dropdown-item i {
    width: 20px;
    text-align: center;
}

/* --- Область сообщений --- */

.uc-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--uc-bg);
}

.uc-messages-area::-webkit-scrollbar {
    width: 6px;
}

.uc-messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.uc-messages-area::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 3px;
}

.uc-messages-area::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.25);
}

.uc-empty-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--uc-muted);
    text-align: center;
    padding: 40px;
}

.uc-empty-chat i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.uc-empty-chat p {
    font-size: 15px;
    margin: 0;
}

/* --- Сообщение (bubble) --- */

.uc-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 75%;
    animation: uc-slide-in 0.25s ease-out;
}

.uc-message--own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.uc-message--other {
    align-self: flex-start;
}

.uc-message--compact {
    max-width: 90%;
}

.uc-message--unread {
    /* Подсветка непрочитанных */
}

.uc-message--unread .uc-bubble {
    border-left: 3px solid var(--uc-accent);
}

.uc-message-avatar {
    flex-shrink: 0;
    margin-bottom: 4px;
    width: 24px;
    height: 24px;
}

.uc-message-avatar .uc-avatar {
    width: 24px;
    height: 24px;
}

.uc-avatar {
    width: var(--uc-avatar-size-sm);
    height: var(--uc-avatar-size-sm);
    border-radius: 50%;
    object-fit: cover;
}

.uc-avatar--placeholder {
    background: linear-gradient(135deg, var(--uc-accent), #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 11px;
}

.uc-bubble {
    padding: 10px 14px;
    border-radius: var(--uc-bubble-radius);
    position: relative;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-shadow: var(--uc-shadow-sm);
}

.uc-message--own .uc-bubble {
    background: var(--uc-own-bg);
    color: var(--uc-own-text);
    border-bottom-right-radius: var(--uc-bubble-tail);
}

.uc-message--other .uc-bubble {
    background: var(--uc-other-bg);
    color: var(--uc-other-text);
    border-bottom-left-radius: var(--uc-bubble-tail);
    border: 1px solid #e8ecf0;
}

.uc-sender-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--uc-accent);
    margin-bottom: 4px;
}

.uc-message--own .uc-sender-name {
    color: rgba(255,255,255,0.8);
}

.uc-bubble-text {
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.uc-bubble-images {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.uc-bubble-image {
    max-width: 240px;
    max-height: 240px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s ease;
    object-fit: cover;
}

.uc-bubble-image:hover {
    transform: scale(1.03);
}

.uc-bubble-image--temp {
    opacity: 0.6;
}

.uc-bubble-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
}

.uc-time {
    font-size: 11px;
    opacity: 0.6;
}

.uc-message--own .uc-time {
    color: rgba(255,255,255,0.7);
}

.uc-delivery-icon {
    font-size: 13px;
    color: rgba(255,255,255,0.45);
    margin-left: 2px;
    transition: color 0.2s ease;
}

.uc-delivery-icon--read {
    color: #34d399 !important;
    opacity: 1;
}

.uc-message--own .uc-delivery-icon {
    color: rgba(255,255,255,0.5);
}

.uc-message--own .uc-delivery-icon--read {
    color: #6ee7b7 !important;
    opacity: 1;
}

.uc-message--other .uc-delivery-icon {
    color: #94a3b8;
}

.uc-message--other .uc-delivery-icon--read {
    color: #34d399 !important;
}

/* --- Typing indicator --- */

.uc-typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--uc-accent);
    font-style: italic;
    min-height: 28px;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.uc-typing-indicator.active {
    opacity: 1;
    transform: translateY(0);
}

.uc-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.uc-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--uc-accent);
    animation: uc-typing-bounce 1.4s infinite ease-in-out both;
}

.uc-typing-dots span:nth-child(1) { animation-delay: 0s; }
.uc-typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.uc-typing-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes uc-typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* --- Pencil typing animation --- */
.uc-typing-pencil {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.uc-typing-pencil-icon {
    width: 20px;
    height: 20px;
    position: relative;
}

.uc-typing-pencil-icon svg {
    width: 100%;
    height: 100%;
    animation: uc-pencil-write 0.6s ease-in-out infinite;
}

@keyframes uc-pencil-write {
    0%, 100% {
        transform: rotate(0deg) translateY(0);
    }
    25% {
        transform: rotate(-15deg) translateY(-2px);
    }
    50% {
        transform: rotate(10deg) translateY(1px);
    }
    75% {
        transform: rotate(-5deg) translateY(-1px);
    }
}

.uc-typing-text {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.uc-typing-text::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--uc-accent);
    animation: uc-typing-dot-pulse 1s ease-in-out infinite;
}

@keyframes uc-typing-dot-pulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* --- Date separator (Telegram style) --- */
.uc-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 8px 0;
    padding: 0 16px;
}

.uc-date-separator__text {
    background: rgba(0, 0, 0, 0.25);
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* --- Статус прочтения --- */

.uc-read-status {
    margin-top: 4px;
}

.uc-read-icons {
    display: flex;
    gap: 2px;
    justify-content: flex-end;
}

.uc-read-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    overflow: hidden;
    border: 1.5px solid var(--uc-accent);
    cursor: pointer;
    position: relative;
    transition: var(--uc-transition);
}

.uc-read-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.uc-read-icon--unread {
    border-color: #d1d5db;
    opacity: 0.5;
}

.uc-read-icon:hover {
    transform: scale(1.2);
}

/* --- Кнопка "Отметить как прочитанное" --- */

.uc-mark-read-wrap {
    margin-top: 4px;
}

.uc-mark-read-btn {
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid var(--uc-border);
    background: #fff;
    color: #64748b;
    font-size: 11px;
    cursor: pointer;
    transition: var(--uc-transition);
}

.uc-mark-read-btn:hover {
    background: var(--uc-accent);
    color: #fff;
    border-color: var(--uc-accent);
}

/* --- Область ввода --- */

.uc-input-area {
    padding: 12px 20px;
    background: var(--uc-header-bg);
    border-top: 1px solid var(--uc-border);
    flex-shrink: 0;
}

.uc-input-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.uc-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.uc-input-field {
    flex: 1;
    padding: 10px 16px;
    border-radius: 24px;
    border: 1px solid var(--uc-input-border);
    font-size: 14px;
    background: #f8fafc;
    outline: none;
    transition: var(--uc-transition);
}

.uc-input-field:focus {
    border-color: var(--uc-accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.uc-input-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: none;
    color: #64748b;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--uc-transition);
    flex-shrink: 0;
}

.uc-input-btn:hover {
    background: #f1f5f9;
    color: var(--uc-accent);
}

.uc-send-btn {
    background: var(--uc-accent);
    color: #fff;
}

.uc-send-btn:hover {
    background: var(--uc-accent-hover);
    color: #fff;
    transform: scale(1.05);
}

/* --- Превью изображений --- */

.uc-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0;
}

.uc-preview-container:empty {
    display: none;
}

.uc-preview-item {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid var(--uc-border);
}

.uc-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.uc-preview-remove {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--uc-danger);
    color: #fff;
    border: none;
    font-size: 9px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.uc-preview-clear-btn {
    padding: 4px 12px;
    border-radius: 8px;
    border: 1px solid var(--uc-danger);
    background: none;
    color: var(--uc-danger);
    font-size: 12px;
    cursor: pointer;
    transition: var(--uc-transition);
}

.uc-preview-clear-btn:hover {
    background: var(--uc-danger);
    color: #fff;
}

/* --- Drop zone --- */

.uc-drop-zone {
    position: absolute;
    inset: 0;
    background: rgba(59, 130, 246, 0.08);
    border: 2px dashed var(--uc-accent);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.uc-drop-zone-content {
    text-align: center;
    color: var(--uc-accent);
}

.uc-drop-zone-content i {
    font-size: 40px;
    margin-bottom: 8px;
}

.uc-drop-zone-content p {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
}

/* ============================================
   Модальный просмотр изображений
   ============================================ */

.uc-image-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    animation: uc-fade-in 0.2s ease;
}

.uc-image-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.uc-image-modal-controls {
    display: flex;
    gap: 8px;
    padding: 16px;
    justify-content: center;
}

.uc-image-modal-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--uc-transition);
    text-decoration: none;
}

.uc-image-modal-btn:hover {
    background: rgba(255,255,255,0.25);
    color: #fff;
}

.uc-image-modal-btn--close {
    background: rgba(239, 68, 68, 0.6);
}

.uc-image-modal-btn--close:hover {
    background: rgba(239, 68, 68, 0.8);
}

.uc-image-modal-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px 20px;
    overflow: hidden;
    cursor: pointer;
    width: 100%;
}

.uc-image-modal-img {
    max-width: 90%;
    max-height: calc(100vh - 100px);
    border-radius: 8px;
    box-shadow: 0 4px 30px rgba(0,0,0,0.4);
    transition: transform 0.2s ease;
    cursor: default;
}

/* ============================================
   Sidebar мини-чат — Доп. стили
   (основной sidebar остаётся в style.css)
   ============================================ */

/* Обновлённые стили для сообщений в sidebar мини-чате */
.bitrix-mini-chat .uc-messages-area {
    padding: 12px;
    gap: 2px;
}

.bitrix-mini-chat .uc-message {
    max-width: 90%;
}

.bitrix-mini-chat .uc-message--compact .uc-bubble {
    padding: 8px 12px;
    border-radius: 14px;
}

.bitrix-mini-chat .uc-message--compact .uc-bubble-text {
    font-size: 13px;
}

.bitrix-mini-chat .uc-message--compact .uc-bubble-image {
    max-width: 180px;
    max-height: 180px;
}

.bitrix-mini-chat .uc-message--own .uc-bubble {
    border-bottom-right-radius: var(--uc-bubble-tail);
}

.bitrix-mini-chat .uc-message--other .uc-bubble {
    border-bottom-left-radius: var(--uc-bubble-tail);
}

/* Стили для модернизированного sidebar input */
.bitrix-mini-chat .uc-input-area {
    padding: 10px 12px;
}

/* ============================================
   Анимации
   ============================================ */

@keyframes uc-slide-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes uc-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================
   Адаптивность — Мобильная версия
   ============================================ */

@media (max-width: 768px) {
    .uc-messenger {
        flex-direction: column;
        border-radius: 0;
        box-shadow: none;
        margin: -20px;
        width: calc(100% + 40px);
        height: calc(100vh - 120px);
    }

    .uc-contacts-panel {
        width: 100%;
        min-width: auto;
        border-right: none;
        border-bottom: 1px solid var(--uc-border);
    }

    /* Когда чат открыт, скрываем контакты */
    .uc-messenger--chat-open .uc-contacts-panel {
        display: none;
    }

    .uc-messenger--chat-open .uc-chat-panel {
        height: 100%;
    }

    /* Показываем кнопку "Назад" */
    .uc-messenger--chat-open .uc-back-btn {
        display: flex;
    }

    .uc-chat-panel {
        height: 0;
        flex: 1;
    }

    /* Если чат не выбран, скрываем панель чата */
    .uc-messenger:not(.uc-messenger--chat-open) .uc-chat-panel {
        display: none;
    }

    .uc-message {
        max-width: 85%;
    }

    .uc-messages-area {
        padding: 12px;
    }

    .uc-input-area {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .uc-input-field {
        font-size: 16px; /* Предотвращает зум на iOS */
    }

    .uc-bubble-image {
        max-width: 200px;
        max-height: 200px;
    }

    /* Мини-чат sidebar в мобильной версии */
    .bitrix-mini-chat .uc-messages-area {
        padding: 10px;
        flex: 1;
        min-height: 0;
    }

    .bitrix-mini-chat .uc-input-area {
        padding: 8px 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .bitrix-mini-chat .uc-input-row {
        gap: 4px;
    }

    .bitrix-mini-chat .uc-input-field {
        min-width: 0;
        flex: 1;
        padding: 8px 12px;
    }

    .bitrix-mini-chat .uc-input-btn {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }
}

@media (max-width: 480px) {
    .uc-message {
        max-width: 90%;
    }

    .uc-bubble-image {
        max-width: 160px;
        max-height: 160px;
    }

    .uc-chat-header {
        padding: 10px 12px;
    }

    .uc-header-icon-btn {
        width: 44px;
        height: 44px;
    }

    .uc-header-icon-btn:first-child {
        margin-left: -8px;
    }

    .uc-dropdown-menu {
        min-width: 200px;
    }

    .uc-dropdown-item {
        padding: 12px 16px;
    }

    /* Ещё более компактный input на маленьких экранах */
    .bitrix-mini-chat .uc-input-row {
        gap: 2px;
    }

    .bitrix-mini-chat .uc-input-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .bitrix-mini-chat .uc-input-field {
        padding: 6px 10px;
        font-size: 14px;
    }
}

/* ============================================
   Совместимость со старыми стилями
   (мини-чат продолжает использовать .bitrix-chat-messages)
   ============================================ */

/* Стили сообщений sidebar через новые классы */
.bitrix-chat-messages .uc-message {
    margin-bottom: 2px;
}

/* Миниатюра в списке контактов */
.uc-contact-mini-image {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    object-fit: cover;
    margin-left: 4px;
}

/* ==========================================
   Реакции и ответы (reply)
   ========================================== */

/* Reply preview внутри пузыря */
.uc-reply-preview {
    background: rgba(0,0,0,0.06);
    border-left: 3px solid var(--uc-accent, #3b82f6);
    border-radius: 4px;
    padding: 6px 10px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.15s;
    max-width: 100%;
    overflow: hidden;
}
.uc-reply-preview:hover { background: rgba(0,0,0,0.1); }
.uc-message--own .uc-reply-preview {
    background: rgba(255,255,255,0.15);
    border-left-color: rgba(255,255,255,0.6);
}
.uc-message--own .uc-reply-preview:hover { background: rgba(255,255,255,0.25); }
.uc-reply-preview-name {
    font-weight: 600;
    font-size: 12px;
    color: var(--uc-accent, #3b82f6);
    margin-bottom: 2px;
}
.uc-message--own .uc-reply-preview-name { color: rgba(255,255,255,0.9); }
.uc-reply-preview-text {
    font-size: 12px;
    color: var(--uc-text-secondary, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.uc-message--own .uc-reply-preview-text { color: rgba(255,255,255,0.7); }

/* Реакции под сообщением */
.uc-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
    padding: 2px 0;
}
.uc-reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.08);
    background: rgba(0,0,0,0.04);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.4;
}
.uc-reaction-badge:hover {
    background: rgba(0,0,0,0.08);
    transform: scale(1.05);
}
.uc-reaction-badge--own {
    background: rgba(59,130,246,0.12);
    border-color: rgba(59,130,246,0.3);
}
.uc-reaction-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--uc-text-secondary, #6b7280);
}
.uc-reaction-badge--own .uc-reaction-count { color: var(--uc-accent, #3b82f6); }

/* Панель действий (hover) */
.uc-message {
    position: relative;
}
.uc-message-actions {
    position: absolute;
    top: 4px;
    display: none;
    gap: 2px;
    background: var(--uc-bg-primary, #fff);
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 8px;
    padding: 2px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    z-index: 10;
}
.uc-message--other .uc-message-actions { right: -8px; }
.uc-message--own .uc-message-actions { left: -8px; }
.uc-message:hover .uc-message-actions { display: flex; }
.uc-action-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--uc-text-secondary, #6b7280);
    transition: background 0.15s;
}
.uc-action-btn:hover { background: rgba(0,0,0,0.06); }

/* Quick reaction picker */
.uc-quick-reaction-picker {
    position: absolute;
    top: -44px;
    display: flex;
    gap: 2px;
    background: var(--uc-bg-primary, #fff);
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 20px;
    padding: 4px 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 20;
    animation: uc-picker-pop 0.15s ease-out;
}
.uc-message--other .uc-quick-reaction-picker { left: 40px; }
.uc-message--own .uc-quick-reaction-picker { right: 0; }
@keyframes uc-picker-pop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.uc-quick-reaction-btn {
    width: 34px;
    height: 34px;
    border: none;
    background: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background 0.1s;
}
.uc-quick-reaction-btn:hover {
    background: rgba(0,0,0,0.06);
    transform: scale(1.25);
}

/* Reply input bar (над полем ввода) */
.uc-reply-input-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--uc-bg-secondary, #f3f4f6);
    border-top: 1px solid rgba(0,0,0,0.06);
    border-radius: 8px 8px 0 0;
    animation: uc-slide-up 0.15s ease-out;
}
@keyframes uc-slide-up {
    from { transform: translateY(8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.uc-reply-input-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}
.uc-reply-input-icon {
    color: var(--uc-accent, #3b82f6);
    font-size: 14px;
    flex-shrink: 0;
}
.uc-reply-input-content { min-width: 0; flex: 1; }
.uc-reply-input-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--uc-accent, #3b82f6);
}
.uc-reply-input-text {
    font-size: 12px;
    color: var(--uc-text-secondary, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.uc-reply-input-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--uc-text-secondary, #6b7280);
    padding: 4px;
    border-radius: 4px;
    font-size: 14px;
    flex-shrink: 0;
}
.uc-reply-input-close:hover { color: #ef4444; background: rgba(0,0,0,0.04); }

/* Highlight при скролле к replied сообщению */
.uc-message--highlight .uc-bubble {
    animation: uc-highlight-flash 2s ease-out;
}
@keyframes uc-highlight-flash {
    0%, 20% { box-shadow: 0 0 0 3px rgba(59,130,246,0.4); }
    100% { box-shadow: none; }
}

/* Compact mode adjustments */
.uc-message--compact .uc-reply-preview { padding: 4px 8px; }
.uc-message--compact .uc-message-actions { top: 0; }
.uc-message--compact .uc-reactions { margin-top: 2px; }
