:root {
    --primary-color: #BFDBFE; /* Biru muda */
    --primary-dark: #60A5FA; /* Biru sedikit gelap */
    --primary-text: #1E3A8A; /* Biru sangat gelap untuk kontras teks */
    --bg-color: #F8FAFC; /* Latar belakang aplikasi web */
    --card-bg: #FFFFFF;
    --chat-bg: #FFFFFF;
    --user-bubble: #DBEAFE;
    --bot-bubble: #F3F4F6;
    --text-color: #334155;
    --text-muted: #64748B;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 1rem;
    --radius-lg: 1.5rem;
}

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

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Utama */
.main-header {
    background-color: white;
    box-shadow: var(--shadow-sm);
    padding: 1.25rem 2rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-content i {
    font-size: 1.75rem;
    color: var(--primary-dark);
}

.header-content h1 {
    font-size: 1.5rem;
    color: var(--primary-text);
    font-weight: 800;
}

/* Kontainer Utama */
.app-main {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
}

/* View Sections */
.view-section {
    display: none;
    animation: fadeIn 0.4s ease;
}

.view-section.active {
    display: block;
}

/* Tampilan Beranda */
.home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.home-header h2 {
    color: var(--primary-text);
    font-size: 1.75rem;
}

.search-bar {
    display: flex;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid #E2E8F0;
}

.search-bar input {
    border: none;
    padding: 0.75rem 1.25rem;
    outline: none;
    font-family: inherit;
    font-size: 1rem;
    width: 250px;
}

.search-bar button {
    background: var(--primary-color);
    border: none;
    padding: 0 1.25rem;
    color: var(--primary-text);
    cursor: pointer;
    transition: background 0.2s;
}

.search-bar button:hover {
    background: var(--primary-dark);
    color: white;
}

/* Loading */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--text-muted);
}
.loading-container.hidden { display: none; }
.spinner {
    border: 4px solid rgba(0,0,0,0.1);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border-left-color: var(--primary-dark);
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Grid Buku */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.book-card {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.book-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    background-color: #E2E8F0;
}

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

.book-title {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    color: var(--primary-text);
    /* Truncate text */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.book-read-btn {
    margin-top: auto;
    background-color: var(--primary-color);
    color: var(--primary-text);
    border: none;
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-weight: 700;
    transition: background 0.2s;
}
.book-card:hover .book-read-btn {
    background-color: var(--primary-dark);
    color: white;
}

/* Tampilan Detail Buku */
.back-btn {
    background: none;
    border: none;
    color: var(--primary-text);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 1.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: transform 0.2s;
    font-family: inherit;
}
.back-btn:hover {
    transform: translateX(-5px);
}

.book-detail-container {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 2rem;
    display: flex;
    gap: 2.5rem;
    align-items: flex-start;
}

.detail-cover {
    width: 250px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.detail-info {
    flex: 1;
}

.detail-title {
    font-size: 2.25rem;
    color: var(--primary-text);
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.detail-author {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.detail-desc {
    line-height: 1.7;
    margin-bottom: 2rem;
    color: var(--text-color);
}

.detail-actions {
    display: flex;
    gap: 1rem;
}

.action-btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 700;
    text-decoration: none;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
}

.action-btn.primary {
    background-color: var(--primary-dark);
    color: white;
}

.action-btn.secondary {
    background-color: var(--primary-color);
    color: var(--primary-text);
}

.action-btn:hover {
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .book-detail-container {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    .detail-actions {
        justify-content: center;
    }
}

/* Floating Chatbot Widget */
.chat-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--primary-dark);
    color: white;
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
}

.chat-window {
    width: 380px;
    height: 550px;
    max-height: calc(100vh - 120px);
    background-color: var(--chat-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
}

.chat-window.hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 480px) {
    .chat-widget {
        bottom: 1rem;
        right: 1rem;
    }
    .chat-window {
        width: calc(100vw - 2rem);
        height: calc(100vh - 100px);
    }
}

/* Chat Header */
.chat-header {
    background-color: var(--primary-color);
    color: var(--primary-text);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 800;
    font-size: 1.1rem;
}

.chat-header-actions button {
    background: none;
    border: none;
    color: var(--primary-text);
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: 0.5rem;
    transition: opacity 0.2s;
}
.chat-header-actions button:hover { opacity: 0.7; }

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
    background-color: #FAFAF9;
}

.message-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    animation: fadeIn 0.3s ease-in-out;
}

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

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.bot-avatar { background-color: var(--primary-color); color: var(--primary-text); }
.user-avatar { background-color: var(--primary-dark); color: white; }

.bubble {
    max-width: 80%;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.bot-bubble {
    background-color: var(--bot-bubble);
    border-radius: 1rem 1rem 1rem 0.25rem;
    color: var(--text-color);
}

.user-bubble {
    background-color: var(--user-bubble);
    border-radius: 1rem 1rem 0.25rem 1rem;
    color: var(--primary-text);
}

/* Markdown styling inside bubble */
.bot-bubble p:not(:last-child) { margin-bottom: 0.5rem; }
.bot-bubble ul, .bot-bubble ol { margin-left: 1.2rem; margin-bottom: 0.5rem; }
.bot-bubble code {
    background-color: rgba(0,0,0,0.05);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
}

.shortcuts {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.shortcut-btn {
    background-color: white;
    border: 1px solid var(--primary-color);
    color: var(--primary-text);
    padding: 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    text-align: left;
    transition: background 0.2s;
}
.shortcut-btn:hover { background-color: var(--primary-color); }

.typing-indicator {
    padding: 0 1rem 1rem 1rem;
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}
.typing-indicator.hidden { display: none; }
.typing-dots { display: flex; gap: 0.2rem; padding: 0.5rem 0; }
.typing-dots span {
    width: 5px; height: 5px; background-color: #9CA3AF; border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

/* Chat Form */
.chat-form {
    padding: 1rem;
    background-color: white;
    border-top: 1px solid #E5E7EB;
    display: flex;
    gap: 0.5rem;
}

#user-input {
    flex: 1;
    padding: 0.6rem 1rem;
    border: 1px solid #E5E7EB;
    border-radius: 1.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}
#user-input:focus { border-color: var(--primary-dark); }

#send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: var(--primary-dark);
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s;
    flex-shrink: 0;
}
#send-btn:hover { background-color: #3B82F6; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }
