/**
 * FCNC Chat - Стили
 * Дизайн-система FactoryCNC: #667eea → #764ba2
 */

/* ============================================================
   ПЕРЕМЕННЫЕ
   ============================================================ */
   :root {
    --fcnc-primary: #667eea;
    --fcnc-secondary: #764ba2;
    --fcnc-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    
    --fcnc-success: #4caf50;
    --fcnc-error: #dc3545;
    --fcnc-warning: #ff9800;
    
    --fcnc-bg-light: #f8f9fa;
    --fcnc-bg-white: #ffffff;
    --fcnc-border: #e0e0e0;
    
    --fcnc-text-dark: #333;
    --fcnc-text-medium: #666;
    --fcnc-text-light: #999;
    
    --fcnc-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --fcnc-shadow-md: 0 4px 16px rgba(102, 126, 234, 0.15);
    --fcnc-shadow-lg: 0 8px 24px rgba(102, 126, 234, 0.25);
    
    --fcnc-radius: 12px;
    --fcnc-radius-sm: 8px;
    --fcnc-radius-lg: 16px;
    
    --fcnc-transition: 0.3s ease;
}

/* ============================================================
   СТРАНИЦА ЧАТА
   ============================================================ */
.fcnc-chat-page {
    max-width: 1600px;
    margin: 40px auto;
    padding: 0 20px;
}

/* ============================================================
   HEADER ЧАТА
   ============================================================ */
.fcnc-chat-header {
    background: var(--fcnc-gradient);
    color: white;
    padding: 30px 40px;
    border-radius: var(--fcnc-radius-lg);
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--fcnc-shadow-lg);
}

.fcnc-chat-logo h1 {
    margin: 0 0 5px 0;
    font-size: 28px;
    font-weight: 700;
}

.fcnc-chat-logo p {
    margin: 0;
    opacity: 0.9;
    font-size: 15px;
}

.fcnc-btn-back {
    background: rgba(255, 255, 255, 0.2);
    -webkit-backdrop-filter: blur(10px); /* Safari */
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white !important;
    padding: 12px 24px;
    border-radius: var(--fcnc-radius-sm);
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--fcnc-transition);
    font-weight: 500;
}

.fcnc-btn-back:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ============================================================
   ГОРИЗОНТАЛЬНОЕ МЕНЮ ПАПОК (НОВОЕ!)
   ============================================================ */
.fcnc-folders-menu {
    background: var(--fcnc-bg-white);
    border-radius: var(--fcnc-radius);
    box-shadow: var(--fcnc-shadow-sm);
    padding: 10px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
}

.fcnc-folders-menu-items {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 1;
    overflow: hidden;
}

/* Миниатюрные ссылки папок */
.fcnc-folder-menu-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--fcnc-radius-sm);
    text-decoration: none !important;
    color: var(--fcnc-text-dark);
    font-size: 14px;
    font-weight: 500;
    transition: var(--fcnc-transition);
    cursor: pointer;
    white-space: nowrap;
    border: 1px solid transparent;
}

.fcnc-folder-menu-link:hover {
    background: rgba(102, 126, 234, 0.1);
    color: var(--fcnc-primary);
    border-color: rgba(102, 126, 234, 0.2);
}

.fcnc-folder-menu-link.active {
    background: var(--fcnc-gradient);
    color: white;
    box-shadow: var(--fcnc-shadow-sm);
}

.fcnc-folder-menu-icon {
    font-size: 16px;
}

.fcnc-folder-menu-text {
    font-size: 14px;
}

/* Dropdown "...еще" */
.fcnc-folders-more-dropdown {
    position: relative;
    margin-right: 5px;
}

.fcnc-folders-more-btn {
    background: transparent;
    border: 1px solid var(--fcnc-border);
    color: var(--fcnc-text-medium);
    padding: 8px 12px;
    border-radius: var(--fcnc-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: var(--fcnc-transition);
}

.fcnc-folders-more-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    color: var(--fcnc-primary);
    border-color: var(--fcnc-primary);
}

.fcnc-folders-more-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 5px;
    background: white;
    border-radius: var(--fcnc-radius-sm);
    box-shadow: var(--fcnc-shadow-md);
    padding: 8px;
    min-width: 180px;
    z-index: 1000;
    display: none;
}

.fcnc-folders-more-menu.active {
    display: block;
}

.fcnc-folders-more-menu .fcnc-folder-menu-link {
    display: flex;
    width: 100%;
    margin-bottom: 2px;
}

