/* AI Assistant Styles - ChatGPT-like interface */

/* CSS переменные для динамических размеров */
:root {
    --ai-header-height: 2.8rem;
    --ai-footer-height: 67px;
    --ai-input-height: 58px; /* начальное значение, обновляется через JS */
    --ai-bottom-offset: calc(var(--ai-input-height) + var(--ai-footer-height));
}

/* Alpine.js cloak - скрываем элементы до инициализации */
[x-cloak] {
    display: none !important;
}

/* Body для AI Assistant */
.ai-assistant-body {
    margin: 0;
    padding: 0;
}

/* Главный контейнер страницы */
#page-container {
    min-height: 100vh;
    min-height: 100dvh;
}

/* Footer остается как есть (position: fixed, height: 67px, z-index: 1030) */

/* Шапка AI Assistant - фиксированная */
#ai-page-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--ai-header-height);
    background-color: #fff;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: center;
}

.ai-header-content {
    width: 100%;
    max-width: 576px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.5rem;
}

/* Основной контейнер */
#ai-main-container {
    display: flex;
    justify-content: center;
    padding-top: var(--ai-header-height);
    padding-bottom: var(--ai-bottom-offset);
    min-height: calc(100vh - var(--ai-header-height));
    min-height: calc(100dvh - var(--ai-header-height));
}

/* Wrapper внутри main */
.ai-assistant-wrapper {
    width: 100%;
    max-width: 576px;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--ai-header-height) - var(--ai-bottom-offset));
    min-height: calc(100dvh - var(--ai-header-height) - var(--ai-bottom-offset));
}

