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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #6b7280;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

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

/* Header */
header {
    text-align: center;
    padding: 40px 0;
}

header h1 {
    font-size: 2.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Search Section */
.search-section {
    margin-bottom: 30px;
}

.search-box {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 24px;
}

.search-input-wrapper {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.search-input-wrapper input {
    flex: 1;
    padding: 14px 18px;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.2s;
}

.search-input-wrapper input:focus {
    border-color: var(--primary-color);
}

.search-options {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.search-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.search-options select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--surface);
    cursor: pointer;
}

/* Buttons */
.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--background);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: underline;
    margin-left: auto;
}

.btn-link:hover {
    color: var(--primary-hover);
}

.btn-remove {
    background: none;
    border: none;
    color: #ef4444;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

/* Advanced Search */
.advanced-search {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
}

.advanced-search h3 {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.advanced-field-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.advanced-field-row select,
.advanced-field-row input {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.advanced-field-row .adv-field {
    min-width: 150px;
}

.advanced-field-row .adv-value {
    flex: 1;
    min-width: 200px;
}

.advanced-field-row .adv-logic {
    min-width: 80px;
}

.advanced-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

/* Results */
.results-section {
    min-height: 200px;
}

.results-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 12px;
}

#pageInfo {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.book-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.book-card h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-card .author {
    color: var(--primary-color);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.book-card .meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.book-card .isbn {
    font-family: monospace;
    background: var(--background);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    display: inline-block;
    margin-top: 8px;
}

.book-card .price {
    color: #059669;
    font-weight: 600;
    margin-top: 8px;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* No Results / Error */
.no-results,
.error {
    text-align: center;
    padding: 60px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.error {
    border-left: 4px solid #ef4444;
}

.error p {
    color: #ef4444;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    padding: 32px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 12px;
}

.modal-close:hover {
    color: var(--text-primary);
}

#bookDetail h2 {
    font-size: 1.5rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

#bookDetail .detail-section {
    margin-bottom: 20px;
}

#bookDetail .detail-section h4 {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

#bookDetail .detail-section p {
    color: var(--text-primary);
}

#bookDetail .detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

#bookDetail .description {
    line-height: 1.7;
    color: var(--text-secondary);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    header {
        padding: 24px 0;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .search-input-wrapper {
        flex-direction: column;
    }

    .search-options {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-options label {
        width: 100%;
        justify-content: space-between;
    }

    .search-options select {
        flex: 1;
    }

    .btn-link {
        margin-left: 0;
        margin-top: 8px;
    }

    .results-info {
        flex-direction: column;
        gap: 12px;
    }

    .pagination {
        width: 100%;
        justify-content: space-between;
    }

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

    #bookDetail .detail-grid {
        grid-template-columns: 1fr;
    }
}

/* PWA specific styles */
@supports (padding: env(safe-area-inset-top)) {
    .container {
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* Touch feedback for mobile */
@media (hover: none) {
    .book-card:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    .btn-primary:active,
    .btn-secondary:active {
        transform: scale(0.95);
    }
}

/* Prevent pull-to-refresh on PWA */
html {
    overscroll-behavior-y: contain;
}

/* Offline indicator */
.offline-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ef4444;
    color: white;
    text-align: center;
    padding: 12px;
    font-size: 0.9rem;
    z-index: 2000;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.offline-banner.show {
    transform: translateY(0);
}
