/**
 * ==============================================
 * CHAT WIDGET (BEM)
 * ==============================================
 * Block: .chat
 * Elements: __toggle, __container, __header, __avatar, __messages, __message, __input, __btn
 * Modifiers: --active, --bot, --user, --system
 */

.chat {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-xl);
    z-index: var(--z-fixed);
}

/* ===== Toggle Button ===== */
.chat__toggle {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    border: none;
    cursor: pointer;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 40px rgba(250, 204, 21, 0.4);
    transition: all var(--transition-base);
    position: relative;
}

.chat__toggle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    opacity: 0.6;
    animation: chatHeartbeat 2s ease-in-out infinite;
    z-index: -1;
}

.chat__toggle::after {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    opacity: 0.3;
    animation: chatHeartbeat 2s ease-in-out infinite 0.3s;
    z-index: -2;
}

@keyframes chatHeartbeat {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.15); opacity: 0; }
}

.chat__toggle:hover {
    transform: scale(1.1);
}

.chat__toggle:hover::before,
.chat__toggle:hover::after {
    animation-play-state: paused;
    opacity: 0;
}

.chat__toggle:focus-visible {
    box-shadow: var(--focus-ring);
}

.chat__toggle--active {
    background: var(--color-bg-primary);
    border: 2px solid var(--color-border-light);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.chat__toggle--active::before,
.chat__toggle--active::after {
    display: none;
}

/* ===== Notification Dot ===== */
.chat__notification {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: var(--color-accent);
    border-radius: var(--radius-full);
    border: 3px solid var(--color-bg-darker);
    animation: notifyPulse 2s ease-in-out infinite;
}

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

.chat__toggle--active .chat__notification {
    display: none;
}

/* ===== Chat Container ===== */
.chat__container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 520px;
    background: rgba(17, 20, 24, 0.9);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border-light);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

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

/* ===== Chat Header ===== */
.chat__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: var(--space-md) 1.25rem;
    background: linear-gradient(135deg, rgba(250, 204, 21, 0.06) 0%, rgba(20, 184, 166, 0.06) 100%);
    border-bottom: 1px solid var(--color-border-lighter);
    position: relative;
}

.chat__header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(250, 204, 21, 0.3), rgba(20, 184, 166, 0.3), transparent);
}

.chat__header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat__avatar-wrapper {
    position: relative;
}

.chat__avatar {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--color-bg-darker);
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(250, 204, 21, 0.3);
}

.chat__online {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: var(--color-success);
    border-radius: var(--radius-full);
    border: 2px solid var(--color-bg-primary);
    animation: onlinePulse 2s ease-in-out infinite;
}

@keyframes onlinePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

.chat__header-text h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 2px;
}

.chat__header-text p {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.chat__remaining {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    background: rgba(20, 184, 166, 0.12);
    color: var(--color-accent);
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid rgba(20, 184, 166, 0.2);
}

.chat__close {
    background: var(--color-bg-glass);
    border: 1px solid var(--color-border-lighter);
    border-radius: var(--radius-full);
    width: 32px;
    height: 32px;
    color: var(--color-text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat__close:hover {
    background: var(--color-bg-glass-hover);
    color: var(--color-primary);
    transform: rotate(90deg);
}

.chat__close:focus-visible {
    box-shadow: var(--focus-ring);
}

/* ===== Chat Messages ===== */
.chat__messages {
    flex: 1;
    padding: var(--space-md);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat__messages::-webkit-scrollbar { width: 4px; }
.chat__messages::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 4px; }

.chat__message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.6;
    animation: chatMsgFade 0.4s ease;
}

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

.chat__message--bot {
    background: var(--color-bg-glass);
    color: var(--color-text-secondary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--color-border-lighter);
    margin-left: 40px;
    position: relative;
}

.chat__message--bot::before {
    content: 'CR';
    position: absolute;
    left: -40px;
    top: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: var(--color-bg-darker);
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat__message--user {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: var(--color-bg-darker);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.chat__message--system {
    background: rgba(249, 115, 22, 0.1);
    color: var(--color-secondary);
    align-self: center;
    text-align: center;
    font-size: 0.8rem;
    border: 1px solid rgba(249, 115, 22, 0.2);
    border-radius: var(--radius-md);
}

/* ===== Typing Indicator ===== */
.chat__typing {
    display: none;
    padding: 14px 18px;
    background: var(--color-bg-glass);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    margin: 0 var(--space-md) 0 calc(var(--space-md) + 40px);
    gap: 5px;
    position: relative;
}

.chat__typing::before {
    content: 'CR';
    position: absolute;
    left: -40px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: var(--color-bg-darker);
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat__typing--show { display: flex; }

.chat__typing-dot {
    width: 8px;
    height: 8px;
    background: var(--color-accent);
    border-radius: var(--radius-full);
    animation: chatTypingBounce 1.4s infinite ease-in-out;
}

.chat__typing-dot:nth-child(1) { animation-delay: 0s; }
.chat__typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat__typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* ===== Quick Questions ===== */
.chat__quick {
    padding: var(--space-sm) var(--space-md) 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.2);
}

.chat__quick-btn {
    padding: 8px 14px;
    background: rgba(20, 184, 166, 0.1);
    border: 1px solid rgba(20, 184, 166, 0.2);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--color-accent);
    cursor: pointer;
    transition: all var(--transition-base);
    font-family: var(--font-body);
    font-weight: 500;
}

.chat__quick-btn:hover:not(:disabled) {
    background: var(--color-accent);
    color: var(--color-bg-darker);
    transform: translateY(-2px);
}

.chat__quick-btn:focus-visible {
    box-shadow: var(--focus-ring-accent);
}

.chat__quick-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ===== Chat Input ===== */
.chat__input-container {
    padding: var(--space-md);
    border-top: 1px solid var(--color-border-lighter);
    display: flex;
    gap: 10px;
}

.chat__input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid var(--color-border-light);
    border-radius: 24px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--color-text-primary);
    font-size: 0.9rem;
    outline: none;
    font-family: var(--font-body);
}

.chat__input:focus {
    border-color: var(--color-accent);
    box-shadow: var(--focus-ring-accent);
}

.chat__input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat__send {
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: var(--color-bg-darker);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
}

.chat__send:hover:not(:disabled) {
    transform: scale(1.08);
}

.chat__send:focus-visible {
    box-shadow: var(--focus-ring);
}

.chat__send:disabled {
    background: var(--color-bg-glass);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 480px) {
    .chat {
        bottom: var(--space-md);
        right: var(--space-md);
    }

    .chat__toggle {
        width: 56px;
        height: 56px;
        font-size: 1.4rem;
    }

    .chat__container {
        width: calc(100vw - 2rem);
        height: calc(100vh - 100px);
        max-height: 500px;
        right: -0.5rem;
    }

    .chat__message--bot {
        margin-left: 36px;
    }

    .chat__message--bot::before {
        left: -36px;
        width: 28px;
        height: 28px;
    }
}