/* Main page container */
.ai-assistant-page {
    width: 100%;
    background-color: #ffffff;
    position: relative;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

/* Conversation list - абсолютное позиционирование */
.ai-conversation-list {
    position: absolute;
    z-index: 1000;
}

/* Messages Area - flex контейнер, скролл на уровне body */
.ai-assistant-messages {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    padding: 0.1rem 0.25rem;
    margin: 0 1rem;
    background-color: #ffffff;
}

/* Spacer - занимает свободное место, прижимая сообщения вниз */
.ai-messages-spacer {
    flex-grow: 1;
    margin-bottom: 0rem; /* отступ между spacer и контентом */
}

.ai-assistant-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.ai-assistant-empty-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.ai-assistant-empty-content:hover {
    opacity: 0.8;
}

.ai-assistant-empty-icon {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.ai-assistant-empty-text {
    margin: 0;
    color: #6c757d;
    font-size: 1rem;
    transition: color 0.2s ease;
}

.ai-assistant-empty-content:hover .ai-assistant-empty-text {
    color: #3b82f6;
}

/* Message Styles */
.ai-message {
    margin-top: 0.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
}

.ai-message:last-of-type {
    margin-bottom: 0;
}

.ai-message-user {
    background-color: #e8f4fc;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    max-width: 85%;
    margin-left: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.1);
    text-align: right;
}

/* Подсветка при добавлении через quick prompt / follow-up */
.ai-message-user.ai-message-highlight {
    animation: messageHighlight 2s ease-out;
}

@keyframes messageHighlight {
    0% {
        background-color: #d5e7f9;
        box-shadow: 0 0 12px rgba(247, 222, 123, 0.6);
    }
    30% {
        background-color: #e5f1fd;
        box-shadow: 0 0 16px rgba(249, 223, 122, 0.5);
    }
    100% {
        background-color: #e8f4fc;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.1);
    }
}

.ai-message-assistant {
    background-color: transparent;
    padding: 0.5rem 0;
    max-width: 100%;
    width: 100%;
    line-height: 1.6;
    /* Минимальная высота для предотвращения сдвига верстки при переключении между отдельным курсором и сообщением */
    min-height: 1.6rem;
    /* Изоляция перерисовки для предотвращения сдвига верстки */
    contain: layout style;
}

.ai-message-error {
    background-color: #fee;
    color: #c33;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    max-width: 85%;
    margin-left: auto;
    border: 1px solid #fcc;
}

.ai-message-content {
    word-wrap: break-word;
    width: 100%;
}

/* Cursor animation */
.ai-cursor {
    display: inline-block;
    animation: blink 1s infinite;
    color: #3b82f6;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Контейнер для стриминга ответа */
.ai-pending-response {
    margin-bottom: 0;
}

.ai-pending-response .ai-message-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-height: 0;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    /* Изоляция перерисовки во время стриминга */
    contain: layout style;
    transform: translateZ(0);
}

.ai-pending-response .ai-message-assistant {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

.ai-pending-response .ai-message-content {
    height: auto !important;
    overflow: visible !important;
}

/* Лоадер скрывается когда есть контент стриминга */
.ai-stream-content:not(:empty) + .ai-stream-loader {
    display: none !important;
}

/* Курсор показывается только когда есть контент стриминга */
.ai-stream-cursor {
    display: none;
}

.ai-stream-content:not(:empty) + .ai-stream-loader + .ai-stream-cursor,
.ai-stream-content:not(:empty) ~ .ai-stream-cursor {
    display: inline-block;
}

/* Waiting Indicator */
.ai-waiting {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.ai-waiting-text {
    margin-right: 0.25rem;
}

.ai-waiting-dots {
    display: inline-flex;
    gap: 0.125rem;
}

.ai-waiting-dots span {
    animation: waiting-dot 1.4s infinite;
    animation-delay: calc(var(--i) * 0.2s);
}

.ai-waiting-dots span:nth-child(1) { --i: 0; }
.ai-waiting-dots span:nth-child(2) { --i: 1; }
.ai-waiting-dots span:nth-child(3) { --i: 2; }

/* Фиксированный бэдж ожидания */
/* Сообщение ожидания вместо поля ввода */
.ai-waiting-message {
    width: 100%;
    padding: 0.5rem;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.0rem;
    font-size: 1rem;
    line-height: 1.5;
    color: #999;
    background-color: transparent;
    border: none;
}

/* ********************* */
/* * ai-waiting-message-text() - эффект сканирования через текст с background-clip */
/* * */
.ai-waiting-message-text {
    white-space: nowrap;
    position: relative;
    color: #999;
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    box-sizing: border-box;
    /* Аппаратное ускорение для webview */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    overflow: visible;
    /* Градиент на тексте через background-clip */
    background: linear-gradient(90deg, 
        #999 0%, 
        #999 40%, 
        #6e94d2 45%, 
        #3e72c6 50%, 
        #6e94d2 55%, 
        #999 60%, 
        #999 100%);
    background-size: 230% 100%;
    background-repeat: repeat-x;
    will-change: background-position;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    -webkit-animation: ai-scanning-text 1.5s linear infinite;
    animation: ai-scanning-text 1.5s linear infinite;
}


/* ********************* */
/* * ai-scanning-text() - анимация смещения градиента для эффекта сканирования */
/* * */
@-webkit-keyframes ai-scanning-text {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: 0% 0;
    }
}

@keyframes ai-scanning-text {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: 0% 0;
    }
}


.ai-waiting-message-dots {
    display: inline-flex;
    gap: 0.125rem;
}

.ai-waiting-message-dots span {
    -webkit-animation: waiting-dot 1.4s infinite;
    animation: waiting-dot 1.4s infinite;
    animation-delay: calc(var(--i) * 0.2s);
    -webkit-animation-delay: calc(var(--i) * 0.2s);
}

.ai-waiting-message-dots span:nth-child(1) { --i: 0; }
.ai-waiting-message-dots span:nth-child(2) { --i: 1; }
.ai-waiting-message-dots span:nth-child(3) { --i: 2; }

@-webkit-keyframes waiting-dot {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

@keyframes waiting-dot {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

/* Waiting Indicator above input */
.ai-waiting-indicator {
    background-color: #f0f4f8;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    animation: fadeIn 0.3s ease-out;
}

/* Input Area - фиксированное над футером */
.ai-assistant-input {
    position: fixed;
    bottom: var(--ai-footer-height);
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 576px;
    z-index: 100;
    border-top: 1px solid #e5e5e5;
    background-color: #f2f2f2;
    padding: 0.3rem 0.5rem;
    display: flex;
    justify-content: center;
    overflow: visible;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15), 0 -2px 6px rgba(0, 0, 0, 0.1);
}

.ai-assistant-input > * {
    width: 100%;
    max-width: 576px;
    overflow: visible;
}

.ai-input-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    overflow: visible;
}

.ai-input-field {
    width: 100%;
    border: none;
    padding: 0.5rem;
    resize: none;
    font-size: 1rem;
    line-height: 1.5;
    max-height: 200px;
    min-height: 42px;
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE и Edge */
    background-color: transparent;
}

.ai-input-field::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.ai-input-field:focus {
    outline: none;
}

/* Временный эффект сканирования для placeholder - для экспериментов */
.ai-input-field-wrapper {
    position: relative;
}

.ai-input-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.25rem 0.5rem 0.25rem 0.5rem;
    gap: 0.5rem;
    min-width: 0;
    overflow: visible;
}

.ai-new-chat-btn {
    background-color: #dfdfdf;
    border: 1px solid #d1d5db;
    border-radius: 1rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .ai-new-chat-btn:hover:not(:disabled) {
        background-color: #eeeeee;
        border-color: #9ca3af;
    }
}

.ai-new-chat-btn.ai-new-chat-btn-active:not(:disabled) {
    background-color: #e5e7eb;
    border-color: #9ca3af;
    transition: background-color 0s, border-color 0s;
}

.ai-new-chat-btn:focus {
    outline: none;
}

.ai-new-chat-btn:disabled,
.ai-new-chat-btn:disabled:focus,
.ai-new-chat-btn:disabled:active,
.ai-new-chat-btn:disabled:hover {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #dfdfdf !important;
    border-color: #d1d5db !important;
    pointer-events: none;
}

.ai-new-chat-btn i {
    font-size: 0.7rem;
}

.ai-response-type-dropdown {
    position: relative;
    display: flex;
    justify-content: flex-start;
    flex-shrink: 1;
    min-width: 0;
    z-index: 1002;
}

.ai-response-type-btn {
    background-color: #dfdfdf;
    border: 1px solid #d1d5db;
    border-radius: 1rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
    white-space: nowrap;
    min-width: 0;
}

.ai-response-type-btn:hover:not(:disabled) {
    background-color: #eeeeee;
    border-color: #9ca3af;
}

.ai-response-type-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-response-type-btn i {
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.ai-response-type-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 0.25rem;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    min-width: 150px;
    z-index: 10000;
    overflow: hidden;
}

.ai-response-type-option {
    width: 100%;
    padding: 0.5rem 0.75rem;
    text-align: left;
    background: none;
    border: none;
    font-size: 1.1rem;
    color: #374151;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.ai-response-type-option:hover {
    background-color: #f3f4f6;
}

.ai-response-type-option.active {
    background-color: #e5e7eb;
    font-weight: 500;
}

.ai-send-button {
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    min-width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    flex-shrink: 0;
}

.ai-send-button:hover:not(:disabled) {
    background-color: #2563eb;
}

.ai-send-button:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
}

/* Sidebar Styles */
.ai-sidebar-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    margin: 0 !important;
    padding: 0 !important;
}

.ai-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 50% !important;
    width: 100%;
    max-width: 576px;
    height: 100vh;
    height: 100dvh;
    background-color: #ffffff;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box;
    transform: translateX(-50%);
    /* Предотвращение pull-to-refresh в сайдбаре */
    overscroll-behavior: none;
    overscroll-behavior-y: none;
    -webkit-overscroll-behavior: none;
    touch-action: pan-y;
}

.ai-sidebar-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0.75rem 1rem;
}

.ai-sidebar-close-btn {
    display: flex;
    align-items: center;
    color: #374151;
    text-decoration: none;
    transition: all 0.2s;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 0.2rem 0.75rem;
}

.ai-sidebar-close-btn:hover {
    color: #1f2937;
    text-decoration: none;
    border-color: #d1d5db;
    background-color: #f9fafb;
}

.ai-sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    /* Предотвращение pull-to-refresh только в сайдбаре */
    overscroll-behavior: none;
    overscroll-behavior-y: none;
    overscroll-behavior-x: none;
    -webkit-overscroll-behavior: none;
    touch-action: pan-y;
    -webkit-overflow-scrolling: auto;
}

.ai-sidebar-actions {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ai-sidebar-action-link {
    display: flex;
    align-items: center;
    padding: 0.5rem 0rem;
    color: #374151;
    text-decoration: none;
    font-size: 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
    gap: 0.5rem;
}

.ai-sidebar-action-link:hover {
    background-color: #f3f4f6;
    color: #1f2937;
    text-decoration: none;
}

.ai-sidebar-action-link i {
    width: 1rem;
    text-align: center;
}

.ai-sidebar-content .list-group-item {
    border-left: none;
    border-right: none;
    padding: 0.75rem 1rem;
}

.ai-sidebar-content .list-group-item:first-child {
    border-top: none;
}

.ai-sidebar-content .list-group-item a {
    color: #374151;
    transition: color 0.2s;
}

.ai-sidebar-content .list-group-item a:hover {
    color: #1f2937;
}

.ai-sidebar-content .list-group-item.ai-conversation-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    padding: 0.75rem 1rem 0.5rem 1rem;
    background-color: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}

