/* AI Chat с темами */
/* Использует базовые стили из chat-modern.css для сообщений */

.ai-chat-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--tg-theme-bg-color, #17212b);
}

/* Панель с темами */
.threads-panel {
    width: 280px;
    background: var(--tg-theme-secondary-bg-color, #232e3c);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.threads-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--tg-theme-secondary-bg-color, #232e3c);
}

.threads-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--tg-theme-text-color, #ffffff);
}

.threads-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.thread-item {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    gap: 12px;
}

.thread-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.thread-item.active {
    background: rgba(var(--tg-theme-button-color, 33, 150, 243), 0.15);
    border-left: 3px solid var(--tg-theme-button-color, #2196F3);
}

.thread-item.new-thread {
    background: var(--tg-theme-button-color, #2196F3);
    color: var(--tg-theme-button-text-color, white);
}

.thread-item.new-thread:hover {
    opacity: 0.9;
}

.thread-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.thread-info {
    flex: 1;
    min-width: 0;
}

.thread-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-meta {
    font-size: 12px;
    color: var(--tg-theme-hint-color, rgba(255, 255, 255, 0.5));
    margin-top: 4px;
}

.thread-item.new-thread .thread-meta {
    color: rgba(255, 255, 255, 0.9);
}

.thread-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
    color: var(--tg-theme-text-color, #ffffff);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Панель чата */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--tg-theme-bg-color, #17212b);
    position: relative;
}

.chat-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: var(--bg-image, none);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.15;
    filter: blur(8px);
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.6s ease, filter 0.6s ease;
}

.chat-panel.show-background::before {
    opacity: 0.95;
    filter: blur(3px);
}

.chat-header {
    padding: 16px 60px 16px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(35, 46, 60, 0.9);
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--tg-theme-button-color, #2196F3);
}

.chat-header-info {
    flex: 1;
}

.chat-header h3 {
    margin: 0 0 4px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--tg-theme-text-color, #ffffff);
}

.chat-header-meta {
    font-size: 14px;
    color: var(--tg-theme-hint-color, rgba(255, 255, 255, 0.5));
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: transparent;
    position: relative;
    z-index: 1;
    transition: opacity 0.6s ease;
}

.chat-messages.hidden-messages {
    opacity: 0.1;
    pointer-events: none;
}

/* Индикатор печатания AI */
.typing-indicator-bubble {
    min-width: 60px;
}

.typing-dots {
    display: flex;
    gap: 6px;
    padding: 4px 0;
    align-items: center;
    justify-content: center;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Форма отправки */
.chat-form {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(35, 46, 60, 0.9);
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
}

.chat-input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.05);
    color: var(--tg-theme-text-color, #ffffff);
}

.chat-input:focus {
    outline: none;
    border-color: var(--tg-theme-button-color, #2196F3);
    background: rgba(255, 255, 255, 0.08);
}

.chat-input::placeholder {
    color: var(--tg-theme-hint-color, rgba(255, 255, 255, 0.5));
}

.send-button {
    background: var(--tg-theme-button-color, #2196F3);
    color: var(--tg-theme-button-text-color, white);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-button:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.send-button:active {
    transform: scale(0.95);
}

/* Кнопки управления в панели тем */
.threads-actions {
    background: var(--tg-theme-secondary-bg-color, #232e3c);
}

.thread-action-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--tg-theme-text-color, #ffffff);
    cursor: pointer;
    transition: all 0.2s;
}

.thread-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--tg-theme-button-color, #2196F3);
}

.thread-action-btn:active {
    transform: scale(0.95);
}

/* Верхние кнопки управления чатом */
.top-controls {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1001;
    display: flex;
    gap: 8px;
}

.close-chat-btn,
.threads-toggle {
    display: flex;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

.close-chat-btn:hover,
.threads-toggle:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.05);
}

.close-chat-btn:active,
.threads-toggle:active {
    transform: scale(0.95);
}

.threads-panel.collapsed {
    transform: translateX(-100%);
}

/* Адаптивность для мобильных */
@media (max-width: 768px) {
    .ai-chat-container {
        flex-direction: row;
        position: relative;
    }
    
    .threads-panel {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        height: 100%;
        z-index: 100;
        border-right: 1px solid rgba(255, 255, 255, 0.1);
        border-bottom: none;
        transition: transform 0.3s ease;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.4);
    }
    
    .threads-panel.collapsed {
        transform: translateX(-100%);
    }
    
    .chat-panel {
        width: 100%;
    }
    
    .top-controls {
        display: flex;
    }
    
    .mobile-controls {
        display: flex;
    }
    
    .chat-bubble,
    .chat-bubble-mine,
    .chat-bubble-other {
        max-width: 85%;
    }
    
    .chat-header {
        padding-right: 70px;
        padding-left: 16px;
    }
    
    .modal-content {
        max-width: 100vw !important;
        width: 100vw !important;
        height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }
    
    .ai-chat-container {
        height: 100vh !important;
    }
}

.chat-bubble-content strong em,
.chat-bubble-content em strong,
.chat-bubble-mine .chat-bubble-content strong em,
.chat-bubble-mine .chat-bubble-content em strong,
.chat-bubble-other .chat-bubble-content strong em,
.chat-bubble-other .chat-bubble-content em strong {
    font-weight: 700;
    font-style: italic;
}

.chat-bubble-content em,
.chat-bubble-mine .chat-bubble-content em,
.chat-bubble-other .chat-bubble-content em {
    font-style: italic;
}

/* Анимации для кастомных диалогов */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Контекстное меню для сообщений */
.chat-bubble,
.chat-bubble-content,
.chat-message-wrapper {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
}

.chat-message-wrapper.context-active {
    background: rgba(var(--tg-theme-button-color, 33, 150, 243), 0.1);
    border-radius: 12px;
    padding: 4px;
    margin: -4px;
}

.context-menu-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10001;
    animation: fadeIn 0.2s ease;
    backdrop-filter: blur(4px);
}

.message-context-menu {
    position: fixed;
    background: rgba(30, 35, 45, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6), 
                0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    z-index: 10002;
    min-width: 220px;
    overflow: hidden;
    animation: contextMenuSlideIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.message-context-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    background: transparent;
    border: none;
    width: 100%;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.95);
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.message-context-menu-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message-context-menu-item:hover::before {
    opacity: 1;
}

.message-context-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(2px);
}

.message-context-menu-item:active {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(0.98);
}

.message-context-menu-icon {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-context-menu-icon img {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(1) opacity(0.9);
    transition: all 0.2s ease;
}

.message-context-menu-item:hover .message-context-menu-icon img {
    filter: brightness(0) invert(1) opacity(1);
    transform: scale(1.1);
}

.message-context-menu-text {
    flex: 1;
    text-align: left;
    position: relative;
    z-index: 1;
}

@keyframes contextMenuSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
