/* OPAC AI Live Chat Variables */
:root {
    --chat-primary: var(--zavier-primary, #0052cc);
    --chat-primary-hover: var(--zavier-primary-dark, #0747a6);
    --chat-bg: #ffffff;
    --chat-panel-bg: #f8f9fa;
    --chat-border: #e1e4e8;
    --chat-text: #333333;
    --chat-text-muted: #6c757d;
    --chat-user-bubble: #e3f2fd;
    --chat-ai-bubble: #ffffff;
    --chat-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    --chat-radius: 12px;
}

/* Toggle Button */
.ai-chat-toggle {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--chat-primary);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.4);
    cursor: pointer;
    z-index: 1040;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.ai-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 82, 204, 0.5);
}

.ai-chat-icon {
    width: 28px;
    height: 28px;
}

.ai-chat-badge {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background-color: #dc3545;
    border: 2px solid white;
    border-radius: 50%;
}

/* Chat Panel */
.ai-chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: calc(100vh - 110px);
    max-height: 800px;
    background-color: var(--chat-panel-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    z-index: 1060;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--chat-border);
    transition: opacity 0.3s, transform 0.3s;
    transform-origin: bottom right;
}

@media (max-width: 768px) {
    .ai-chat-panel {
        width: auto !important;
        right: 16px !important;
        left: 16px !important;
        top: 90px !important;
        bottom: 90px !important;
        height: auto !important;
        max-height: none !important;
    }
}

/* Header */
.ai-chat-header {
    background-color: var(--chat-primary);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-avatar {
    width: 40px;
    height: 40px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-avatar i {
    width: 24px;
    height: 24px;
}

.online-indicator {
    width: 8px;
    height: 8px;
    fill: #28a745;
    color: #28a745;
}

.ai-chat-close {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.8;
}

.ai-chat-close:hover {
    opacity: 1;
}

.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-disclaimer {
    margin-top: 4px;
    text-align: center;
    color: var(--chat-text-muted);
    font-size: 0.7rem;
}

.ai-book-list {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.ai-chat-link {
    color: var(--chat-primary);
    text-decoration: underline;
    font-weight: 600;
}

.ai-chat-whatsapp-link {
    display: inline-flex;
    align-items: center;
    margin: 5px 4px 2px 0;
    padding: 8px 12px;
    border-radius: 9px;
    background: #087e56;
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.ai-chat-whatsapp-link:hover,
.ai-chat-whatsapp-link:focus-visible { background: #066b49; color: #fff; }

.ai-chat-map-link {
    display: inline-flex;
    align-items: center;
    margin: 5px 4px 2px 0;
    padding: 8px 12px;
    border-radius: 9px;
    background: var(--chat-primary);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.ai-chat-map-link:hover,
.ai-chat-map-link:focus-visible { color: #fff; filter: brightness(.9); }

/* Body */
.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Messages */
.ai-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.ai-message.user {
    align-self: flex-end;
}

.ai-message.assistant {
    align-self: flex-start;
}

.ai-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-break: break-word;
}

.user .ai-bubble {
    background-color: var(--chat-user-bubble);
    color: var(--chat-text);
    border-bottom-right-radius: 4px;
}

.assistant .ai-bubble {
    background-color: var(--chat-ai-bubble);
    color: var(--chat-text);
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 4px;
}

.ai-message-time {
    font-size: 0.7rem;
    color: var(--chat-text-muted);
    margin-top: 4px;
    align-self: flex-end;
}

/* Quick Prompts */
.ai-quick-prompts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.ai-quick-btn {
    background-color: white;
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--chat-primary);
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-quick-btn:hover {
    background-color: var(--chat-user-bubble);
    border-color: var(--chat-primary);
}

/* Book Card */
.ai-book-card {
    display: flex;
    gap: 12px;
    background-color: white;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
    text-decoration: none;
    color: var(--chat-text);
    transition: box-shadow 0.2s;
}

.ai-book-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    color: var(--chat-text);
}

.ai-book-cover {
    width: 60px;
    height: 85px;
    object-fit: cover;
    border-radius: 4px;
    background-color: #eee;
}

.ai-book-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.ai-book-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
    line-height: 1.2;
}

.ai-book-author {
    font-size: 0.8rem;
    color: var(--chat-text-muted);
    margin-bottom: 8px;
}

.ai-book-status {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    background-color: #e8f5e9;
    color: #2e7d32;
    display: inline-block;
    align-self: flex-start;
}

/* Typing Indicator */
.ai-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px !important;
    align-items: center;
    width: fit-content;
}

.ai-typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: #90a4ae;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.ai-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Footer & Form */
.ai-chat-footer {
    background-color: white;
    padding: 12px;
    border-top: 1px solid var(--chat-border);
}

.ai-chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ai-chat-input {
    resize: none;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 0.9rem;
    max-height: 100px;
    overflow-y: auto;
}

.ai-chat-input:focus {
    box-shadow: none;
    border-color: var(--chat-primary);
}

.ai-chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: var(--chat-primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.ai-chat-send:disabled {
    background-color: #b0bec5;
    cursor: not-allowed;
}

.ai-chat-send i {
    width: 20px;
    height: 20px;
}

/* Rating Modal */
.ai-rating-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.ai-rating-content {
    background-color: white;
    padding: 32px 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    transform: translateY(0);
    animation: modalSlideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-stars {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 16px 0 24px;
}

.ai-stars [data-rating] {
    width: 36px;
    height: 36px;
    color: #ffd54f;
    cursor: pointer;
    fill: transparent;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), fill 0.2s;
}

.ai-stars [data-rating]:hover {
    transform: scale(1.2);
}

.ai-stars [data-rating].active {
    fill: #ffd54f;
    animation: starPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes starPop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.35);
    }

    100% {
        transform: scale(1);
    }
}

/* Mobile Features Container */
.mobile-features-container {
    position: fixed;
    bottom: 85px;
    right: 20px;
    z-index: 1050;
}

.mobile-features-fab {
    background-color: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    font-size: 12px;
    font-weight: 600;
}

.mobile-features-fab i {
    width: 24px;
    height: 24px;
    margin-bottom: 2px;
}

.mobile-features-popup {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 280px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    padding: 12px 0;
    display: flex;
    flex-direction: column;
}

.feature-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: none;
    border: none;
    text-align: left;
    width: 100%;
    cursor: pointer;
    transition: background 0.2s;
}

.feature-item:hover {
    background: #f8f9fa;
}

.feature-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
}