.ai-conversation-group {
    margin-bottom: 1.5rem;
}

.ai-conversation-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}

.ai-conversation-item {
    display: flex;
    align-items: center;
    padding: 0.1rem 0.75rem;
    border-radius: 0.375rem;
    margin-bottom: 0.3rem;
    transition: background-color 0.2s;
}

.ai-conversation-item:hover {
    background-color: #f3f4f6;
}

.ai-conversation-link {
    flex: 1;
    color: #374151;
    text-decoration: none;
    font-size: 1rem;
    word-wrap: break-word;
    word-break: break-word;
}

.ai-conversation-link:hover {
    color: #1f2937;
}

.ai-conversation-delete {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-conversation-item:hover .ai-conversation-delete {
    opacity: 1;
}

.ai-conversation-delete:hover {
    color: #ef4444;
}

.ai-conversation-empty {
    padding: 2rem;
    text-align: center;
}

/* Message Text */
.ai-message-text {
    word-wrap: break-word;
    width: 100%;
    max-width: 100%;
    display: block;
    padding: 0 0.25rem;
    /* Разрешаем выделение текста */
    -webkit-user-select: text;
    user-select: text;
    /* Изоляция перерисовки для предотвращения моргания */
    contain: layout style;
}

.ai-message-assistant .ai-message-text {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.ai-message-assistant .ai-message-text > * {
    max-width: 100%;
    box-sizing: border-box;
}

/* Стили для всех элементов в ответах - одинаковые отступы */
.ai-message-assistant .ai-message-text > * {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.ai-message-assistant .ai-message-text > *:first-child {
    margin-top: 0;
}

.ai-message-assistant .ai-message-text > *:last-child {
    margin-bottom: 0;
}

/* Специфичные стили для параграфов - одинаковые отступы */
.ai-message-assistant .ai-message-text p {
    margin-top: 0.5rem !important;
    margin-bottom: 0.5rem !important;
}

.ai-message-assistant .ai-message-text p:first-of-type {
    margin-top: 0 !important;
}

.ai-message-assistant .ai-message-text p:last-of-type {
    margin-bottom: 0 !important;
}

/* Убираем нижний отступ у элемента перед курсором, чтобы курсор не сдвигался вниз */
.ai-message-assistant .ai-message-text > *:has(+ .ai-streaming-cursor-line) {
    margin-bottom: 0 !important;
}

/* Fallback для браузеров без поддержки :has() - убираем отступ у предпоследнего элемента если последний - курсор */
.ai-message-assistant .ai-message-text > *:nth-last-child(2):not(.ai-streaming-cursor-line) {
    margin-bottom: 0;
}

/* Дополнительно для параграфов - убираем отступ у параграфа перед курсором */
.ai-message-assistant .ai-message-text > p:nth-last-child(2) {
    margin-bottom: 0 !important;
}

/* Стили для заголовков - увеличенные отступы сверху */
.ai-message-assistant .ai-message-text h1,
.ai-message-assistant .ai-message-text h2,
.ai-message-assistant .ai-message-text h3,
.ai-message-assistant .ai-message-text h4,
.ai-message-assistant .ai-message-text h5,
.ai-message-assistant .ai-message-text h6 {
    margin-top: 1.5rem !important;
    margin-bottom: 0.5rem !important;
}

/* Streaming Cursor - мигающий блочный курсор во время стриминга */
.ai-streaming-cursor-line {
    display: block;
    width: 100%;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    line-height: 1.6;
    /* Компенсируем padding родителя (.ai-message-text имеет padding: 0 1rem) */
    /* Используем отрицательный margin, чтобы курсор был точно под первым символом */
    margin-left: 0rem;
    position: relative;
}

.ai-streaming-cursor {
    display: inline-block;
    width: 0.75rem;
    height: 1.2em;
    background-color: #3b82f6;
    margin: 0;
    padding: 0;
    vertical-align: baseline;
    animation: ai-cursor-blink 1.0s infinite;
    flex-shrink: 0;
    /* Фиксируем позицию курсора, чтобы он был точно под первым символом */
    position: relative;
    /* Убираем любые отступы */
    border: none;
    outline: none;
}

@keyframes ai-cursor-blink {
    0%, 60% {
        opacity: 1;
    }
    61%, 100% {
        opacity: 0;
    }
}

/* Message Actions - под сообщением справа */
.ai-message-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.5rem;
    opacity: 1;
    transition: opacity 0.2s;
}

.ai-message-copy-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    transition: color 0.2s, transform 0.2s;
}

.ai-message-refresh-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    transition: color 0.2s, transform 0.2s;
}

.ai-message-copy-btn i {
    font-size: 1rem;
}

.ai-message-refresh-btn i {
    font-size: 0.95rem;
}

.ai-message-copy-btn:hover,
.ai-message-refresh-btn:hover {
    color: #3b82f6;
    transform: scale(1.1);
}

/* Follow-up Questions */
.ai-followup-questions {
    margin-top: 1rem;
    margin-bottom: 0;
    padding-bottom: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
}

/* Random Questions Message */
.ai-message-random-questions {
    padding: 0.5rem 0;
}

.ai-message-random-questions .ai-followup-questions {
    margin-top: 0;
}

/* Context Questions Message */
.ai-message-context-questions {
    padding: 0.5rem 0;
}

.ai-context-questions-header {
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-context-questions-header i {
    color: #3b82f6;
}

.ai-message-context-questions .ai-followup-questions {
    margin-top: 0;
}

.ai-followup-question-btn {
    background-color: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin: 0.2rem 0;
    text-align: left;
    cursor: pointer;
    transition: background-color 3s ease, border-color 3s ease, color 3s ease;
    font-size: 0.875rem;
    color: #374151;
}

.ai-followup-question-btn.ai-followup-question-btn-active {
    background-color: #cae4f6;
    /* color: #ffffff; */
    border-color: #d1d5db;
    transition: background-color 0s ease, color 0s ease, border-color 0s ease;
}

.ai-followup-question-btn:not(.ai-followup-question-btn-active):not(:disabled) {
    transition: background-color 2s ease, border-color 2s ease, color 2s ease;
}

.ai-followup-question-btn:disabled:not(.ai-followup-question-btn-active) {
    transition: background-color 2s ease, border-color 2s ease, color 2s ease;
}

.ai-followup-question-btn:disabled {
    /* Не меняем стиль при disabled - кнопки должны выглядеть одинаково во время стриминга */
    cursor: not-allowed;
    /* Убираем opacity, чтобы стиль не менялся */
}

/* Bible Reference Links */
.ai-bible-ref-link {
    color: #3b82f6;
    text-decoration: none;
    background-color: transparent;
    transition: color 0.2s, background-color 1.3s;
    padding: 2px 4px;
    border-radius: 3px;
    white-space: nowrap;
}

.ai-bible-ref-link:active,
.ai-bible-ref-link:focus {
    background-color: #e0e7ff;
    transition: background-color 0.1s;
    outline: none;
}

.ai-bible-ref-link:hover {
    color: #2563eb;
}

/* Bible Text Block */
.ai-bible-text-block {
    display: block;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    margin: 2rem 0;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    /* Предотвращаем моргание при перерисовке */
    contain: layout style;
    transform: translateZ(0);
}

/* Переопределяем margin для bible-text-block внутри message-text */
.ai-message-assistant .ai-message-text > .ai-bible-text-block {
    margin-top: 1.2rem !important;
    margin-bottom: 1.2rem !important;
}

.ai-bible-text-block:hover {
    background-color: #f3f4f6;
    border-color: #d1d5db;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.ai-bible-text-header {
    margin-bottom: 0.75rem;
}

.ai-bible-text-ref {
    font-weight: 600;
    color: #374151;
    font-size: 0.875rem;
}

.ai-bible-text-content {
    color: #1f2937;
    line-height: 1.6;
}

/* Стриминговый блок библейского текста (упрощенный, без моргания) */
.ai-bible-text-streaming {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    margin: 1rem 0;
}

.ai-bible-text-streaming strong {
    display: block;
    margin-bottom: 0.5rem;
    color: #374151;
    font-size: 0.875rem;
}

.ai-bible-text-streaming blockquote {
    margin: 0;
    padding: 0;
    border: none;
    color: #1f2937;
    line-height: 1.6;
}

/* Rate Limit Error */
.ai-rate-limit-error {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    margin: 0.5rem 1rem;
    color: #991b1b;
    font-size: 0.875rem;
}

/* Context Badge in Message */
.ai-message-context-badge {
    display: inline-flex;
    align-items: center;
    background-color: #e0f2f7;
    border: 1px solid #b2ebf2;
    border-radius: 0.75rem;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
    white-space: nowrap;
}

.ai-context-link-small {
    color: #007bff;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.ai-context-link-small:hover {
    text-decoration: underline;
}

/* Bible Context Badge (над полем ввода) */
.ai-bible-context-badge {
    padding: 0.75rem;
    background-color: #f8f9fa;
    border-radius: 0.5rem;
    border: 1px solid #e9ecef;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Context Message */
.ai-message-context {
    display: flex;
    flex-direction: column;
}

.ai-context-badge {
    display: inline-flex;
    align-items: center;
    background-color: #e8f4fc;
    border-radius: 0.5rem;
    padding: 0.4rem 0.75rem;
    gap: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.1);
}

.ai-context-link {
    color: #494949;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
}

.ai-context-link:hover {
    text-decoration: underline;
}

.ai-context-remove {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    padding: 0.125rem 0.25rem;
    font-size: 0.75rem;
    transition: color 0.2s;
}

.ai-context-remove:hover {
    color: #dc3545;
}

/* Quick Prompts */
.ai-quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.ai-quick-prompt-btn {
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 1rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    color: #495057;
    cursor: pointer;
    transition: background-color 3s ease, border-color 3s ease, color 3s ease;
}

.ai-quick-prompt-btn.ai-quick-prompt-active {
    background-color: #cae4f6;
    /* color: #ffffff; */
    border-color: #dee2e6;
    transition: background-color 0s ease, color 0s ease, border-color 0s ease;
}

.ai-quick-prompt-btn:not(.ai-quick-prompt-active):not(:disabled) {
    transition: background-color 2s ease, border-color 2s ease, color 2s ease;
}

.ai-quick-prompt-btn:disabled:not(.ai-quick-prompt-active) {
    transition: background-color 2s ease, border-color 2s ease, color 2s ease;
}

.ai-quick-prompt-btn:disabled {
    /* Не меняем стиль при disabled - кнопки должны выглядеть одинаково во время стриминга */
    cursor: not-allowed;
    /* Убираем opacity, чтобы стиль не менялся */
}

/* Streaming message cursor */
.ai-streaming-message .ai-cursor {
    display: inline-block;
    animation: blink 1s infinite;
    color: #3b82f6;
    margin-left: 2px;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.ai-message {
    animation: fadeIn 0.3s ease-out;
}


/* Убрана анимация с bible-блоков - она вызывала моргание при обновлении innerHTML */

.ai-context-badge {
    animation: fadeIn 0.2s ease-out;
}

/* Smooth transitions */
.ai-assistant-messages {
    scroll-behavior: smooth;
    /* Предотвращаем блокировку скроллинга при взаимодействии с элементами */
    -webkit-user-select: text;
    user-select: text;
}


/* Responsive */
@media (max-width: 768px) {
    .ai-assistant-wrapper {
        padding: 0;
    }
    
    .ai-assistant-page {
        max-width: 100%;
    }
    
    .ai-message-user {
        max-width: 90%;
        margin-top: 0.5rem;
    }
    
    .ai-message-assistant {
        max-width: 100%;
    }
    
    .ai-sidebar {
        width: 100% !important;
        max-width: 100% !important;
        left: 0 !important;
        transform: translateX(0) !important;
    }
    
    .ai-assistant-header h5 {
        font-size: 1rem;
    }
    
    .ai-input-field {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .ai-assistant-input {
        padding: 0.3rem 0.5rem;
    }
    
    .ai-input-actions {
        padding-right: 0.5rem;
        gap: 0.375rem;
    }
    
    .ai-new-chat-btn,
    .ai-response-type-btn {
        font-size: 0.8rem;
        padding: 0.35rem 0.6rem;
    }
    
    .ai-bible-text-block {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
    
    .ai-followup-questions {
        gap: 0.375rem;
    }
    
    .ai-followup-question-btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
    }
    
    /* Дополнительные настройки для мобильных webview */
    .ai-assistant-messages {
        /* Улучшенная поддержка touch-скроллинга на мобильных */
        -webkit-overflow-scrolling: touch;
    }
}

@media (min-width: 769px) {
    .ai-sidebar {
        left: 50% !important;
        max-width: 576px !important;
        transform: translateX(-50%) !important;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .ai-message-user {
        max-width: 80%;
    }
    
    .ai-message-assistant {
        max-width: 100%;
    }
}

@media (min-width: 1025px) {
    .ai-assistant-messages {
        padding: 0.5rem 0.5rem;
    }
    
    .ai-message-user {
        max-width: 75%;
    }
    
    .ai-message-assistant {
        max-width: 100%;
    }
}

/* Popup во время стриминга */
.ai-streaming-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.ai-streaming-popup {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 
                0 10px 10px -5px rgba(0, 0, 0, 0.04),
                0 0 0 1px rgba(59, 130, 246, 0.1);
    max-width: 420px;
    width: 100%;
    padding: 0;
    padding-bottom: 0.5rem;
    overflow: hidden;
    position: relative;
    min-height: 140px;
}

.ai-streaming-popup::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 50%, #3b82f6 100%);
    background-size: 200% 100%;
    animation: ai-popup-gradient-shift 3s ease infinite;
}

@keyframes ai-popup-gradient-shift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.ai-streaming-popup-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 0.75rem 1rem 0.5rem 1rem;
    position: relative;
    gap: 1rem;
}

.ai-streaming-popup-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    position: relative;
    margin: 0 auto;
    padding-top: 1rem;
    padding-bottom: 1.25rem;
}

.ai-streaming-spinner {
    position: relative;
    width: 2rem;
    height: 2rem;
}

.ai-spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: ai-spinner-rotate 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.ai-spinner-ring:nth-child(1) {
    animation-delay: -0.45s;
    border-top-color: #3b82f6;
    opacity: 1;
}

.ai-spinner-ring:nth-child(2) {
    animation-delay: -0.3s;
    border-top-color: #8b5cf6;
    opacity: 0.7;
    width: 85%;
    height: 85%;
    top: 7.5%;
    left: 7.5%;
}

.ai-spinner-ring:nth-child(3) {
    animation-delay: -0.15s;
    border-top-color: #06b6d4;
    opacity: 0.5;
    width: 70%;
    height: 70%;
    top: 15%;
    left: 15%;
}

@keyframes ai-spinner-rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.ai-streaming-popup-close {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
}

.ai-streaming-popup-close:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: #475569;
    transform: scale(1.05);
}