/* Кнопка "Создать папку" */
.fcnc-folder-menu-create {
    background: transparent;
    border: 1px solid var(--fcnc-border);
    color: var(--fcnc-text-dark);
    padding: 8px 12px;
    border-radius: var(--fcnc-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--fcnc-transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    margin-left: auto;
    flex-shrink: 0;
}

.fcnc-folder-menu-create:hover {
    background: var(--fcnc-gradient);
    color: white;
    border-color: transparent;
    box-shadow: var(--fcnc-shadow-sm);
}

.fcnc-folder-menu-create i {
    font-size: 12px;
}

/* ============================================================
   КНОПКИ ФИЛЬТРОВ (НАД ДИАЛОГОМ)
   ============================================================ */
.fcnc-filter-buttons {
    display: flex;
    gap: 10px;
    padding: 12px 15px;
    background: var(--fcnc-bg-light);
    border-radius: var(--fcnc-radius) var(--fcnc-radius) 0 0;
    border-bottom: 1px solid var(--fcnc-border);
    flex-shrink: 0; /* ✅ Не сжимается */
    z-index: 10;
}

.fcnc-filter-btn-mini {
    background: white;
    border: 1px solid var(--fcnc-border);
    color: var(--fcnc-text-dark);
    padding: 8px 16px;
    border-radius: var(--fcnc-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--fcnc-transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.fcnc-filter-btn-mini:hover {
    background: rgba(102, 126, 234, 0.1);
    color: var(--fcnc-primary);
    border-color: var(--fcnc-primary);
}

.fcnc-filter-btn-mini.active {
    background: var(--fcnc-gradient);
    color: white;
    border-color: transparent;
    box-shadow: var(--fcnc-shadow-sm);
}

.fcnc-filter-btn-mini .fcnc-filter-icon {
    font-size: 16px;
}

.fcnc-filter-btn-mini .fcnc-filter-label {
    font-size: 14px;
}

/* ============================================================
   WRAPPER ДИАЛОГА (для правильного скролла)
   ============================================================ */
.fcnc-dialog-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--fcnc-bg-white);
    border-radius: 0 0 var(--fcnc-radius) var(--fcnc-radius);
    min-height: 0; /* ✅ КРИТИЧНО: позволяет flex-контейнеру сжиматься */
}

.fcnc-dialog-container {
    display: flex;
    flex-direction: column;
    height: 100%; /* ✅ Растягивается на всю высоту wrapper */
}

/* ============================================================
   ОСНОВНОЙ КОНТЕЙНЕР (3 КОЛОНКИ)
   ============================================================ */
.fcnc-chat-container {
    display: grid;
    grid-template-columns: 280px 350px 1fr;
    gap: 20px;
    height: calc(100vh - 250px); /* ✅ Подстраивается под размер экрана */
    min-height: 600px; /* ✅ Минимальная высота */
}

/* ============================================================
   SIDEBAR (ПАПКИ)
   ============================================================ */
.fcnc-chat-sidebar {
    background: var(--fcnc-bg-white);
    border-radius: var(--fcnc-radius);
    box-shadow: var(--fcnc-shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fcnc-chat-sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--fcnc-border);
    background: var(--fcnc-bg-light);
}

.fcnc-chat-sidebar-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--fcnc-text-dark);
}

.fcnc-folders-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.fcnc-folder-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--fcnc-radius-sm);
    cursor: pointer;
    transition: var(--fcnc-transition);
    margin-bottom: 5px;
    position: relative;
}

.fcnc-folder-item:hover {
    background: var(--fcnc-bg-light);
}

.fcnc-folder-item.active {
    background: var(--fcnc-gradient);
    color: white;
}

.fcnc-folder-icon {
    font-size: 20px;
}

.fcnc-folder-name {
    flex: 1;
    font-weight: 500;
    font-size: 14px;
}

.fcnc-folder-actions {
    display: none;
    gap: 5px;
}

.fcnc-folder-item:hover .fcnc-folder-actions {
    display: flex;
}

.fcnc-folder-edit,
.fcnc-folder-delete {
    background: transparent;
    border: none;
    color: var(--fcnc-text-medium);
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: var(--fcnc-transition);
}

.fcnc-folder-edit:hover {
    background: rgba(102, 126, 234, 0.1);
    color: var(--fcnc-primary);
}

.fcnc-folder-delete:hover {
    background: rgba(220, 53, 69, 0.1);
    color: var(--fcnc-error);
}

.fcnc-btn-create-folder {
    background: rgba(255, 255, 255, 0.2);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white !important;
    padding: 12px 24px;
    border-radius: var(--fcnc-radius-sm);
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--fcnc-transition);
    font-weight: 500;
}

