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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f4f4f4;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem 0;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.cart-button {
    position: absolute;
    top: 1rem;
    right: 2rem;
    padding: 0.8rem 1.5rem;
    background: white;
    color: #667eea;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.cart-button:hover {
    transform: scale(1.05);
}

main {
    padding: 2rem 0;
}

.search-section {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

#searchInput {
    flex: 1;
    padding: 0.8rem;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
}

#categoryFilter {
    padding: 0.8rem;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    min-width: 200px;
}

.search-section button {
    padding: 0.8rem 2rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
}

.search-section button:hover {
    background: #5568d3;
}

.stats {
    margin-bottom: 1rem;
    color: #666;
}

.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    min-height: 520px; /* Prevent collapse during loading */
}

/* Prevent layout shift during image loading */
.books-grid img {
    content-visibility: auto;
}

.book-card {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: transform 0.3s;
    cursor: pointer;
    height: 520px; /* Fixed height to prevent jumping */
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
}

.book-cover {
    width: 100%;
    height: 300px;
    min-height: 300px; /* Prevent collapse */
    max-height: 300px; /* Prevent expansion */
    object-fit: cover;
    background: #f0f0f0;
    flex-shrink: 0; /* Prevent shrinking */
    display: block; /* Remove inline spacing */
    aspect-ratio: 5/6; /* Maintain aspect ratio */
}

.book-info {
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex shrinking */
}

.book-title {
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 2.4em; /* Fixed height for 2 lines */
    line-height: 1.2em;
}

.book-author {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.book-category {
    display: inline-block;
    background: #e0e7ff;
    color: #667eea;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.book-price {
    font-size: 1.2rem;
    font-weight: bold;
    color: #667eea;
}

.add-to-cart-btn {
    width: 100%;
    padding: 0.8rem;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 0.5rem;
}

.add-to-cart-btn:hover {
    background: #059669;
}

.cart-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid #eee;
    align-items: center;
}

.cart-item img {
    width: 80px;
    height: 100px;
    object-fit: cover;
    border-radius: 5px;
}

.cart-item-info {
    flex: 1;
}

.cart-item-title {
    font-weight: bold;
    margin-bottom: 0.3rem;
}

.cart-item-price {
    color: #667eea;
    font-weight: bold;
}

.remove-btn {
    padding: 0.5rem 1rem;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.remove-btn:hover {
    background: #dc2626;
}

.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 2rem 0;
}

.pagination button {
    padding: 0.5rem 1rem;
    background: white;
    border: 2px solid #667eea;
    color: #667eea;
    border-radius: 5px;
    cursor: pointer;
}

.pagination button:hover {
    background: #667eea;
    color: white;
}

.pagination button.active {
    background: #667eea;
    color: white;
}

.request-section {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin: 2rem 0;
}

.request-section button {
    margin-top: 1rem;
    padding: 1rem 2rem;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
}

.request-section button:hover {
    background: #059669;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    background: white;
    margin: 5% auto;
    padding: 2rem;
    border-radius: 10px;
    max-width: 600px;
    position: relative;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: #999;
}

.close:hover {
    color: #333;
}

#requestForm input,
#requestForm textarea {
    width: 100%;
    padding: 0.8rem;
    margin: 0.5rem 0;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
}

#requestForm button {
    width: 100%;
    padding: 1rem;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    margin-top: 1rem;
}

#requestForm button:hover {
    background: #059669;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: #666;
}

footer {
    background: #333;
    color: white;
    text-align: center;
    padding: 2rem 0;
    margin-top: 3rem;
}

footer a {
    color: #667eea;
    text-decoration: none;
    margin-left: 1rem;
}

footer a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .search-section {
        flex-direction: column;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}