.ai-streaming-popup-close:active {
    transform: scale(0.95);
    background-color: rgba(0, 0, 0, 0.1);
}

.ai-streaming-popup-close i {
    font-size: 0.875rem;
}

.ai-streaming-popup-content {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0 0 0;
    gap: 0.5rem;
    text-align: left;
    flex: 1;
}

.ai-streaming-popup-title {
    color: #1e293b;
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: -0.01em;
}

.ai-streaming-popup-text {
    color: #64748b;
    font-size: 0.9375rem;
    line-height: 1.6;
    font-weight: 400;
}

/* Transitions для попапа */
.ai-popup-enter {
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-popup-enter-start {
    opacity: 0;
    transform: scale(0.9) translateY(-10px);
}

.ai-popup-enter-end {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.ai-popup-leave {
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-popup-leave-start {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.ai-popup-leave-end {
    opacity: 0;
    transform: scale(0.95) translateY(5px);
}

/* Bible Popup Styles */
.ai-bible-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
}

.ai-bible-popup {
    background: #ffffff;
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 
                0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 600px;
    width: 100%;
    height: 70vh;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.ai-bible-popup-header {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.ai-bible-popup-title {
    color: #1e293b;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.5;
    margin: 0;
    flex: 1;
}

.ai-bible-popup-copy-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    transition: color 0.2s, transform 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-bible-popup-copy-btn i {
    font-size: 1.2rem;
}

.ai-bible-popup-copy-btn:hover {
    color: #3b82f6;
    transform: scale(1.1);
}

.ai-bible-popup-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    min-height: 0;
}

.ai-bible-popup-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 0;
}

.ai-bible-popup-text {
    color: #374151;
    font-size: 1rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.ai-bible-popup-text-clickable {
    cursor: pointer;
    user-select: text;
    transition: background-color 0.5s ease;
    border-radius: 0.5rem;
    padding: 0.5rem;
    margin: -0.5rem;
}

.ai-bible-popup-text-clickable:active {
    background-color: #e5e7eb;
}

.ai-bible-popup-error {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    color: #6b7280;
    font-size: 0.875rem;
    line-height: 1.5;
}

.ai-bible-popup-footer {
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.ai-bible-popup-close-btn {
    flex: 1;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 0.75rem;
    transition: all 0.2s ease;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.ai-bible-popup-close-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.ai-bible-popup-close-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

.ai-bible-popup-go-btn {
    width: 3rem;
    /* min-height: 3rem; */
    height: 3rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 0.75rem;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.ai-bible-popup-go-btn:hover:not(.disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.ai-bible-popup-go-btn:active:not(.disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

.ai-bible-popup-go-btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Стили для скроллбара в попапе библии */
.ai-bible-popup-content::-webkit-scrollbar {
    width: 8px;
}

.ai-bible-popup-content::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.ai-bible-popup-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.ai-bible-popup-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}