.fcnc-btn-create-folder:hover {
    transform: translateY(-2px);
    box-shadow: var(--fcnc-shadow-md);
}

/* ============================================================
   КОНТАКТЫ (ЦЕНТР)
   ============================================================ */
.fcnc-chat-contacts {
    background: var(--fcnc-bg-white);
    border-radius: var(--fcnc-radius);
    box-shadow: var(--fcnc-shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 100%; /* ✅ Не растём больше grid cell */
}

.fcnc-chat-contacts-header {
    padding: 20px;
    border-bottom: 1px solid var(--fcnc-border);
    background: var(--fcnc-bg-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fcnc-chat-contacts-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--fcnc-text-dark);
}

.fcnc-btn-filter {
    background: var(--fcnc-gradient);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--fcnc-radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--fcnc-transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.fcnc-btn-filter:hover {
    transform: translateY(-2px);
    box-shadow: var(--fcnc-shadow-md);
}

.fcnc-contacts-search {
    padding: 15px;
    border-bottom: 1px solid var(--fcnc-border);
}

.fcnc-input {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--fcnc-border);
    border-radius: var(--fcnc-radius-sm);
    font-size: 14px;
    transition: var(--fcnc-transition);
}

.fcnc-input:focus {
    outline: none;
    border-color: var(--fcnc-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.fcnc-contacts-list {
    flex: 1;
    overflow-y: auto;
}

/* Карточки контактов */
.fcnc-contact-item {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--fcnc-border);
    cursor: pointer;
    transition: var(--fcnc-transition);
    position: relative;
}

.fcnc-contact-item:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
    transform: translateX(4px);
}

.fcnc-contact-item:active {
    transform: translateX(2px);
}

.fcnc-contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    overflow: hidden;
    margin-right: 14px;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--fcnc-primary) 0%, var(--fcnc-secondary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    position: relative;
}

.fcnc-contact-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
}

.fcnc-contact-avatar span {
    color: #fff;
    font-size: 20px;
    font-weight: 600;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.fcnc-contact-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.fcnc-contact-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--fcnc-text-dark);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fcnc-contact-last-message {
    font-size: 13px;
    color: var(--fcnc-text-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.fcnc-unread-badge {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, var(--fcnc-primary) 0%, var(--fcnc-secondary) 100%);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 12px;
    min-width: 24px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* ============================================================
   ДИАЛОГ (СПРАВА)
   ============================================================ */
.fcnc-chat-dialog {
    background: var(--fcnc-bg-white);
    border-radius: var(--fcnc-radius);
    box-shadow: var(--fcnc-shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 100%; /* ✅ Не растём больше grid cell */
    max-width: 100%; /* ✅ НЕ ВЫХОДИМ ЗА ШИРИНУ! */
    width: 100%; /* ✅ Ограничиваем ширину */
}

.fcnc-chat-dialog-header {
    padding: 20px;
    border-bottom: 1px solid var(--fcnc-border);
    background: var(--fcnc-bg-light);
    flex-shrink: 0; /* ✅ Не сжимается */
}

.fcnc-chat-deal-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 15px;
    background: #fff;
    border-radius: 12px;
    padding: 12px 18px;
    border: 1px solid #ecefff;
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.08);
}

.fcnc-chat-deal-panel.is-disabled {
    opacity: 0.6;
}

.fcnc-chat-deal-panel strong {
    display: block;
    font-size: 14px;
    color: #2f3358;
}

.fcnc-chat-deal-status {
    font-size: 13px;
    color: #5a5f82;
    line-height: 1.5;
}

.fcnc-chat-deal-status span {
    font-weight: 600;
    color: #333760;
}

.fcnc-chat-deal-btn {
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 18px rgba(102, 126, 234, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.fcnc-chat-deal-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(102, 126, 234, 0.4);
}

.fcnc-chat-deal-btn.is-pending {
    background: linear-gradient(135deg, #ffb347 0%, #ffcc33 100%);
    box-shadow: 0 8px 18px rgba(255, 188, 80, 0.35);
}

.fcnc-chat-deal-btn:disabled,
.fcnc-chat-deal-btn.is-disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.fcnc-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--fcnc-bg-light);
    min-height: 0; /* ✅ Позволяет сжиматься */
}

.fcnc-message-form {
    padding: 20px;
    border-top: 1px solid var(--fcnc-border);
    background: var(--fcnc-bg-white);
    flex-shrink: 0; /* ✅ Не сжимается */
}

.fcnc-textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--fcnc-border);
    border-radius: var(--fcnc-radius-sm);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    transition: var(--fcnc-transition);
}

