/* Стили для плавающего чата */
.chat-widget,
.chat-start-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    transition: bottom 0.3s ease;
}

.chat-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 255, 255, 0.3);
    transition: all 0.3s ease;
    font-size: 24px;
    color: #000;
    position: relative;
    z-index: 10001;
}

.chat-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 255, 255, 0.5);
}

.chat-icon i {
    color: #000;
    font-size: 24px;
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    z-index: 10002;
}

/* ИСПРАВЛЕННЫЕ СТИЛИ ДЛЯ ПОЗИЦИОНИРОВАНИЯ ПРИ ОТКРЫТОМ ТРЕКЕРЕ */
/* Когда трекер открыт (не свернут) */
body:has(.tracker-mini-panel:not(.collapsed)) .chat-widget,
body:has(.tracker-mini-panel:not(.collapsed)) .chat-start-button {
    bottom: 100px !important;
}

/* Когда трекер свернут */
body:has(.tracker-mini-panel.collapsed) .chat-widget,
body:has(.tracker-mini-panel.collapsed) .chat-start-button {
    bottom: 60px !important;
}

/* Когда нет транзакций (мини-панель скрыта) */
body:has(.tracker-mini-panel:not(.has-transactions)) .chat-widget,
body:has(.tracker-mini-panel:not(.has-transactions)) .chat-start-button {
    bottom: 20px !important;
}

/* Альтернативный вариант через JavaScript классы */
.tracker-panel-open .chat-widget,
.tracker-panel-open .chat-start-button {
    bottom: 100px !important;
}

.tracker-panel-collapsed .chat-widget,
.tracker-panel-collapsed .chat-start-button {
    bottom: 60px !important;
}

.tracker-panel-hidden .chat-widget,
.tracker-panel-hidden .chat-start-button {
    bottom: 20px !important;
}

/* Медиа-запросы для планшетов */
@media (max-width: 768px) {
    .chat-widget,
    .chat-start-button {
        bottom: 20px;
        right: 20px;
    }
    
    body:has(.tracker-mini-panel:not(.collapsed)) .chat-widget,
    body:has(.tracker-mini-panel:not(.collapsed)) .chat-start-button {
        bottom: 110px !important;
    }
    
    body:has(.tracker-mini-panel.collapsed) .chat-widget,
    body:has(.tracker-mini-panel.collapsed) .chat-start-button {
        bottom: 70px !important;
    }
    
    body:has(.tracker-mini-panel:not(.has-transactions)) .chat-widget,
    body:has(.tracker-mini-panel:not(.has-transactions)) .chat-start-button {
        bottom: 20px !important;
    }
}

/* Медиа-запросы для мобильных */
@media (max-width: 480px) {
    .chat-widget,
    .chat-start-button {
        bottom: 20px;
        right: 20px;
    }
    
    body:has(.tracker-mini-panel:not(.collapsed)) .chat-widget,
    body:has(.tracker-mini-panel:not(.collapsed)) .chat-start-button {
        bottom: 100px !important;
    }
    
    body:has(.tracker-mini-panel.collapsed) .chat-widget,
    body:has(.tracker-mini-panel.collapsed) .chat-start-button {
        bottom: 65px !important;
    }
    
    body:has(.tracker-mini-panel:not(.has-transactions)) .chat-widget,
    body:has(.tracker-mini-panel:not(.has-transactions)) .chat-start-button {
        bottom: 20px !important;
    }
}

/* Особые случаи для очень маленьких экранов */
@media (max-width: 360px) {
    .chat-widget,
    .chat-start-button {
        bottom: 15px;
        right: 15px;
    }
    
    body:has(.tracker-mini-panel:not(.collapsed)) .chat-widget,
    body:has(.tracker-mini-panel:not(.collapsed)) .chat-start-button {
        bottom: 90px !important;
    }
    
    body:has(.tracker-mini-panel.collapsed) .chat-widget,
    body:has(.tracker-mini-panel.collapsed) .chat-start-button {
        bottom: 60px !important;
    }
}

/* Окно чата */
.chat-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 10001;
}

.chat-window.open {
    display: flex;
    animation: chatSlideUp 0.3s ease;
}

@keyframes chatSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h4 {
    margin: 0;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-actions {
    display: flex;
    gap: 5px;
}

.chat-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    border-radius: 3px;
    transition: background 0.3s;
    z-index: 10002;
}

