/* Pustakawan AI - Chat Widget Styles */

#pustakawan-ai-widget {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #1f2937;
}

/* Floating Button (above SLiMS chat btn & bottom nav) */
#pai-btn {
    position: fixed;
    bottom: 150px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    border: none;
    background: var(--pai-primary, #073b63);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(7, 59, 99, 0.4);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}
#pai-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(7, 59, 99, 0.45);
}
#pai-btn:active {
    transform: scale(0.96);
}
#pai-btn svg {
    width: 26px;
    height: 26px;
    pointer-events: none;
}

/* Chat Panel */
#pai-panel {
    position: fixed;
    bottom: 218px;
    right: 24px;
    width: 380px;
    max-height: min(520px, calc(100vh - 240px));
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 99999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    transition: opacity 0.25s ease, transform 0.25s ease;
}
#pai-panel.pai-open {
    display: flex;
}
#pai-panel.pai-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Header */
.pai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--pai-primary, #073b63), var(--pai-primary-dark, #052a47));
    color: #fff;
    flex-shrink: 0;
}
.pai-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.pai-header-icon {
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}
.pai-header-text h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}
.pai-header-text small {
    opacity: 0.85;
    font-size: 11px;
}
.pai-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pai-close:hover {
    opacity: 1;
}
.pai-close svg {
    width: 20px;
    height: 20px;
}

/* Messages Area */
.pai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
}
.pai-messages::-webkit-scrollbar {
    width: 5px;
}
.pai-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* Message Bubbles */
.pai-msg {
    max-width: 85%;
    padding: 10px 14px;
    margin-bottom: 10px;
    border-radius: 16px;
    word-wrap: break-word;
    animation: paiFadeIn 0.3s ease;
}
.pai-msg-user {
    background: var(--pai-user-bg, #eef2ff);
    color: #312e81;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.pai-msg-model {
    background: #f3f4f6;
    color: #1f2937;
    margin-right: auto;
    border-bottom-left-radius: 4px;
}
.pai-msg strong { font-weight: 600; }
.pai-msg em { font-style: italic; }
.pai-msg code {
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}
.pai-msg a {
    color: var(--pai-primary, #073b63);
    text-decoration: underline;
}

/* Error Message */
.pai-msg-error {
    background: #fef2f2;
    color: #991b1b;
    margin: 0 auto 10px;
    text-align: center;
    font-size: 13px;
    border-radius: 8px;
    max-width: 90%;
}

/* Typing Indicator */
.pai-typing {
    display: none;
    padding: 0 16px 12px;
}
.pai-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f3f4f6;
    padding: 10px 14px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}
.pai-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: paiDot 1.4s infinite;
}
.pai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.pai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Input Area */
.pai-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
    background: #fff;
}
#pai-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    background: #f9fafb;
    color: #1f2937;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}
#pai-input:focus {
    border-color: var(--pai-primary, #073b63);
    box-shadow: 0 0 0 3px rgba(7, 59, 99, 0.15);
    background: #fff;
}
#pai-input::placeholder {
    color: #9ca3af;
}
#pai-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--pai-primary, #073b63);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}
#pai-send:hover {
    filter: brightness(1.1);
}
#pai-send:active {
    transform: scale(0.92);
}
#pai-send:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}
#pai-send svg {
    width: 18px;
    height: 18px;
    pointer-events: none;
}

/* Footer */
.pai-footer {
    text-align: center;
    padding: 4px 16px 8px;
    font-size: 10px;
    color: #9ca3af;
    background: #fff;
    flex-shrink: 0;
}

/* Quick Action Chips */
.pai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0 10px;
    animation: paiFadeIn 0.3s ease;
}
.pai-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    background: #fff;
    color: #374151;
    font-size: 12.5px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1.3;
    white-space: nowrap;
}
.pai-chip:hover {
    background: var(--pai-primary, #073b63);
    color: #fff;
    border-color: var(--pai-primary, #073b63);
}
.pai-chip:active {
    transform: scale(0.95);
}

/* Confidence Indicator */
.pai-confidence {
    font-size: 11px;
    color: #6b7280;
    padding: 2px 0 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    animation: paiFadeIn 0.3s ease;
}
.pai-confidence::before {
    content: '\2139';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    font-size: 9px;
    font-weight: 700;
    flex-shrink: 0;
}

/* Inline OPAC Links */
.pai-opac-link {
    color: var(--pai-primary, #073b63);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px dashed var(--pai-primary, #073b63);
    transition: border-color 0.2s, color 0.2s;
}
.pai-opac-link:hover {
    color: #0369a1;
    border-bottom-style: solid;
}

/* Animations */
@keyframes paiFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes paiDot {
    0%, 80%, 100% { transform: scale(0.4); opacity: 0.5; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* Responsive */
@media (max-width: 480px) {
    #pai-panel {
        width: calc(100% - 16px);
        height: calc(100vh - 220px);
        right: 8px;
        bottom: 208px;
        border-radius: 12px;
    }
    #pai-btn {
        bottom: 140px;
        right: 16px;
    }
}