.fcnc-textarea:focus {
    outline: none;
    border-color: var(--fcnc-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.fcnc-message-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.fcnc-btn-attach {
    background: transparent;
    border: 1px solid var(--fcnc-border);
    color: var(--fcnc-text-medium);
    padding: 10px 16px;
    border-radius: var(--fcnc-radius-sm);
    cursor: pointer;
    transition: var(--fcnc-transition);
}

.fcnc-btn-attach:hover {
    background: var(--fcnc-bg-light);
    border-color: var(--fcnc-primary);
    color: var(--fcnc-primary);
}

.fcnc-btn-send {
    background: var(--fcnc-gradient);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: var(--fcnc-radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--fcnc-transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.fcnc-btn-send:hover {
    transform: translateY(-2px);
    box-shadow: var(--fcnc-shadow-md);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.fcnc-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--fcnc-text-medium);
    padding: 40px;
}

.fcnc-empty-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.fcnc-empty-state h3 {
    margin: 0 0 10px 0;
    color: var(--fcnc-text-dark);
    font-size: 20px;
}

.fcnc-empty-state p {
    margin: 0;
    font-size: 14px;
    color: var(--fcnc-text-light);
}

/* ============================================================
   LOADING
   ============================================================ */
.fcnc-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    gap: 15px;
}

.fcnc-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--fcnc-bg-light);
    border-top-color: var(--fcnc-primary);
    border-radius: 50%;
    animation: fcnc-spin 0.8s linear infinite;
}

@keyframes fcnc-spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   ERROR
   ============================================================ */
.fcnc-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    padding: 15px;
    border-radius: var(--fcnc-radius-sm);
    margin: 15px;
}

/* ============================================================
   МОДАЛЬНЫЕ ОКНА
   ============================================================ */
.fcnc-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fcnc-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(4px); /* Safari */
    backdrop-filter: blur(4px);
    z-index: 1;
}

.fcnc-modal-container {
    position: relative;
    z-index: 2;
    background: var(--fcnc-bg-white);
    border-radius: var(--fcnc-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.fcnc-modal-header {
    padding: 24px 30px;
    border-bottom: 1px solid var(--fcnc-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--fcnc-gradient);
    border-radius: var(--fcnc-radius) var(--fcnc-radius) 0 0;
    color: white;
}

.fcnc-modal-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.fcnc-modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--fcnc-transition);
    font-size: 18px;
}

.fcnc-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.fcnc-modal-content {
    padding: 30px;
    overflow-y: auto;
    flex: 1;
}

.fcnc-modal-footer {
    padding: 20px 30px;
    border-top: 1px solid var(--fcnc-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: var(--fcnc-bg-light);
    border-radius: 0 0 var(--fcnc-radius) var(--fcnc-radius);
}

.fcnc-btn {
    padding: 12px 24px;
    border-radius: var(--fcnc-radius-sm);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: var(--fcnc-transition);
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.fcnc-btn-primary {
    background: var(--fcnc-gradient);
    color: white;
}

.fcnc-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--fcnc-shadow-md);
}

/* ============================================================
   АДАПТИВНОСТЬ
   ============================================================ */

/* Планшеты */
@media (max-width: 1200px) {
    .fcnc-chat-container {
        grid-template-columns: 250px 300px 1fr;
    }
}

/* Мобильные (вертикальный стек) */
@media (max-width: 968px) {
    .fcnc-chat-container {
        grid-template-columns: 1fr;
        height: auto; /* ✅ Автоматическая высота */
    }
    
    .fcnc-chat-sidebar,
    .fcnc-chat-contacts {
        height: calc(50vh - 100px); /* ✅ Подстраивается под экран */
        min-height: 300px; /* ✅ Минимальная высота */
    }
    
    .fcnc-chat-dialog {
        height: calc(100vh - 200px); /* ✅ Подстраивается под экран */
        min-height: 500px; /* ✅ Минимальная высота */
    }
    
    .fcnc-chat-header {
        flex-direction: column;
        gap: 20px;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .fcnc-chat-page {
        padding: 0 10px;
        margin: 20px auto;
    }
    
    .fcnc-chat-header {
        padding: 20px;
    }
    
    .fcnc-chat-logo h1 {
        font-size: 22px;
    }
}

/* ============================================================
   ИНДИКАТОР "ПЕЧАТАЕТ..." (HEARTBEAT API)
   ============================================================ */
.fcnc-typing-indicator {
    padding: 12px 20px;
    background: var(--fcnc-bg-light);
    border-radius: var(--fcnc-radius-sm);
    margin-top: 10px;
    font-size: 14px;
    color: var(--fcnc-text-medium);
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 8px;
}

.fcnc-typing-dots {
    display: flex;
    align-items: center;
    gap: 2px;
}

.fcnc-typing-dot {
    opacity: 0;
    animation: fcnc-typing-blink 1.4s infinite;
}

.fcnc-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.fcnc-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes fcnc-typing-blink {
    0%, 60%, 100% {
        opacity: 0;
    }
    30% {
        opacity: 1;
    }
}

/* Badge непрочитанных сообщений */
.fcnc-unread-badge {
    display: inline-block;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--fcnc-gradient);
    color: white;
    font-size: 11px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    border-radius: 10px;
    margin-left: auto;
}

