/* Основные стили для Q&A системы в стиле DeepSeek */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Разрешаем выделение текста в сообщениях и текстовых полях */
.message,
.feedback-textarea,
.message-input {
    user-select: text;
}

/* Запрещаем выделение для интерактивных элементов */
.feedback-button,
.rating-star-popup,
.feedback-cancel,
.feedback-submit,
.send-button,
.attach-button,
.attachment-remove,
.reset-button,
.source-ref {
    user-select: none;
}

body {
    font-family: "Exo 2", "Open Sans", Arial, Helvetica, sans-serif;
    background: linear-gradient(45deg, #012057, #034be2, #012057, #034be2);
    background-size: 400% 400%;
    animation: ambientFlow 20s ease-in-out infinite;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

@keyframes ambientFlow {
    0% {
        background-position: 0% 50%;
    }
    25% {
        background-position: 100% 30%;
    }
    50% {
        background-position: 80% 70%;
    }
    75% {
        background-position: 20% 80%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.container {
    width: 100%;
    max-width: 800px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}


/* Логотип */
.logo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

.logo {
    height: 30px;
    width: auto;
    object-fit: contain;
}

/* Чат контейнер */
.chat-container {
    flex: 1;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 20px;
}

/* Шапка профиля */
.chat-header {
    background-color: #f8f9fa;
    border-radius: 12px 12px 0 0;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.chat-theme {
    font-size: 14px;
    color: #374151;
    line-height: 1.4;
    max-height: calc(1.4em * 3); /* Максимум 3 строки */
    overflow-y: auto;
    overflow-x: hidden;
    word-wrap: break-word;
    font-weight: 500;
}

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

.chat-theme::-webkit-scrollbar-track {
    background: transparent;
}

.chat-theme::-webkit-scrollbar-thumb {
    background-color: #d1d5db;
    border-radius: 2px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Стили сообщений */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user {
    background-color: #f0f2f5;
    color: #000000;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background-color: #ffffff;
    color: #000000;
    align-self: flex-start;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.message.assistant a {
    color: #2966e7;
    text-decoration: none;
}

.message.assistant a:hover {
    text-decoration: underline;
}

/* Индикатор загрузки */
.message.loading {
    background-color: #ffffff;
    color: #000000;
    align-self: flex-start;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background-color: #81868f;
    border-radius: 50%;
    animation: loading 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

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

/* Поле ввода */
.input-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.input-wrapper {
    display: flex;
    background-color: #ffffff;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    align-items: center;
    gap: 12px;
}

.file-input {
    display: none;
}

.attach-button {
    width: 40px;
    height: 40px;
    border: 1px solid #dbe3f1;
    border-radius: 8px;
    background: #f7f9fc;
    color: #1f4fd4;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.attach-button:hover:not(:disabled) {
    background: #eaf0ff;
    border-color: #2966e7;
    transform: translateY(-1px);
}

.attach-button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.attachments-list {
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
}

.attachments-list.visible {
    display: flex;
}

.attachment-chip,
.attachment-status {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    padding: 7px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    color: #1f2937;
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.attachment-name {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-remove {
    width: 22px;
    height: 22px;
    margin-left: 7px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-size: 19px;
    line-height: 1;
}

.attachment-remove:hover:not(:disabled) {
    background: #fee2e2;
    color: #dc2626;
}

.attachment-status {
    color: #4b5563;
}

.message-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    color: #000000;
    background: transparent;
    min-height: 24px;
    max-height: 120px;
    overflow-y: auto;
    padding: 2px 0;
    text-align: left;
    vertical-align: top;
}

.message-input::placeholder {
    color: #81868f;
}

.send-button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background-color: #2966e7;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background-color: #1f4fd4;
    transform: translateY(-1px);
}

.send-button:disabled {
    background-color: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

/* Анимация смайлика при отправке */
.send-emoji {
    font-size: 18px;
    transition: transform 0.3s ease;
}

.send-button.sending .send-emoji {
    animation: shrinkEmoji 1s ease-in-out;
}

@keyframes shrinkEmoji {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.3);
    }
    100% {
        transform: scale(1);
    }
}

.reset-container {
    display: flex;
    justify-content: center;
}

.reset-button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-button:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

/* Объединенная панель управления */
.bottom-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
}

.control-button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.control-button:hover {
    background-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

/* Индикатор пользователя */
.user-indicator {
    position: absolute;
    bottom: 0;
    left: 0;
    color: white;
    font-size: 14px;
    font-weight: 500;
    opacity: 0.8;
}

/* Скроллбар */
.messages::-webkit-scrollbar {
    width: 6px;
}

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

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

.messages::-webkit-scrollbar-thumb:hover {
    background-color: #9ca3af;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        height: 100vh;
        max-width: 100%;
    }

    .logo {
        height: 25px;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-theme {
        font-size: 13px;
    }

    .logo-container {
        margin-bottom: 15px;
    }

    .messages {
        padding: 12px;
        gap: 12px;
    }

    .message {
        max-width: 95%;
        padding: 10px 12px;
        font-size: 14px;
    }

    .input-wrapper {
        padding: 8px;
        gap: 8px;
    }

    .message-input {
        font-size: 16px; /* Предотвращает зум на iOS */
        min-height: 20px;
    }

    .send-button {
        width: 36px;
        height: 36px;
    }

    .attach-button {
        width: 36px;
        height: 36px;
    }

    .attachment-name {
        max-width: 210px;
    }

    /* Адаптивность для popup */
    .rating-popup-content {
        padding: 25px;
        max-width: 440px;
        width: 95%;
    }

    .rating-star-popup {
        font-size: 28px;
    }

    .feedback-textarea {
        height: 100px;
        font-size: 14px;
    }

    /* Адаптивность для кнопок и оценок */
    .feedback-button {
        max-width: 95%;
        padding: 6px 10px;
        font-size: 13px;
    }

    .submitted-rating {
        max-width: 95%;
        padding: 6px 10px;
        font-size: 13px;
        word-wrap: break-word;
    }

    .user-indicator {
        font-size: 12px;
    }
}

/* Дополнительная адаптивность для очень маленьких экранов */
@media (max-width: 480px) {
    .container {
        height: 100vh;
        padding: 0;
    }

    .logo-container {
        margin-bottom: 10px;
    }

    .messages {
        padding: 8px;
        gap: 8px;
    }

    .rating-popup-content {
        padding: 20px;
        max-width: 400px;
    }

    .rating-popup-title {
        font-size: 16px;
    }

    .rating-star-popup {
        font-size: 24px;
        gap: 4px;
    }

    .feedback-actions {
        flex-direction: column;
        gap: 8px;
    }

    .feedback-cancel,
    .feedback-submit {
        width: 100%;
        padding: 10px;
    }

    /* Мобильная адаптация для кнопки Reset */
    .container {
        padding-bottom: 70px;
    }

    .user-indicator {
        bottom: 50px;
        font-size: 11px;
    }

    .reset-container {
        position: fixed;
        bottom: 15px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 10;
    }

    .reset-button {
        padding: 6px 12px;
        font-size: 12px;
        background-color: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(4px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
}

/* Адаптивность по соотношению сторон */
@media (max-aspect-ratio: 1/1) {
    .container {
        height: 100vh;
        padding-bottom: 80px; /* Добавляем отступ снизу для кнопки Reset */
    }

    .logo-container {
        margin-bottom: 10px;
    }

    .messages {
        flex: 1;
        min-height: 0;
    }

    .user-indicator {
        bottom: 60px; /* Поднимаем индикатор выше кнопки Reset */
    }

    .reset-container {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 10;
    }

    .reset-button {
        background-color: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(4px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .reset-button:hover {
        background-color: rgba(255, 255, 255, 0.3);
    }
}

/* Состояние отключенного интерфейса во время загрузки */
.container.loading .input-wrapper {
    opacity: 0.6;
    pointer-events: none;
}

/* Кнопка оценки под сообщениями */
.feedback-button {
    max-width: 85%;
    align-self: flex-start;
    margin-top: 8px;
    padding: 8px 12px;
    background-color: #f9f9f9;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.feedback-button:hover {
    background-color: #f0f0f0;
    border-color: #d1d5db;
}

/* Popup окно для оценки */
.rating-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.rating-popup.visible {
    opacity: 1;
    visibility: visible;
}

.rating-popup-content {
    background-color: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    border: 4px solid #e5e7eb;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transition: border-color 0.3s ease;
}

.rating-popup-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    text-align: center;
    color: #333;
}

.rating-stars-popup {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.rating-star-popup {
    font-size: 32px;
    cursor: pointer;
    transition: transform 0.1s ease;
    user-select: none;
}

.rating-star-popup:hover {
    transform: scale(1.1);
}

.feedback-textarea {
    width: 100%;
    height: 125px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 15px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    outline: none;
    margin-bottom: 20px;
}

.feedback-textarea::placeholder {
    color: #9ca3af;
}

.feedback-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.feedback-cancel {
    padding: 10px 20px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    background-color: white;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.feedback-cancel:hover {
    background-color: #d1d5db;
}

.feedback-submit {
    padding: 10px 20px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    background-color: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

/* Цветовые схемы для рейтингов */
.rating-1 { border-color: #ef4444; color: #ef4444; }
.rating-1 .rating-popup-content { border-color: #ef4444; }
.rating-1 .feedback-submit { border-color: #ef4444; color: #ef4444; }
.rating-1 .feedback-submit:hover { background-color: #ef4444; color: white; }

.rating-2 { border-color: #f97316; color: #f97316; }
.rating-2 .rating-popup-content { border-color: #f97316; }
.rating-2 .feedback-submit { border-color: #f97316; color: #f97316; }
.rating-2 .feedback-submit:hover { background-color: #f97316; color: white; }

.rating-3 { border-color: #eab308; color: #eab308; }
.rating-3 .rating-popup-content { border-color: #eab308; }
.rating-3 .feedback-submit { border-color: #eab308; color: #eab308; }
.rating-3 .feedback-submit:hover { background-color: #eab308; color: white; }

.rating-4 { border-color: #3b82f6; color: #3b82f6; }
.rating-4 .rating-popup-content { border-color: #3b82f6; }
.rating-4 .feedback-submit { border-color: #3b82f6; color: #3b82f6; }
.rating-4 .feedback-submit:hover { background-color: #3b82f6; color: white; }

.rating-5 { border-color: #22c55e; color: #22c55e; }
.rating-5 .rating-popup-content { border-color: #22c55e; }
.rating-5 .feedback-submit { border-color: #22c55e; color: #22c55e; }
.rating-5 .feedback-submit:hover { background-color: #22c55e; color: white; }

/* Отображение отправленной оценки */
.submitted-rating {
    max-width: 85%;
    align-self: flex-start;
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    border: 2px solid;
    opacity: 0.8;
}

.submitted-rating.rating-1 {
    border-color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}
.submitted-rating.rating-2 {
    border-color: #f97316;
    background-color: rgba(249, 115, 22, 0.1);
    color: #f97316;
}
.submitted-rating.rating-3 {
    border-color: #eab308;
    background-color: rgba(234, 179, 8, 0.1);
    color: #eab308;
}
.submitted-rating.rating-4 {
    border-color: #3b82f6;
    background-color: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}
.submitted-rating.rating-5 {
    border-color: #22c55e;
    background-color: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

/* Стили для Markdown контента */
.message h1, .message h2, .message h3 {
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.message h1 { font-size: 24px; }
.message h2 { font-size: 20px; }
.message h3 { font-size: 18px; }

.message strong {
    font-weight: 600;
}

.message em {
    font-style: italic;
}

.message code {
    background-color: #f3f4f6;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.message pre {
    background-color: #f3f4f6;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.message pre code {
    background: none;
    padding: 0;
}

.message ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message li {
    margin: 4px 0;
}

.message p {
    margin: 8px 0;
}

.message hr {
    border: none;
    border-top: 2px solid #e5e7eb;
    margin: 16px 0;
    opacity: 0.7;
}

/* Стили для источников */
.source-ref {
    display: inline-block;
    background-color: #f3f4f6;
    border: 1px solid #6b7280;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    position: relative;
    margin: 0 2px;
    transition: all 0.2s ease;
    vertical-align: super;
    line-height: 1;
}

.source-ref:hover {
    background-color: #e5e7eb;
    border-color: #374151;
    transform: translateY(-1px);
}

/* Tooltip для источников */
.source-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #1f2937;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1000;
    margin-bottom: 5px;
    pointer-events: none;
}

.source-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1f2937;
}

.source-tooltip.visible {
    opacity: 1;
    visibility: visible;
}
