/* Плавающая кнопка чата */
.chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: #667eea;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10000;
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.25s ease, visibility 0.25s ease;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.chat-button svg {
    width: 30px;
    height: 30px;
    fill: white;
}

/* Скрыть круглую кнопку, когда чат открыт (класс выставляется в JS на саму кнопку) */
.chat-button.chat-button-hidden {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

#chat-widget.chat-open .chat-button {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Окно чата — анимация открытия/закрытия */
.chat-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 10001;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.9) translateY(20px);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease, box-shadow 0.25s ease;
}

.chat-window.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: scale(1) translateY(0);
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}

.chat-header {
    background: #667eea;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease, transform 0.15s ease;
}

.chat-close:hover {
    background: rgba(255,255,255,0.2);
}

.chat-close:active {
    transform: scale(0.95);
}

/* Форма регистрации */
.chat-form {
    padding: 20px;
    display: none;
    transition: opacity 0.2s ease;
}

.chat-form.active {
    display: block;
    animation: chat-fade-in 0.25s ease;
}

@keyframes chat-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.chat-form-group {
    margin-bottom: 15px;
}

.chat-form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
    color: #333;
    font-weight: 500;
}

.chat-form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.chat-form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.chat-form-group .required {
    color: #e74c3c;
}

.chat-checkbox-group {
    margin-top: 10px;
}

.chat-checkbox-label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    font-size: 11px;
    line-height: 1.4;
    margin-bottom: 0;
    position: relative;
}

.chat-checkbox-label input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    margin-top: 2px;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
    z-index: 1;
}

.chat-checkbox-label span {
    color: #333;
    user-select: none;
    display: inline;
    font-size: 11px;
}

.chat-checkbox-label .chat-link {
    color: #667eea !important;
    text-decoration: underline !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    display: inline !important;
    font-weight: normal;
    font-size: 11px;
    position: relative;
    z-index: 2;
}

.chat-checkbox-label .chat-link:hover {
    color: #5568d3 !important;
    text-decoration: underline !important;
}

.chat-form-submit {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s;
}

.chat-form-submit:hover {
    background: #5568d3;
}

.chat-form-submit:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Область сообщений */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f9f9f9;
    display: none;
}

.chat-messages.active {
    display: block;
    animation: chat-fade-in 0.25s ease;
}

.chat-message-wrapper {
    display: flex;
    margin-bottom: 15px;
    gap: 10px;
    animation: chat-message-in 0.3s ease;
}

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

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

.chat-message-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid lightgray;
}

.chat-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-message {
    margin-bottom: 0;
    padding: 10px 15px;
    border-radius: 10px;
    max-width: calc(80% - 50px);
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
}

.chat-message-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 5px;
    opacity: 0.8;
}

.chat-message.user .chat-message-name {
    color: rgba(255, 255, 255, 0.9);
}

.chat-message.assistant .chat-message-name {
    color: #667eea;
}

.chat-message-text {
    word-wrap: break-word;
}

.chat-message-text a {
    color: #667eea;
    text-decoration: underline;
    word-break: break-all;
}

.chat-message.user .chat-message-text a {
    color: #ffffff;
    text-decoration: underline;
}

.chat-message a:hover {
    opacity: 0.8;
}

.chat-message.user {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chat-message-wrapper.user .chat-message {
    margin-left: auto;
}

.chat-message-wrapper.assistant .chat-message {
    margin-right: auto;
}

.chat-message-image {
    max-width: 100%;
    width: 100%;
    max-height: 200px;
    border-radius: 8px;
    margin-top: 10px;
    cursor: pointer;
    display: block;
    object-fit: contain;
}

.chat-image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000;
    cursor: pointer;
}

.chat-image-modal-content {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 5px;
}

/* Поле ввода */
.chat-input-area {
    padding: 15px;
    border-top: 1px solid #eee;
    display: none;
}

.chat-input-area.active {
    display: flex;
    gap: 10px;
    animation: chat-fade-in 0.25s ease;
}

.chat-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.chat-input:focus {
    outline: none;
    border-color: #667eea;
}

.chat-send {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.chat-send:hover {
    background: #5568d3;
}

.chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Загрузка — «Ассистент печатает…» */
.chat-loading {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    color: #666;
    font-size: 14px;
}

.chat-typing-text {
    margin-right: 2px;
}

.chat-typing-dots {
    display: inline-block;
    width: 1.2em;
    text-align: left;
}

.chat-typing-dots::after {
    content: '...';
    animation: chat-typing-dots-opacity 0.6s ease-in-out infinite;
}

@keyframes chat-typing-dots-opacity {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Адаптивность */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 80px;
        height: calc(100vh - 100px);
    }
    
    .chat-button {
        right: 10px;
        bottom: 10px;
    }
}
