/* ============================================
   СТАРЭКС AI Чат-консультант
   Стили в стиле Apple/СТАРЭКС
   ============================================ */

/* Контейнер чата */
.chatbot-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 16px;
}

/* Всплывающая подсказка */
.chatbot-tooltip {
    position: relative;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.9);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
}

.chatbot-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chatbot-tooltip-content {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 16px 20px;
    border-radius: 20px;
    box-shadow: 
        0 10px 40px rgba(102, 126, 234, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    max-width: 260px;
}

.chatbot-tooltip-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.2) 0%, transparent 50%);
    border-radius: 20px;
    pointer-events: none;
}

@keyframes shimmer {
    0%, 100% { transform: translate(-30%, -30%); }
    50% { transform: translate(30%, 30%); }
}

.chatbot-tooltip-icon {
    position: relative;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    backdrop-filter: blur(10px);
}

.chatbot-tooltip-icon::before {
    content: '👋';
    font-size: 24px;
    animation: wave 1.5s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { transform: rotate(0deg); }
    20% { transform: rotate(20deg); }
    40% { transform: rotate(-10deg); }
    60% { transform: rotate(15deg); }
    80% { transform: rotate(-5deg); }
}

.chatbot-tooltip-text {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 1;
}

.chatbot-tooltip-text strong {
    font-size: 1rem;
    color: #fff;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chatbot-tooltip-text span {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.chatbot-tooltip-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #1d1d1f;
    color: #fff;
    border: 2px solid #fff;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10;
}

.chatbot-tooltip-close:hover {
    background: #ff3b30;
    transform: scale(1.15) rotate(90deg);
}

.chatbot-tooltip-arrow {
    position: absolute;
    right: 24px;
    bottom: -10px;
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 12px solid #764ba2;
}

/* Пульсация вокруг подсказки */
.chatbot-tooltip.visible::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 24px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    z-index: -1;
    opacity: 0.5;
    animation: pulse-ring 2s ease-out infinite;
}

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.15); opacity: 0; }
}

/* Кнопка чата */
.chatbot-trigger {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 122, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    animation: pulse-glow 2s ease-in-out infinite;
    flex-shrink: 0;
}

.chatbot-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 122, 255, 0.5);
}

.chatbot-trigger:active {
    transform: scale(0.95);
}

.chatbot-trigger svg {
    width: 28px;
    height: 28px;
    color: white;
    transition: transform 0.3s ease;
}

.chatbot-trigger.active svg {
    transform: rotate(90deg);
}

/* Индикатор онлайн */
.chatbot-trigger::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    background: #34c759;
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.7);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(52, 199, 89, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(52, 199, 89, 0);
    }
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(0, 122, 255, 0.4);
    }
    50% {
        box-shadow: 0 4px 30px rgba(0, 122, 255, 0.6);
    }
}

/* Окно чата */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 9998;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Шапка чата */
.chatbot-header {
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.chatbot-avatar {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-avatar svg {
    width: 28px;
    height: 28px;
    color: white;
}

.chatbot-avatar-emoji {
    font-size: 26px;
    line-height: 1;
}

.chatbot-info {
    flex: 1;
}

.chatbot-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.chatbot-status {
    font-size: 0.85rem;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatbot-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #34c759;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.chatbot-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chatbot-close svg {
    width: 18px;
    height: 18px;
    color: white;
}

/* Область сообщений */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8f9fa;
    /* scroll-behavior управляется через JS */
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #d2d2d7;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #b8b8bc;
}

/* Сообщения */
.chatbot-message {
    display: flex;
    gap: 10px;
    animation: messageSlide 0.3s ease;
}

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

.chatbot-message.user {
    flex-direction: row-reverse;
}

.chatbot-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #e5e5ea;
}

.chatbot-message.assistant .chatbot-message-avatar {
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    color: white;
}

.chatbot-message.user .chatbot-message-avatar {
    background: #34c759;
    color: white;
}

.chatbot-message-avatar svg {
    width: 20px;
    height: 20px;
}