.fcnc-unread-badge:empty {
    display: none;
}

/* ============================================================
   КАРТОЧКА КОНТАКТА (ИЗ ПОИСКА ПОСТАВЩИКОВ)
   ============================================================ */
.fcnc-chat-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--fcnc-bg-white);
    border: 2px solid transparent;
    border-radius: var(--fcnc-radius-sm);
    margin-bottom: 12px;
    cursor: pointer;
    transition: var(--fcnc-transition);
    box-shadow: var(--fcnc-shadow-sm);
}

.fcnc-chat-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--fcnc-shadow-md);
    border-color: var(--fcnc-primary);
}

.fcnc-chat-item.active {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-color: var(--fcnc-primary);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.2);
}

.fcnc-chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--fcnc-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 14px;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.fcnc-chat-avatar span {
    color: white;
    font-size: 20px;
    font-weight: 700;
    text-transform: uppercase;
}

.fcnc-chat-info {
    flex: 1;
    min-width: 0;
}

.fcnc-chat-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--fcnc-text-dark);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fcnc-chat-preview {
    font-size: 13px;
    color: var(--fcnc-text-medium);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fcnc-chat-item.active .fcnc-chat-name {
    color: var(--fcnc-primary);
    font-weight: 700;
}

.fcnc-chat-item.active .fcnc-chat-preview {
    color: var(--fcnc-secondary);
    font-weight: 500;
}

/* ============================================================
   ДЕЙСТВИЯ С ВЫБРАННЫМИ (STICKY КНОПКИ)
   ============================================================ */
.fcnc-filter-actions {
    position: sticky;
    bottom: 0;
    z-index: 100;
    background: white;
    padding: 20px;
    border-top: 2px solid var(--fcnc-border);
    margin: 0 -20px -20px -20px; /* Компенсируем padding родителя */
    display: flex;
    gap: 12px;
    justify-content: center;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
}

.fcnc-btn-success,
.fcnc-btn-broadcast {
    padding: 16px 32px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: var(--fcnc-radius-sm);
    cursor: pointer;
    transition: var(--fcnc-transition);
    box-shadow: var(--fcnc-shadow-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.fcnc-btn-success {
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    color: white;
}

.fcnc-btn-success:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.fcnc-btn-broadcast {
    background: var(--fcnc-gradient);
    color: white;
}

.fcnc-btn-broadcast:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

/* ============================================================
   ГРУППЫ МАССОВЫХ ЗАПРОСОВ (АККОРДЕОН)
   ============================================================ */
.fcnc-broadcast-group {
    margin-bottom: 12px;
    border: 1px solid var(--fcnc-border);
    border-radius: var(--fcnc-radius-sm);
    overflow: hidden;
    transition: var(--fcnc-transition);
}

.fcnc-broadcast-group:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.fcnc-group-header {
    padding: 16px 20px;
    background: var(--fcnc-gradient);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: var(--fcnc-transition);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.fcnc-group-header:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.fcnc-group-header .fcnc-group-title {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
    margin-right: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fcnc-contacts-badge {
    background: rgba(255, 255, 255, 0.3);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    margin-right: 10px;
}

.fcnc-toggle-icon {
    font-size: 14px;
    transition: transform 0.3s ease;
}

.fcnc-broadcast-group.expanded .fcnc-toggle-icon {
    transform: rotate(180deg);
}

.fcnc-group-contacts {
    background: #f8f9fa;
    padding: 0;
}

.fcnc-group-contacts .fcnc-contact-item {
    margin: 0;
    border-bottom: 1px solid var(--fcnc-border);
}

.fcnc-group-contacts .fcnc-contact-item:last-child {
    border-bottom: none;
}