.feature-icon i {
    width: 18px;
    height: 18px;
}

.feature-text strong {
    display: block;
    color: #333;
    font-size: 14px;
    margin-bottom: 2px;
}

.feature-text p {
    margin: 0;
    color: #6c757d;
    font-size: 11px;
    line-height: 1.3;
}

/* Responsiveness adjustments for WCAG and AI Chat floating elements */
@media (max-width: 768px) {
    .ai-chat-toggle {
        display: none !important;
    }

    .wcag-fab {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .mobile-features-container {
        display: none !important;
    }

    /* Desktop edge-attached floating buttons */
    .wcag-fab,
    .ai-chat-toggle {
        position: fixed !important;
        right: 0 !important;
        left: auto !important;
        bottom: auto !important;
        border-radius: 8px 0 0 8px !important;
        width: 48px !important;
        height: 48px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        overflow: hidden !important;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        white-space: nowrap !important;
    }

    .wcag-fab {
        top: calc(50% - 28px) !important;
        transform: translateY(-50%) !important;
        background-color: #00a65a !important;
    }

    .ai-chat-toggle {
        top: calc(50% + 28px) !important;
        transform: translateY(-50%) !important;
    }

    /* Icon positioning */
    .wcag-fab svg,
    .ai-chat-icon {
        flex-shrink: 0 !important;
        width: 24px !important;
        height: 24px !important;
        margin-left: 12px !important;
        margin-right: 12px !important;
    }

    /* Remove default transform scale on hover, but keep translateY */
    .wcag-fab:hover,
    .ai-chat-toggle:hover {
        transform: translateY(-50%) scale(1) !important;
    }

    /* Hover expansion widths */
    .wcag-fab:hover {
        width: 140px !important;
    }

    .ai-chat-toggle:hover {
        width: 180px !important;
    }

    /* Text using pseudo-elements */
    .wcag-fab::after {
        content: "Aksesibilitas";
        font-family: inherit;
        font-size: 14px;
        font-weight: 500;
        color: white;
        opacity: 0;
        transition: opacity 0.2s ease;
        transition-delay: 0s;
    }

    .ai-chat-toggle::after {
        content: "Asisten Pustakawan";
        font-family: inherit;
        font-size: 14px;
        font-weight: 500;
        color: white;
        opacity: 0;
        transition: opacity 0.2s ease;
        transition-delay: 0s;
    }

    .wcag-fab:hover::after,
    .ai-chat-toggle:hover::after {
        opacity: 1;
        transition-delay: 0.1s;
        /* delay text appearance slightly until expanded */
    }

    /* Adjust badge for AI chat so it doesn't break layout */
    .ai-chat-badge {
        left: 28px !important;
        right: auto !important;
        top: 6px !important;
        z-index: 2 !important;
    }
}
.ai-book-reason { margin-top: .35rem; font-size: .78rem; color: #475569; line-height: 1.35; }
.ai-recommendation-feedback { display: flex; flex-wrap: wrap; gap: .4rem; margin: .35rem 0 .8rem 2.5rem; }
.ai-recommendation-feedback-btn { border: 1px solid #cbd5e1; background: #fff; color: #334155; border-radius: 999px; padding: .35rem .7rem; font-size: .78rem; cursor: pointer; }
.ai-recommendation-feedback-btn:hover, .ai-recommendation-feedback-btn.active { border-color: #2563eb; background: #eff6ff; color: #1d4ed8; }
