/**
 * Bookish AI Assistant Styles
 * Стилі в духі сайту bookish.kiev.ua
 * Колірна схема: #be003c (primary), #2b2b2b (text)
 */

.bookish-ai-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: "Open Sans", Arial, sans-serif;
}

/* Кнопка перемикання */
.ai-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #be003c;
    border: none;
    box-shadow: 0 4px 12px rgba(190, 0, 60, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s ease;
    position: relative;
}

.ai-toggle:hover {
    background: #a00034;
    box-shadow: 0 6px 16px rgba(190, 0, 60, 0.4);
}

.ai-toggle:active {
    transform: scale(0.95);
}

.ai-toggle svg {
    width: 28px;
    height: 28px;
}

/* Індикатор онлайн статусу */
.pulse-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 12px;
    height: 12px;
    background: #4ade80;
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse 2s ease-in-out infinite;
}

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

/* Панель чату */
.ai-chat-panel {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    border: 1px solid #e0e0e0;
}

.ai-chat-panel.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Заголовок */
.ai-header {
    background: linear-gradient(135deg, #be003c 0%, #a00034 100%);
    color: white;
    padding: 16px;
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.ai-info {
    flex: 1;
}

.ai-info h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.ai-status {
    font-size: 12px;
    opacity: 0.85;
    font-weight: 400;
}

.ai-clear-history {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    margin-right: 8px;
}

.ai-clear-history:hover {
    background: rgba(255, 255, 255, 0.25);
}

.ai-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    color: white;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.ai-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Повідомлення */
.ai-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f9f9f9;
}

.ai-message {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    animation: messageSlide 0.25s ease;
}

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

.ai-message-avatar {
    width: 32px;
    height: 32px;
    background: #be003c;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
    letter-spacing: -0.5px;
}

.ai-message-content {
    background: white;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    max-width: 75%;
    border: 1px solid #f0f0f0;
}

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

.ai-message-user .ai-message-content {
    background: #be003c;
    color: white;
    margin-left: auto;
    border-color: transparent;
}

.ai-message-content p {
    margin: 0 0 8px 0;
    font-size: 14px;
    line-height: 1.5;
}

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

.ai-message-content ul {
    margin: 8px 0;
    padding-left: 18px;
}

.ai-message-content li {
    margin: 4px 0;
    font-size: 14px;
    line-height: 1.5;
}

.ai-book-link {
    color: #be003c;
    text-decoration: none;
    font-weight: 600;
    display: inline-block;
    margin: 4px 0;
    transition: color 0.2s ease;
}

.ai-book-link:hover {
    color: #a00034;
    text-decoration: underline;
}

.ai-message-user .ai-book-link {
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.5);
}

.ai-message-user .ai-book-link:hover {
    border-bottom-color: white;
}

/* Підказки */
.ai-suggestions {
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: white;
    border-top: 1px solid #e5e5e5;
}

.ai-suggestion-btn {
    padding: 7px 14px;
    border: 1px solid #d9d9dc;
    background: white;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    color: #2b2b2b;
}

.ai-suggestion-btn:hover {
    background: #f9f9f9;
    border-color: #be003c;
    color: #be003c;
}

/* Кнопки дій AI (action buttons) */
.ai-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
    margin: 0 16px 12px;
    background: #f5f5f5;
    border-radius: 8px;
}

.ai-action-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #be003c 0%, #d41650 100%);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(190, 0, 60, 0.2);
    min-height: 44px;
}

.ai-action-button:hover:not(:disabled) {
    background: linear-gradient(135deg, #a00034 0%, #be003c 100%);
    box-shadow: 0 4px 12px rgba(190, 0, 60, 0.3);
    transform: translateY(-1px);
}

.ai-action-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(190, 0, 60, 0.3);
}

.ai-action-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.ai-action-button.completed {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.2);
}

