/* PWA Library Styles */
:root {
    --primary-color: #f7931a;
    --secondary-color: #1a1a1a;
    --accent-color: #4caf50;
    --danger-color: #f44336;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --background-primary: #121212;
    --background-secondary: #1e1e1e;
    --background-tertiary: #2a2a2a;
    --border-color: #333333;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --border-radius: 12px;
}

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

body.pwa-mode {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

.pwa-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    min-height: 100vh;
}

/* PWA Status Bar */
.pwa-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-color), #e6830a);
    padding: 0.5rem 1rem;
    margin: 0 -1rem 1rem -1rem;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    font-size: 0.85rem;
}

.pwa-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    font-weight: 500;
}

.pwa-icon {
    font-size: 1rem;
}

.pwa-version {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
}

/* Header */
.pwa-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.pwa-header h1 {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0;
}

.reader-id-display {
    display: inline-block;
    font-family: 'Courier New', monospace;
    background: var(--background-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.reader-id-display:hover {
    opacity: 1 !important;
    background: var(--background-tertiary);
    transform: scale(1.02);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.upload-btn, .sync-btn, .update-btn, .subscriptions-btn, .backup-btn, .restore-btn {
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.upload-btn {
    background: var(--primary-color);
    color: #000;
}

.subscriptions-btn {
    background: linear-gradient(135deg, #8e44ad, #9b59b6);
    color: white;
    position: relative;
}

.subscriptions-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(142, 68, 173, 0.4);
}

.subscriptions-btn .badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #e74c3c;
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
}

.upload-btn:hover {
    background: #e6840f;
    transform: translateY(-1px);
}

.sync-btn {
    background: var(--accent-color);
    color: white;
}

.sync-btn:hover {
    background: #45a049;
    transform: translateY(-1px);
}

.update-btn {
    background: var(--background-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.update-btn:hover {
    background: var(--background-secondary);
    transform: translateY(-1px);
}

.backup-btn {
    background: linear-gradient(135deg, #2196f3, #1976d2);
    color: white;
}

.backup-btn:hover {
    background: linear-gradient(135deg, #1976d2, #1565c0);
    transform: translateY(-1px);
}

.restore-btn {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    color: white;
}

.restore-btn:hover {
    background: linear-gradient(135deg, #f57c00, #e65100);
    transform: translateY(-1px);
}

.update-btn:hover {
    background: var(--primary-color);
    color: #000;
    transform: translateY(-1px);
}

.update-btn.checking {
    background: #ffc107;
    color: #000;
    animation: pulse 1.5s infinite;
}

.update-btn.update-available {
    background: #28a745;
    color: white;
    animation: glow 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px rgba(40, 167, 69, 0.5); }
    50% { box-shadow: 0 0 20px rgba(40, 167, 69, 0.8); }
}

/* Search and Filter Bar */
.search-filter-bar {
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.search-container {
    position: relative;
    margin-bottom: 1rem;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
    opacity: 0.6;
}

.search-input {
    width: 100%;
    padding: 0.75rem 3rem 0.75rem 3rem;
    background: var(--background-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--background-primary);
}

.search-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.clear-search {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.clear-search:hover {
    background: var(--background-primary);
    color: var(--text-primary);
}

.filter-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    white-space: nowrap;
}

.filter-select {
    padding: 0.5rem 0.75rem;
    background: var(--background-tertiary);
    border: 1px solid var(--border-color);
    border-radius: calc(var(--border-radius) / 2);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-select:hover {
    border-color: var(--primary-color);
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--background-primary);
}

/* Results Summary */
.results-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--background-tertiary);
    border-radius: calc(var(--border-radius) / 2);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.results-summary #results-count {
    color: var(--text-primary);
    font-weight: 500;
}

.clear-filters {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    padding: 0.5rem 1rem;
    border-radius: calc(var(--border-radius) / 2);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.clear-filters:hover {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
}

/* Upload Area */
.upload-area {
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-bottom: 2rem;
    border: 2px dashed var(--border-color);
    transition: all 0.3s ease;
}

.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(247, 147, 26, 0.1);
}

.upload-content h3 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.upload-zone {
    text-align: center;
    padding: 2rem;
    border: 1px dashed var(--border-color);
    border-radius: calc(var(--border-radius) - 2px);
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-zone:hover {
    border-color: var(--primary-color);
    background: rgba(247, 147, 26, 0.05);
}

.upload-text p {
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

.upload-actions {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

.cancel-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: calc(var(--border-radius) / 2);
    cursor: pointer;
    transition: all 0.2s ease;
}

.cancel-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-primary);
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.book-card {
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.book-cover {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, var(--primary-color), #e6840f);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    position: relative;
    overflow: hidden;
}

.book-cover-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
}

.book-cover-placeholder {
    font-size: 3rem;
    opacity: 0.8;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    z-index: 1;
}

.new-badge {
    background: linear-gradient(135deg, #ff6b35, #f7931a);
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: bold;
    letter-spacing: 1px;
    box-shadow: 0 2px 8px rgba(247, 147, 26, 0.4);
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(247, 147, 26, 0.4);
    }
    50% { 
        transform: scale(1.05);
        box-shadow: 0 4px 16px rgba(247, 147, 26, 0.6);
    }
}

.book-info {
    padding: 1.25rem;
}

.book-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

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

.book-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.book-type {
    background: var(--background-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.book-type.published {
    background: var(--accent-color);
    color: #000;
}

.book-menu-trigger {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.book-menu-trigger:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* Context Menu */
.book-menu {
    position: fixed;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    min-width: 160px;
    z-index: 1000;
    overflow: hidden;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    gap: 0.75rem;
}

.menu-item:hover {
    background: var(--background-tertiary);
}

.menu-item.danger:hover {
    background: var(--danger-color);
    color: white;
}

.menu-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.empty-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.empty-content p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

.primary-btn {
    background: var(--primary-color);
    color: #000;
    border: none;
    padding: 1rem 2rem;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
}

.primary-btn:hover {
    background: #e6840f;
    transform: translateY(-1px);
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

.modal-content {
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

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

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(80vh - 100px);
}

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

/* Update Modal Styles */
.update-modal .modal-content {
    max-width: 600px;
}

.update-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--background-tertiary);
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-color);
}

.update-section h4 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.update-section p {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.update-section details {
    margin-top: 0.5rem;
}

.update-section summary {
    cursor: pointer;
    color: var(--primary-color);
    font-weight: 500;
}

.update-section ul {
    margin: 0.5rem 0 0 1rem;
    color: var(--text-secondary);
}

.modal-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--primary-color);
    color: #000;
}

.btn-primary:hover {
    background: #e6840f;
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--background-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .pwa-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .header-actions button {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }
    
    .search-filter-bar {
        padding: 1rem;
    }
    
    .filter-controls {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .filter-group {
        width: 100%;
        justify-content: space-between;
    }
    
    .filter-select {
        flex: 1;
        min-width: 0;
    }
    
    .results-summary {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
    
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 1rem;
    }
    
    .upload-area {
        padding: 1.5rem;
    }
    
    .upload-zone {
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .search-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .books-grid {
        grid-template-columns: 1fr;
    }
    
    .pwa-container {
        padding: 0 0.75rem;
    }
}