:root {
    --primary: #5a2d82; /* Deep Purple */
    --secondary: #f2a900; /* Amber/Orange */
    --bg: #f8f8f8; /* Light Gray Background */
    --surface: #ffffff; /* White Card/Modal Surface */
    --text: #333333; /* Dark Gray Text */
    --text-muted: #666666; /* Medium Gray Text */
    --border-color: #e0e0e0; /* Light Gray Border */
    --border-radius: 8px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --font-family: 'Inter', 'system-ui', sans-serif; /* Modern sans-serif */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
}

/* Basic Reset & Typography */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    color: var(--text);
    background-color: var(--bg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--primary);
    margin-top: 0;
    margin-bottom: var(--spacing-sm);
    font-weight: 700;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }

p {
    margin-bottom: var(--spacing-sm);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--secondary);
}

/* Header & Navigation */
header {
    background-color: var(--primary);
    color: #ffffff;
    padding: var(--spacing-sm) 0;
    box-shadow: var(--box-shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-sm);
}

.logo {
    font-size: 1.8rem;
    font-weight: bold;
    color: #ffffff;
    text-decoration: none;
}

nav ul {
    list-style: none;
    display: flex;
    gap: var(--spacing-md);
}

nav ul li a {
    color: #ffffff;
    font-weight: 500;
    padding: var(--spacing-xs) 0;
    transition: color 0.3s ease, border-bottom 0.3s ease;
}

nav ul li a:hover,
nav ul li a.active {
    color: var(--secondary);
    border-bottom: 2px solid var(--secondary);
}

.cart-icon {
    position: relative;
    cursor: pointer;
    color: #ffffff;
    font-size: 1.5rem;
    padding: var(--spacing-xs);
    border-radius: var(--border-radius);
    transition: background-color 0.3s ease;
}

.cart-icon:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.cart-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: var(--secondary);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: bold;
    border-radius: 50%;
    padding: 3px 7px;
    min-width: 24px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Main Content Layout */
main {
    flex-grow: 1;
    max-width: 1200px;
    margin: var(--spacing-md) auto;
    padding: 0 var(--spacing-sm);
}

.page-section {
    background-color: var(--surface);
    padding: var(--spacing-lg);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin-bottom: var(--spacing-md);
}

/* Hero Section */
.hero {
    background: linear-gradient(rgba(90, 45, 130, 0.85), rgba(90, 45, 130, 0.85)), url('https://placehold.co/1200x400/5a2d82/ffffff?text=Welcome+to+Book+Haven') no-repeat center center/cover;
    color: #ffffff;
    text-align: center;
    padding: var(--spacing-xl) var(--spacing-sm);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

.hero h1 {
    color: #ffffff;
    font-size: 3rem;
    margin-bottom: var(--spacing-sm);
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.hero p {
    font-size: 1.2rem;
    margin-bottom: var(--spacing-lg);
    max-width: 700px;
}

/* Buttons */
.btn {
    background-color: var(--secondary);
    color: var(--primary);
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    text-decoration: none;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    display: inline-block;
    text-align: center;
}

.btn:hover {
    background-color: #e09d00; /* Slightly darker secondary */
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

/* Book Grid */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-md);
    margin-top: var(--spacing-md);
}

.book-card {
    background-color: var(--surface);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: hidden;
    text-align: center;
    padding: var(--spacing-sm);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

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

.book-card img {
    max-width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-sm);
    border: 1px solid var(--border-color);
}

.book-card h3 {
    font-size: 1.2rem;
    margin-bottom: var(--spacing-xs);
    flex-grow: 1;
}

.book-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: var(--spacing-xs);
}

.book-card .price {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: var(--spacing-sm);
    display: block;
}

/* Forms */
.form-group {
    margin-bottom: var(--spacing-sm);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-weight: 500;
    color: var(--text);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group textarea,
.filter-sort-controls input[type="text"],
.filter-sort-controls select {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-sizing: border-box;
    font-family: var(--font-family);
    font-size: 1rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.filter-sort-controls input:focus,
.filter-sort-controls select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(90, 45, 130, 0.2);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

/* Cart Specific Styles */
.cart-items {
    margin-top: var(--spacing-md);
}

.cart-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-color);
}

