/**
 * Frontend CSS для интеграции AI
 */

/* Основной контейнер результатов */
.qsm-ai-results {
    max-width: 900px;
    margin: 40px auto;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

/* Заголовок */
.qsm-ai-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    padding: 40px;
    text-align: center;
}

.qsm-ai-title {
    margin: 0 0 10px 0;
    font-size: 28px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.qsm-ai-icon {
    width: 32px;
    height: 32px;
    color: #ffffff;
}

.qsm-ai-subtitle {
    margin: 0;
    font-size: 16px;
    opacity: 0.9;
    font-weight: 400;
}

/* Секции с результатами */
.qsm-ai-section {
    padding: 32px 40px;
    border-bottom: 1px solid #e5e7eb;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease;
}

.qsm-ai-section:last-of-type {
    border-bottom: none;
}

.qsm-ai-section-animated {
    opacity: 1;
    transform: translateY(0);
}

.qsm-ai-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.qsm-ai-section-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex-shrink: 0;
}

.qsm-ai-result .qsm-ai-section-icon {
    background: #d1fae5;
    color: #065f46;
}

.qsm-ai-analysis .qsm-ai-section-icon {
    background: #dbeafe;
    color: #1e40af;
}

.qsm-ai-recommendations .qsm-ai-section-icon {
    background: #fef3c7;
    color: #92400e;
}

.qsm-ai-section-title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: #111827;
}

.qsm-ai-section-content {
    font-size: 16px;
    line-height: 1.7;
    color: #374151;
}

.qsm-ai-section-content p {
    margin: 0 0 16px 0;
}

.qsm-ai-section-content p:last-child {
    margin-bottom: 0;
}

.qsm-ai-section-content strong {
    color: #111827;
    font-weight: 600;
}

.qsm-ai-section-content em {
    font-style: italic;
    color: #6b7280;
}

.qsm-ai-section-content ul,
.qsm-ai-section-content ol {
    margin: 16px 0;
    padding-left: 24px;
}

.qsm-ai-section-content li {
    margin-bottom: 12px;
    line-height: 1.6;
}

.qsm-ai-section-content li:last-child {
    margin-bottom: 0;
}

/* Футер */
.qsm-ai-footer {
    padding: 24px 40px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.qsm-ai-disclaimer {
    margin: 0;
    font-size: 14px;
    color: #6b7280;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.6;
}

.qsm-ai-info-icon {
    flex-shrink: 0;
    margin-top: 2px;
    color: #9ca3af;
}

/* Индикатор загрузки */
.qsm-ai-loading {
    text-align: center;
    padding: 60px 40px;
    background: #ffffff;
    border-radius: 16px;
    margin: 40px 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.qsm-ai-spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 20px;
    border: 4px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: qsm-ai-spin 1s linear infinite;
}

@keyframes qsm-ai-spin {
    to {
        transform: rotate(360deg);
    }
}

.qsm-ai-loading p {
    margin: 0;
    font-size: 18px;
    color: #374151;
    font-weight: 500;
}

/* Ошибка */
.qsm-ai-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 12px;
    padding: 20px;
    margin: 40px 0;
    display: flex;
    align-items: center;
    gap: 16px;
}

.qsm-ai-error-icon {
    flex-shrink: 0;
    color: #dc2626;
}

.qsm-ai-error p {
    margin: 0;
    color: #991b1b;
    font-size: 16px;
}

/* Для drawing-теста не показываем fallback "нет подключения", пока AI-запрос ещё выполняется */
.psy-test.qsm-ai-drawing-pending #fallbackBlock {
    display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
    .qsm-ai-results {
        margin: 20px;
        border-radius: 12px;
    }
    
    .qsm-ai-header {
        padding: 30px 24px;
    }
    
    .qsm-ai-title {
        font-size: 24px;
    }
    
    .qsm-ai-subtitle {
        font-size: 14px;
    }
    
    .qsm-ai-section {
        padding: 24px;
    }
    
    .qsm-ai-section-title {
        font-size: 20px;
    }
    
    .qsm-ai-section-content {
        font-size: 15px;
    }
    
    .qsm-ai-footer {
        padding: 20px 24px;
    }
    
    .qsm-ai-loading {
        padding: 40px 24px;
        margin: 20px;
    }
    
    .qsm-ai-error {
        margin: 20px;
    }
}