.ai-action-button.error {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

.ai-action-icon {
    font-size: 16px;
    line-height: 1;
}

.ai-action-loading {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Поле введення */
.ai-input-wrapper {
    display: flex;
    gap: 8px;
    padding: 16px;
    background: white;
    border-radius: 0 0 8px 8px;
    border-top: 1px solid #e5e5e5;
}

.ai-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d9d9dc;
    border-radius: 6px;
    font-size: 14px;
    font-family: "Open Sans", Arial, sans-serif;
    resize: none;
    outline: none;
    transition: border 0.2s ease;
    color: #2b2b2b;
}

.ai-input:focus {
    border-color: #be003c;
}

.ai-input::placeholder {
    color: #999;
}

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

.ai-send:hover {
    background: #a00034;
}

.ai-send:active {
    transform: scale(0.95);
}

/* Індикатор набору */
.ai-typing {
    padding: 12px 16px;
    display: flex;
    gap: 5px;
    align-items: center;
    background: #f9f9f9;
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s ease-in-out infinite;
}

.ai-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { 
        transform: translateY(0); 
        opacity: 1;
    }
    30% { 
        transform: translateY(-6px); 
        opacity: 0.7;
    }
}

/* Мобільна адаптація - fullscreen messenger style */
@media (max-width: 768px) {
    /* Виправляємо viewport щоб не дергався */
    body.ai-panel-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
    
    .bookish-ai-widget {
        bottom: 20px;
        right: 20px;
    }
    
    .ai-toggle {
        width: 56px;
        height: 56px;
        box-shadow: 0 4px 20px rgba(190, 0, 60, 0.4);
    }
    
    /* Overlay затемнення */
    .ai-chat-panel::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: -1;
    }
    
    .ai-chat-panel.active::before {
        opacity: 1;
        pointer-events: all;
    }
    
    /* Fullscreen панель */
    .ai-chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        transform: translateY(100%);
        z-index: 100000;
        border: none;
    }
    
    .ai-chat-panel.active {
        transform: translateY(0);
    }
    
    /* Заголовок з тінню */
    .ai-header {
        border-radius: 0;
        padding: 15px 20px;
        min-height: 64px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    /* Збільшуємо аватар */
    .ai-avatar {
        width: 42px;
        height: 42px;
        font-size: 18px;
    }
    
    /* Повідомлення з більшими відступами */
    .ai-messages {
        padding: 20px 16px;
        flex: 1;
    }
    
    .ai-message {
        margin-bottom: 20px;
    }
    
    .ai-message-content {
        max-width: 85%;
        font-size: 15px;
        line-height: 1.5;
        padding: 12px 16px;
    }
    
    .ai-message-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    /* Швидкі відповіді */
    .ai-suggestions {
        padding: 12px 16px;
        gap: 10px;
    }
    
    .ai-suggestion-btn {
        padding: 10px 18px;
        font-size: 14px;
    }
    
    /* Кнопки дій (actions) */
    .ai-actions {
        margin: 0 16px 16px;
        padding: 12px;
        gap: 12px;
    }
    
    .ai-action-button {
        width: 100%; /* На мобільних кнопки на всю ширину */
        justify-content: center;
        padding: 12px 20px;
        font-size: 15px;
        min-height: 48px; /* Ще більше для зручності */
    }
    
    .ai-action-icon {
        font-size: 18px;
    }
    
    /* Поле вводу */
    .ai-input-wrapper {
        padding: 12px 16px 20px;
        background: #ffffff;
        border-top: 1px solid #e5e5e5;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    }
    
    .ai-input {
        font-size: 16px; /* Виправляє zoom на iOS */
        padding: 12px 50px 12px 16px;
        min-height: 44px; /* Touch-friendly */
        max-height: 120px;
    }
    
    .ai-send {
        width: 44px;
        height: 44px;
        right: 20px;
    }
    
    /* Кнопка закриття */
    .ai-close {
        width: 40px;
        height: 40px;
        font-size: 28px;
    }
    
    /* Кнопка очистки */
    .ai-clear-history {
        width: 40px;
        height: 40px;
    }
    
    /* Typing indicator */
    .ai-typing {
        padding: 12px 16px;
    }
}

/* Для дуже маленьких екранів */
@media (max-width: 360px) {
    .ai-message-content {
        max-width: 90%;
        font-size: 14px;
    }
    
    .ai-header {
        padding: 12px 16px;
    }
    
    .ai-info h3 {
        font-size: 16px;
    }
    
    .ai-status {
        font-size: 12px;
    }
}

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

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

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

.ai-messages::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}
