/* Стили диалогов */
.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-style: italic;
}

.error {
    text-align: center;
    padding: 20px;
    color: var(--danger-color);
    font-style: italic;
    border: none !important; /* Принудительно убираем границы */
}

/* Локальная нормализация только для области диалогов */
.dialogs-full-container,
.dialogs-full-container * {
    box-sizing: border-box;
}

/* Стили для контентных областей диалогов - максимально близко к sidebar */
.chat-container,
.dialogs-container,
.messages-container {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    position: relative !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

/* Стили для chatsList - растягиваем на всю высоту */
#chatsList {
    flex: 1 !important;
    overflow-y: auto !important;
    height: calc(100vh - 45px - 60px) !important; /* 45px header + 60px заголовок+поиск */
    min-height: 0 !important;
}

/* Контейнер диалогов занимает всю высоту */
.dialogs-full-container {
    position: fixed !important;
    top: 45px !important;
    left: 60px !important;
    right: 0 !important;
    bottom: 0 !important;
    display: flex !important;
    background: var(--border-color) !important;
}

/* When sidebar expands on hover (desktop), shift dialogs container accordingly */
.sidebar:hover ~ main .dialogs-full-container {
    left: var(--sidebar-width) !important;
}

/* Левая панель с диалогами */
.dialogs-left-panel {
    width: 420px !important;
    background: var(--card-bg) !important;
    display: flex !important;
    flex-direction: column !important;
}

.unread-pill {
    min-width: 20px;
    height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.18);
    color: var(--text-primary);
    font-size: 12px;
    line-height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Стили сообщений */
.message {
    margin-bottom: 12px;
    display: flex;
    position: relative;
}

.message-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 72%;
}

.message.sent {
    justify-content: flex-end;
}

.message.received {
    justify-content: flex-start;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 11px;
    font-weight: bold;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.message-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    position: absolute;
    inset: 0;
}

.message-avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.message-sender {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.message.sent .message-sender {
    text-align: right;
}

.message-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.25;
}

/* Media inside message bubble */
.message-media {
    margin-top: 8px;
}

.message-media-img {
    max-width: 320px;
    max-height: 240px;
    width: auto;
    height: auto;
    object-fit: cover;
    border-radius: 10px;
    display: block;
    background: rgba(0,0,0,0.06);
    cursor: zoom-in;
}

.media-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 99999;
}

.media-lightbox.visible {
    display: flex;
}

.media-lightbox img {
    max-width: min(100%, 1100px);
    max-height: min(100%, 90vh);
    width: auto;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.35);
    cursor: zoom-out;
}

.message-media-placeholder {
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(0,0,0,0.06);
    color: var(--text-secondary);
    font-size: 13px;
}

#chatBadges {
    display: none;
    gap: 6px;
    flex-wrap: wrap;
}

.chat-header-badge {
    font-size: 11px;
    opacity: 0.75;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 1px 6px;
    line-height: 1.4;
}

.message-reactions {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.message-bubble.message-failed {
    outline: 1px solid rgba(239, 68, 68, 0.55);
}

.message.sent .message-bubble {
    background: var(--primary-color);
    color: white;
    border-radius: 12px 12px 4px 12px;
}

.message.received .message-bubble {
    background: var(--card-bg);
    color: var(--text-primary);
    border-radius: 12px 12px 12px 4px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.message-status {
    font-size: 9px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.message-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

.message.sent .message-meta {
    text-align: right;
}

.message.sent .message-status {
    text-align: right;
}

/* Стили элементов диалога */
.chat-item {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.2s;
}

.chat-item:hover {
    background: var(--hover-bg);
}

.chat-item.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--text-primary);
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    color: white;
    font-weight: bold;
    flex-shrink: 0;
    font-size: 14px;
    overflow: hidden;
    position: relative;
}

.chat-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-avatar-fallback {
    position: absolute;
    inset: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* По умолчанию показываем fallback (инициалы), скрываем только когда картинка точно загрузилась */
.chat-avatar.has-image .chat-avatar-fallback {
    opacity: 0;
}

.chat-avatar.fallback .chat-avatar-img {
    display: none;
}

/* Заголовок чата использует #chatAvatar как контейнер аватара */
#chatAvatar {
    overflow: hidden;
    position: relative;
}

#chatAvatar .chat-avatar-fallback {
    position: absolute;
    inset: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#chatAvatar.has-image .chat-avatar-fallback {
    opacity: 0;
}

#chatAvatar.fallback .chat-avatar-img {
    display: none;
}

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    margin-left: 6px;
    flex-shrink: 0;
}

.unread-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--primary-color);
    color: #fff;
    font-size: 12px;
    line-height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
}

.chat-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 6px;
    flex-shrink: 0;
}

.chat-item.active .chat-preview,
.chat-item.active .chat-time {
    color: var(--text-secondary);
}