/* Анимация появления */
.qsm-ai-results-wrapper {
    animation: qsm-ai-fadein 0.6s ease;
}

@keyframes qsm-ai-fadein {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Улучшения для списков */
.qsm-ai-section-content ul {
    list-style-type: none;
    padding-left: 0;
}

.qsm-ai-section-content ul li {
    padding-left: 28px;
    position: relative;
}

.qsm-ai-section-content ul li:before {
    content: "•";
    position: absolute;
    left: 8px;
    color: #667eea;
    font-weight: bold;
    font-size: 20px;
    line-height: 1.4;
}

/* Градиенты для разных секций */
.qsm-ai-result {
    background: linear-gradient(to right, rgba(209, 250, 229, 0.2) 0%, transparent 100%);
}

.qsm-ai-analysis {
    background: linear-gradient(to right, rgba(219, 234, 254, 0.2) 0%, transparent 100%);
}

.qsm-ai-recommendations {
    background: linear-gradient(to right, rgba(254, 243, 199, 0.2) 0%, transparent 100%);
}

/* СКРЫВАЕМ стандартные результаты теста (.psy-result и .psy-result-raw), когда показываем AI анализ */
.psy-test:has(.qsm-ai-results-wrapper) .psy-result,
.psy-test:has(.qsm-ai-results-wrapper) .psy-result-raw,
.psy-test:has(.qsm-ai-results-wrapper) #results,
.psy-test:has(.qsm-ai-results-wrapper) .results,
.psy-test:has(.qsm-ai-results-wrapper) .quiz-results,
.psy-test:has(.qsm-ai-results-wrapper) #result,
.psy-test:has(.qsm-ai-results-wrapper) #score-display,
.psy-test:has(.qsm-ai-results-wrapper) .score-result,
.psy-test:has(.qsm-ai-results-wrapper) #tpResults,
.psy-test:has(.qsm-ai-results-wrapper) .tp-results,
.psy-test:has(.qsm-ai-results-wrapper) #resultsBox {
    display: none !important;
}

/* Обратная совместимость со старыми контейнерами */
.quiz-container:has(.qsm-ai-results-wrapper) .psy-result,
.quiz-container:has(.qsm-ai-results-wrapper) .psy-result-raw,
.quiz-container:has(.qsm-ai-results-wrapper) #results,
.quiz-container:has(.qsm-ai-results-wrapper) .results,
.quiz-container:has(.qsm-ai-results-wrapper) .quiz-results {
    display: none !important;
}

/* Дополнительная защита - скрываем все возможные блоки результатов при активном анализе */
.qsm-ai-active .psy-result,
.qsm-ai-active .psy-result-raw,
.qsm-ai-active #results,
.qsm-ai-active .results,
.qsm-ai-active .quiz-results,
.qsm-ai-active #result,
.qsm-ai-active #score-display,
.qsm-ai-active #tpResults,
.qsm-ai-active .tp-results,
.qsm-ai-active #resultsBox {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* АГРЕССИВНОЕ скрытие через атрибутный селектор (но НЕ результаты AI) */
.qsm-ai-active [id*="result"]:not(.qsm-ai-results-wrapper):not([class*="ai"]):not(.psy-result):not(.psy-result-raw),
.qsm-ai-active [class*="result"]:not(.qsm-ai-results-wrapper):not([class*="ai"]):not(.psy-result):not(.psy-result-raw) {
    display: none !important;
    visibility: hidden !important;
}

/* ВАЖНО: .psy-result и .psy-result-raw должны быть ВИДИМЫМИ при отсутствии класса qsm-ai-active */
/* Это позволяет показывать стандартные результаты при ошибках ИИ */
.psy-test:not(.qsm-ai-active) .psy-result,
.psy-test:not(.qsm-ai-active) .psy-result-raw {
    /* Результаты будут видимыми, если у них нет display: none от других стилей */
}
