/* static/css/chat-widget.css */
/* 
Чат-виджет Mamibot
Цвета бренда: бирюзовый (#0EA5E9) и белый
*/

/* ========== ПЕРЕМЕННЫЕ ========== */
:root {
    --chat-primary: #0EA5E9;
    --chat-primary-dark: #0284C7;
    --chat-primary-light: #E0F2FE;
    --chat-white: #FFFFFF;
    --chat-bg: #F8FAFC;
    --chat-text: #0F172A;
    --chat-text-light: #64748B;
    --chat-shadow: 0 8px 32px rgba(14, 165, 233, 0.15);
    --chat-shadow-hover: 0 12px 48px rgba(14, 165, 233, 0.25);
    --chat-radius: 16px;
    --chat-radius-sm: 10px;
    --chat-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Позиция (можно менять) */
    --chat-position-bottom: 24px;
    --chat-position-right: 24px;
}

/* ========== КНОПКА ОТКРЫТИЯ ========== */
.chat-toggle {
    position: fixed;
    bottom: var(--chat-position-bottom);
    right: var(--chat-position-right);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-white);
    cursor: pointer;
    box-shadow: var(--chat-shadow);
    transition: var(--chat-transition);
    z-index: 9999;
    padding: 4px;
    border: 2px solid var(--chat-primary);
}

.chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: var(--chat-shadow-hover);
}

.chat-toggle-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #EF4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: system-ui, -apple-system, sans-serif;
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ========== ОКНО ЧАТА ========== */
.chat-window {
    position: fixed;
    bottom: calc(var(--chat-position-bottom) + 72px);
    right: var(--chat-position-right);
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--chat-white);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow-hover);
    display: flex;
    flex-direction: column;
    z-index: 9998;
    animation: slide-up 0.3s ease;
    overflow: hidden;
    font-family: system-ui, -apple-system, sans-serif;
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========== ХЕДЕР ========== */
.chat-header {
    background: var(--chat-primary);
    color: white;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.3);
}

.chat-title {
    font-weight: 600;
    font-size: 15px;
}

.chat-status {
    font-size: 12px;
    opacity: 0.85;
}

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

.chat-minimize,
.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
    transition: var(--chat-transition);
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
}

.chat-minimize:hover,
.chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

/* ========== СООБЩЕНИЯ ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 100px;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 4px;
}

/* Сообщения */
.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 88%;
    animation: message-in 0.3s ease;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot {
    align-self: flex-start;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message .avatar-small {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--chat-primary-light);
}

.message .bubble {
    padding: 10px 14px;
    border-radius: var(--chat-radius-sm);
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.message.bot .bubble {
    background: white;
    color: var(--chat-text);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    border-radius: 0 var(--chat-radius-sm) var(--chat-radius-sm) var(--chat-radius-sm);
}

.message.user .bubble {
    background: var(--chat-primary);
    color: white;
    border-radius: var(--chat-radius-sm) 0 var(--chat-radius-sm) var(--chat-radius-sm);
}

.message .bubble a {
    color: var(--chat-primary-dark);
    text-decoration: underline;
}

.message.user .bubble a {
    color: #FFD700;
}

/* Индикатор печатания */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #94A3B8;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* ========== КАРТОЧКИ ========== */
.chat-cards-container {
    padding: 0 18px 12px 18px;
    background: var(--chat-bg);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid #E2E8F0;
}

.chat-cards-container::-webkit-scrollbar {
    width: 3px;
}

.chat-cards-container::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 4px;
}

.card-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: white;
    border-radius: var(--chat-radius-sm);
    border: 1px solid #E2E8F0;
    cursor: pointer;
    transition: var(--chat-transition);
    font-size: 14px;
    color: var(--chat-text);
}

.card-item:hover {
    border-color: var(--chat-primary);
    box-shadow: 0 2px 12px rgba(14, 165, 233, 0.08);
    transform: translateX(4px);
}

.card-item:active {
    transform: scale(0.98);
}

.card-item .card-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.card-item .card-text {
    flex: 1;
    font-weight: 500;
}

.card-item .card-arrow {
    color: var(--chat-text-light);
    font-size: 12px;
}

/* ========== ПОЛЕ ВВОДА ========== */
.chat-input-area {
    padding: 10px 18px 14px;
    background: white;
    border-top: 1px solid #E2E8F0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #E2E8F0;
    border-radius: var(--chat-radius-sm);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: var(--chat-transition);
    min-height: 42px;
    max-height: 80px;
    line-height: 1.5;
    background: var(--chat-bg);
}

.chat-input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
    background: white;
}

.chat-send {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--chat-primary);
    color: white;
    cursor: pointer;
    transition: var(--chat-transition);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-send:hover {
    background: var(--chat-primary-dark);
    transform: scale(1.05);
}

.chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.chat-escalate {
    background: none;
    border: none;
    color: var(--chat-text-light);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
    transition: var(--chat-transition);
    text-align: center;
}

.chat-escalate:hover {
    color: var(--chat-primary);
}

/* ========== АДАПТИВНОСТЬ ========== */
@media (max-width: 768px) {
    .chat-window {
        width: 360px;
        height: 500px;
        bottom: calc(var(--chat-position-bottom) + 66px);
    }

    .chat-toggle {
        width: 54px;
        height: 54px;
    }
}

@media (max-width: 480px) {
    .chat-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        animation: slide-up-mobile 0.3s ease;
    }

    @keyframes slide-up-mobile {
        from { opacity: 0; transform: translateY(40px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .chat-header { border-radius: 0; padding: 12px 14px; }
    .chat-messages { padding: 12px 14px; }
    .chat-cards-container { padding: 0 14px 10px 14px; max-height: 160px; }
    .chat-input-area { padding: 8px 14px 12px; }

    .chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .message .bubble { font-size: 13px; padding: 8px 12px; }
    .card-item { padding: 8px 12px; font-size: 13px; }
    .card-item .card-icon { font-size: 18px; }
}

/* ========== УТИЛИТЫ ========== */
.hidden { display: none !important; }

.divider {
    text-align: center;
    color: var(--chat-text-light);
    font-size: 12px;
    padding: 6px 0;
}

.divider::before,
.divider::after {
    content: '';
    display: inline-block;
    width: 30px;
    height: 1px;
    background: #E2E8F0;
    vertical-align: middle;
    margin: 0 10px;
}