.cart-item:last-child {
    border-bottom: none;
}

.cart-item img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.cart-item-details {
    flex-grow: 1;
}

.cart-item-details h4 {
    margin: 0 0 0.2rem 0;
    font-size: 1.1rem;
    color: var(--primary);
}

.cart-item-details p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.cart-item-quantity {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.cart-item-quantity button {
    background-color: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cart-item-quantity button:hover {
    background-color: #4a246b; /* Darker primary */
}

.cart-item-quantity span {
    min-width: 20px;
    text-align: center;
    font-weight: 500;
}

.cart-item .remove-btn {
    background-color: #dc3545; /* Red for danger */
    color: #ffffff;
    padding: 0.5rem 0.8rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.3s ease;
}

.cart-item .remove-btn:hover {
    background-color: #c82333; /* Darker red */
}

.cart-summary {
    text-align: right;
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--border-color);
}

.cart-summary h3 {
    font-size: 1.5rem;
    color: var(--primary);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.empty-message {
    text-align: center;
    padding: var(--spacing-lg);
    color: var(--text-muted);
    font-size: 1.1rem;
}

.success-message {
    color: #28a745; /* Green */
    font-weight: bold;
    margin-top: var(--spacing-sm);
}

.error-message {
    color: #dc3545; /* Red */
    font-weight: bold;
    margin-top: var(--spacing-sm);
}

/* Modal */
.modal {
    display: flex; /* Use flex for centering */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6); /* Darker overlay */
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.open {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--surface);
    margin: auto;
    padding: var(--spacing-lg);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    width: 90%;
    max-width: 500px;
    position: relative;
    transform: translateY(-20px);
    transition: transform 0.3s ease;
}

.modal.open .modal-content {
    transform: translateY(0);
}

.close-button {
    color: var(--text-muted);
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close-button:hover,
.close-button:focus {
    color: var(--primary);
}

/* Filter and Sort Controls */
.filter-sort-controls {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    flex-wrap: wrap;
}

.filter-sort-controls input,
.filter-sort-controls select {
    flex: 1;
    min-width: 150px;
}

/* Footer */
footer {
    background-color: var(--primary);
    color: #ffffff;
    text-align: center;
    padding: var(--spacing-md) var(--spacing-sm);
    margin-top: var(--spacing-xl);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
}

/* Loading Skeletons */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes loading {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.book-card-skeleton {
    background-color: var(--surface);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: var(--spacing-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
}
.book-card-skeleton div:nth-child(1) { /* Image */
    width: 100%;
    height: 200px;
    background: var(--border-color);
    border-radius: var(--border-radius);
}
.book-card-skeleton div:nth-child(2) { /* Title */
    width: 80%;
    height: 20px;
    background: var(--border-color);
}
.book-card-skeleton div:nth-child(3) { /* Price */
    width: 50%;
    height: 20px;
    background: var(--border-color);
}

.text-skeleton {
    height: 18px;
    margin-bottom: 10px;
    background: var(--border-color);
    width: 100%;
}
.text-skeleton.short { width: 70%; }
.text-skeleton.medium { width: 85%; }

/* Responsive Adjustments */
@media (max-width: 768px) {
    h1 { font-size: 2rem; }
    h2 { font-size: 1.75rem; }
    h3 { font-size: 1.25rem; }

    nav {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    nav ul {
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--spacing-sm);
    }

    .hero {
        padding: var(--spacing-lg) var(--spacing-sm);
    }

    .hero h1 {
        font-size: 2.5rem;
    }

    .book-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

    .book-card {
        padding: var(--spacing-xs);
    }

    .book-card img {
        height: 150px;
    }

    .filter-sort-controls {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 1.5rem;
    }

    nav ul li a {
        font-size: 0.9rem;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .hero p {
        font-size: 1rem;
    }

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .book-grid {
        grid-template-columns: 1fr;
    }

    .cart-item {
        flex-wrap: wrap;
        justify-content: center;
        text-align: center;
    }

    .cart-item img {
        width: 60px;
        height: 60px;
    }

    .cart-item-details, .cart-item-quantity {
        flex-basis: 100%;
        margin-top: var(--spacing-xs);
    }
    .cart-item-quantity {
        justify-content: center;
    }
}