.chatbot-message-content {
    max-width: 280px;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chatbot-message.assistant .chatbot-message-content {
    background: white;
    color: #1d1d1f;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.chatbot-message.user .chatbot-message-content {
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

/* Индикатор печати */
.chatbot-typing {
    display: flex;
    gap: 10px;
    padding: 10px 0;
}

.chatbot-typing-indicator {
    background: white;
    padding: 14px 18px;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    display: flex;
    gap: 4px;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.chatbot-typing-dot {
    width: 8px;
    height: 8px;
    background: #86868b;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

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

/* Быстрые действия */
.chatbot-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px;
    background: white;
    border-top: 1px solid #e5e5e7;
}

.chatbot-quick-btn {
    padding: 8px 14px;
    background: #f5f5f7;
    border: none;
    border-radius: 20px;
    font-size: 0.85rem;
    color: #1d1d1f;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.chatbot-quick-btn:hover {
    background: #007aff;
    color: white;
}

/* Форма ввода */
.chatbot-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e5e5e7;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chatbot-input-wrapper {
    flex: 1;
    position: relative;
}

.chatbot-input {
    width: 100%;
    padding: 14px 18px;
    border: 1px solid #e5e5e7;
    border-radius: 24px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: all 0.2s ease;
    line-height: 1.4;
}

.chatbot-input:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.chatbot-input::placeholder {
    color: #86868b;
}

.chatbot-send-btn {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chatbot-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.4);
}

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

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chatbot-send-btn svg {
    width: 22px;
    height: 22px;
    color: white;
}

/* Подвал чата */
.chatbot-footer {
    padding: 10px 20px;
    background: #f8f9fa;
    text-align: center;
    border-top: 1px solid #e5e5e7;
}

.chatbot-footer-text {
    font-size: 0.75rem;
    color: #86868b;
}

.chatbot-footer-text a {
    color: #007aff;
    text-decoration: none;
}

.chatbot-footer-text a:hover {
    text-decoration: underline;
}

/* Ошибка */
.chatbot-error {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    text-align: center;
    margin: 10px 0;
}

/* Адаптивность */
@media (max-width: 480px) {
    .chatbot-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .chatbot-container {
        bottom: 16px;
        right: 16px;
        gap: 12px;
    }
    
    .chatbot-trigger {
        width: 56px;
        height: 56px;
    }
    
    .chatbot-tooltip-content {
        max-width: 220px;
        padding: 14px 16px;
        gap: 12px;
    }
    
    .chatbot-tooltip-icon {
        width: 40px;
        height: 40px;
    }
    
    .chatbot-tooltip-icon::before {
        font-size: 20px;
    }
    
    .chatbot-tooltip-text strong {
        font-size: 0.9rem;
    }
    
    .chatbot-tooltip-text span {
        font-size: 0.8rem;
    }
    
    .chatbot-tooltip-arrow {
        right: 20px;
    }
    
    .chatbot-header {
        padding: 16px;
        border-radius: 0;
    }
    
    .chatbot-messages {
        padding: 16px;
    }
    
    .chatbot-message-content {
        max-width: calc(100% - 60px);
    }
    
    .chatbot-input-area {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    .chatbot-quick-actions {
        padding: 10px 16px;
    }
}

/* Тёмная тема (опционально) */
@media (prefers-color-scheme: dark) {
    .chatbot-window {
        /* Можно добавить тёмную тему */
    }
}

/* Скрытие кнопки чата на мобильных в определённых случаях */
.chatbot-hidden {
    display: none !important;
}

/* Анимация появления окна на мобильных */
@media (max-width: 480px) {
    .chatbot-window.open {
        animation: slideUp 0.3s ease;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
}

/* Стили для ссылок в сообщениях */
.chatbot-message-content a {
    color: #007aff;
    text-decoration: underline;
}

.chatbot-message.user .chatbot-message-content a {
    color: white;
}

/* Форматирование текста в сообщениях */
.chatbot-message-content strong,
.chatbot-message-content b {
    font-weight: 600;
}

.chatbot-message-content ul,
.chatbot-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chatbot-message-content li {
    margin: 4px 0;
}

.chatbot-message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.9em;
}

.chatbot-message.user .chatbot-message-content code {
    background: rgba(255, 255, 255, 0.2);
}

/* Emoji поддержка */
.chatbot-message-content {
    font-family: 'Ubuntu', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 
                 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif;
}

/* ============================================
   Эффект печатания текста (как в ChatGPT)
   ============================================ */

/* Мигающий курсор */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background-color: #007aff;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursorBlink 0.8s ease-in-out infinite;
    border-radius: 1px;
}

@keyframes cursorBlink {
    0%, 50% { 
        opacity: 1; 
    }
    51%, 100% { 
        opacity: 0; 
    }
}

/* Состояние активного печатания */
.chatbot-message-content.typing-active {
    min-height: 20px;
}

/* Плавное появление текста */
.chatbot-message-content.typing-active {
    animation: fadeInText 0.2s ease-out;
}

@keyframes fadeInText {
    from {
        opacity: 0.7;
    }
    to {
        opacity: 1;
    }
}

/* Курсор в тёмной теме (для сообщений пользователя, если бы он там был) */
.chatbot-message.user .typing-cursor {
    background-color: rgba(255, 255, 255, 0.9);
}

/* Плавная анимация высоты при печатании */
.chatbot-message-content {
    transition: min-height 0.1s ease;
}

/* Убираем курсор после завершения печатания */
.chatbot-message-content:not(.typing-active) .typing-cursor {
    display: none;
}