.chat-btn:hover {
    background: rgba(255,255,255,0.2);
}

.chat-body {
    flex: 1;
    background: #f8f9fa;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-welcome {
    text-align: center;
    color: #666;
    padding: 20px;
}

.chat-welcome i {
    font-size: 40px;
    margin-bottom: 10px;
    color: #667eea;
}

.message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: #667eea;
    color: white;
    border-bottom-right-radius: 5px;
}

.message.admin {
    align-self: flex-start;
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 5px;
}

.message.system {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    color: #6c757d;
    font-style: italic;
    text-align: center;
    max-width: 90%;
    align-self: center;
    border-radius: 10px;
    padding: 8px 12px;
    margin: 5px auto;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 5px;
}

.message-image {
    max-width: 100%;
    border-radius: 10px;
    margin-top: 5px;
    cursor: pointer;
}

.message-admin-name {
    font-size: 11px;
    font-weight: bold;
    color: #667eea;
    margin-bottom: 3px;
}

.chat-footer {
    border-top: 1px solid #e0e0e0;
    background: white;
}

.chat-guest-info {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-guest-info input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 12px;
}

.chat-input-area {
    position: relative;
}

.chat-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    position: relative;
    z-index: 1;
}

.chat-tool-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 5px;
    transition: all 0.3s ease;
    font-size: 14px;
}

.chat-tool-btn:hover {
    background: var(--accent-primary);
    color: white;
    transform: scale(1.1);
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#chatInput {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 15px;
    resize: none;
    font-size: 12px;
    max-height: 100px;
    min-height: 40px;
    font-family: Arial, sans-serif;
}

#sendMessage {
    background: #667eea;
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s;
}

#sendMessage:hover {
    background: #5a6fd8;
}

#sendMessage:active {
    animation: messageSent 0.3s ease;
}

@keyframes messageSent {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* Эмодзи пикер */
.chat-emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    display: none;
    flex-wrap: wrap;
    gap: 5px;
    max-width: 300px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    z-index: 10003;
}

.chat-emoji-picker.show {
    display: flex;
    animation: emojiAppear 0.3s ease;
}

@keyframes emojiAppear {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.emoji {
    cursor: pointer;
    padding: 5px;
    border-radius: 3px;
    transition: all 0.3s ease;
    font-size: 18px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji:hover {
    background: var(--accent-primary);
    transform: scale(1.2);
}

/* Превью изображений */
.image-preview-container {
    margin: 10px 0;
    padding: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.image-preview {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 5px;
    border: 1px solid var(--border-color);
}

.image-preview-info {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8em;
    color: var(--text-muted);
}

.remove-preview {
    background: none;
    border: none;
    color: #ff4757;
    cursor: pointer;
    padding: 5px;
    border-radius: 3px;
    transition: background 0.3s;
}

.remove-preview:hover {
    background: rgba(255, 71, 87, 0.1);
}

/* Состояние перетаскивания */
.chat-input-area.drag-over {
    background: rgba(0, 255, 255, 0.1);
    border: 2px dashed var(--accent-primary);
}

/* Индикатор набора текста */
.typing-indicator {
    font-style: italic;
    color: #666;
    font-size: 11px;
    padding: 5px 15px;
}

/* Кнопка начала чата */
.chat-start-button {
    transition: opacity 0.3s ease, visibility 0.3s ease;
    visibility: visible;
    opacity: 1;
}

.chat-start-button.hidden {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.chat-start-info {
    padding: 15px;
    text-align: center;
}

#startNewChat {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#startNewChat:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

/* Видимость элементов чата */
.chat-widget {
    display: none;
}

#chatStartButton {
    display: block !important;
}

/* Адаптация окна чата для мобильных */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 40px);
        height: 70vh;
        right: 10px;
        bottom: 70px;
    }
}

/* Исправление для очень маленьких экранов */
@media (max-width: 360px) {
    .chat-window {
        width: calc(100vw - 30px);
        right: 5px;
    }
}

/* Гарантируем кликабельность на всех разрешениях */
.chat-icon {
    pointer-events: auto !important;
}

.chat-start-button .chat-icon {
    pointer-events: auto !important;
}

/* Убираем любые возможные перекрытия */
.chat-widget *,
.chat-start-button * {
    pointer-events: auto;
}