/* app/static/css/style.css */
:root[data-theme="dark"] {
    --bg: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text: #e0e0e0;
    --text-secondary: #b0b0b0;
    --accent: #4a9eff;
    --border: #3d3d3d;
}

:root[data-theme="light"] {
    --bg: #ffffff;
    --bg-secondary: #f5f5f5;
    --text: #2d2d2d;
    --text-secondary: #666666;
    --accent: #2563eb;
    --border: #e0e0e0;
}

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

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

body.modal-open {
    overflow: hidden;
}

.navbar {
    background: var(--bg-secondary);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: bold;
}

.nav-links {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.nav-links a, .nav-links button {
    color: var(--text);
    text-decoration: none;
    padding: 0.5rem 1rem;
    background: none;
    border: 1px solid var(--border);
    cursor: pointer;
    border-radius: 4px;
}

.nav-links a:hover, .nav-links button:hover {
    background: var(--accent);
    color: white;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.filters {
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.filters select {
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    min-width: 200px;
    cursor: pointer;
}

.author-combo {
    position: relative;
    min-width: 200px;
}

.author-combo input[type="text"] {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
}

.author-combo input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

.author-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 0.25rem;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.author-dropdown.show {
    display: block;
}

.author-option {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.author-option:last-child {
    border-bottom: none;
}

.author-option:hover {
    background: var(--accent);
    color: white;
}

.author-option.selected {
    background: var(--accent);
    color: white;
}

.author-option .author-count {
    font-size: 0.85rem;
    opacity: 0.7;
}

.author-dropdown-loading {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.clear-filters-btn {
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.clear-filters-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.search-bar {
    margin-bottom: 2rem;
    display: flex;
    gap: 1rem;
}

.search-bar input {
    flex: 1;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
}

.search-bar button {
    padding: 1rem 2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.search-bar button:hover {
    opacity: 0.9;
}

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

.book-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    height: 450px;
    position: relative;
}

.book-card:hover {
    transform: translateY(-4px);
}

.book-card img {
    width: 100%;
    height: 300px;
    object-fit: contain;
    object-position: center;
    background: var(--bg-secondary);
    display: block;
    flex-shrink: 0;
}

.book-card img.lazy {
    background: var(--bg-secondary);
    min-height: 300px;
}

.book-card h3 {
    padding: 1rem 1rem 0.5rem;
    font-size: 1rem;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
    min-height: 2.6em;
}

.book-card p {
    padding: 0 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.genre-tag {
    display: block;
    padding: 0.25rem 0.75rem;
    margin: auto 1rem 1rem;
    background: var(--accent);
    color: white;
    border-radius: 4px;
    font-size: 0.75rem;
    text-align: center;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rating-display {
    display: inline-flex;
    position: relative;
    font-size: 1em;
    line-height: 1;
}

.rating-stars-bg {
    color: #444;
    position: relative;
}

.rating-stars-fill {
    color: #ffc107;
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    white-space: nowrap;
}

.book-card-rating {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: rgba(0, 0, 0, 0.8);
    color: #ffc107;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.book-rating {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: #ffc107;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

.modal-rating {
    color: #ffc107;
    font-size: 1.1rem;
    margin: 1rem 0;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-rating .rating-display {
    font-size: 1.1rem;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
}

.auth-form {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
}

.auth-form h2 {
    margin-bottom: 1rem;
}

.auth-form input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
}

.auth-form button {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 1rem;
}

.auth-form button:hover {
    opacity: 0.9;
}

.auth-form button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-form a {
    color: var(--accent);
    text-decoration: none;
    display: block;
    text-align: center;
}

.auth-form a:hover {
    text-decoration: underline;
}

.auth-note {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.account-created {
    text-align: center;
}

.code-box {
    background: var(--bg);
    border: 2px solid var(--accent);
    padding: 1.5rem;
    margin: 1rem 0;
    font-size: 1.5rem;
    font-family: monospace;
    font-weight: bold;
    letter-spacing: 0.1em;
    border-radius: 8px;
}

.account-code-display {
    margin: 2rem 0;
}

.account-code-display h3 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.account-code-display button {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 1rem;
}

.account-code-display button:hover {
    opacity: 0.9;
}

.warning-box {
    background: rgba(255, 152, 0, 0.1);
    border-left: 4px solid #ff9800;
    padding: 1rem;
    margin: 2rem 0;
    border-radius: 4px;
    text-align: left;
}

.warning-box p {
    margin: 0.5rem 0;
}

.btn-primary {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.75rem 2rem;
    background: var(--accent);
    color: white !important; 
    text-decoration: none;
    border-radius: 4px;
}

.btn-primary:hover {
    opacity: 0.9;
}

.account-created .btn-primary {
    display: block;
    width: 100%;
    text-align: center;
    margin-top: 2rem;
}

.flash-messages {
    max-width: 1400px;
    margin: 1rem auto;
    padding: 0 2rem;
}

.flash {
    background: var(--accent);
    color: white;
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.book-detail {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 2rem;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 3rem;
}

.book-cover img {
    width: 100%;
    border-radius: 8px;
}

.book-info h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.book-info h2 {
    color: var(--text-secondary);
    font-weight: normal;
    margin-bottom: 1rem;
}

.book-info p {
    margin-bottom: 1rem;
    line-height: 1.8;
}

.book-actions {
    margin: 2rem 0;
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.book-actions select {
    padding: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
}

.remove-book-btn {
    padding: 0.5rem 1rem;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.remove-book-btn:hover {
    background: #d32f2f;
}

.rating {
    display: flex;
    gap: 0.5rem;
}

.star {
    font-size: 2.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
    user-select: none;
    position: relative;
    line-height: 1;
}

.star:hover {
    color: var(--text-secondary);
}

.star.active {
    color: #ffc107;
}

.star.half::after {
    content: '★';
    position: absolute;
    left: 0;
    top: 0;
    color: #ffc107;
    overflow: hidden;
    width: 50%;
}

.star.hover-half::before,
.star.hover-full::before {
    content: '★';
    position: absolute;
    left: 0;
    top: 0;
    color: #ffc107;
    overflow: hidden;
    pointer-events: none;
}

.star.hover-half::before {
    width: 50%;
}

.star.hover-full::before {
    width: 100%;
}

.book-info textarea {
    width: 100%;
    min-height: 150px;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    resize: vertical;
    margin-bottom: 1rem;
    font-family: inherit;
}

.book-info button {
    padding: 0.75rem 2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.book-info button:hover {
    opacity: 0.9;
}

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

.modal-content {
    background: var(--bg-secondary);
    margin: 5% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.book-modal-content {
    max-width: 1000px;
}

.book-modal-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
}

.book-modal-cover img {
    width: 100%;
    border-radius: 8px;
}

.book-modal-info h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.book-modal-info h3 {
    color: var(--text-secondary);
    font-weight: normal;
    margin-bottom: 0.5rem;
}

.book-year {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.book-description {
    margin: 1rem 0;
    line-height: 1.8;
}

.book-modal-info .book-actions {
    margin: 1.5rem 0;
}

.book-modal-info textarea {
    width: 100%;
    min-height: 120px;
    padding: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    resize: vertical;
    margin-bottom: 1rem;
    font-family: inherit;
}

.book-modal-info button {
    padding: 0.75rem 2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.book-modal-info button:hover {
    opacity: 0.9;
}

.modal-content h2 {
    margin-bottom: 1rem;
}

.modal-content input {
    width: 100%;
    padding: 1rem;
    margin-bottom: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 1rem;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

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

.ol-results {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.ol-result {
    display: grid;
    grid-template-columns: 80px 1fr auto;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 8px;
    align-items: center;
    border: 1px solid var(--border);
}

.ol-result img {
    width: 80px;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
}

.ol-result-info h4 {
    margin: 0;
    font-size: 1rem;
}

.ol-result-info p {
    margin: 0.25rem 0 0 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.import-btn {
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.import-btn:hover {
    opacity: 0.9;
}

.review-form {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.review-form h3 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.reviews-section {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.reviews-section h3 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.review-card {
    background: var(--bg);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.review-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.review-header-right {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.review-rating {
    color: #ffc107;
    font-size: 1rem;
}

.edit-review-btn {
    padding: 0.25rem 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.edit-review-btn:hover {
    opacity: 0.9;
}

.review-text {
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.no-reviews {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.save-status {
    margin-top: 1rem;
    padding: 0.5rem;
    border-radius: 4px;
    text-align: center;
    font-size: 0.9rem;
}

.save-status.success {
    background: #4caf50;
    color: white;
}

.save-status.error {
    background: #f44336;
    color: white;
}

.profile-header {
    margin-bottom: 3rem;
}

.profile-header h1 {
    font-size: 2.5rem;
    margin-bottom: 2rem;
}

.profile-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
}

.stat-number {
    font-size: 3rem;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 1rem;
}

.profile-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
}

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

.tab-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.no-books {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
    font-size: 1.2rem;
}

.settings-section {
    max-width: 1200px;
    margin: 0 auto;
}

.settings-card {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.settings-card h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.code-display {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.code-display code {
    flex: 1;
    background: var(--bg);
    padding: 1rem;
    border-radius: 4px;
    font-size: 1.2rem;
    border: 1px solid var(--border);
}

.code-display button {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.code-display button:hover {
    opacity: 0.9;
}

.settings-note {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

#display-name-form {
    display: flex;
    gap: 1rem;
}

#display-name-form input {
    flex: 1;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
}

#display-name-form button {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#display-name-form button:hover {
    opacity: 0.9;
}

@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }
    
    .book-detail {
        grid-template-columns: 1fr;
    }
    
    .book-modal-grid {
        grid-template-columns: 1fr;
    }
    
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 1rem;
    }
    
    .book-card {
        height: 380px;
    }
    
    .book-card img {
        height: 225px;
    }
    
    .book-card img.lazy {
        min-height: 225px;
    }
    
    .search-bar {
        flex-direction: column;
    }
    
    .ol-result {
        grid-template-columns: 60px 1fr;
        gap: 0.75rem;
    }
    
    .ol-result img {
        width: 60px;
        height: 90px;
    }
    
    .import-btn {
        grid-column: 2;
        margin-top: 0.5rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 1.5rem;
    }
    
    .filters select {
        width: 100%;
    }
    
    .author-combo {
        width: 100%;
        min-width: unset;
    }
    
    .clear-filters-btn {
        width: 100%;
    }
    
    .profile-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .stat-card {
        padding: 1.5rem;
    }
    
    .stat-number {
        font-size: 2.5rem;
    }
    
    .profile-tabs {
        flex-direction: column;
    }
    
    .tab-btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 1rem;
    }
    
    .navbar {
        padding: 1rem;
    }
    
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .book-card {
        height: 320px;
    }
    
    .book-card img {
        height: 180px;
    }
    
    .book-card img.lazy {
        min-height: 180px;
    }
    
    .book-card h3 {
        font-size: 0.9rem;
        padding: 0.75rem 0.75rem 0.5rem;
    }
    
    .book-card p {
        font-size: 0.8rem;
        padding: 0 0.75rem;
    }
}


.book-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.book-title-row h2 {
    margin: 0;
    flex: 1;
}

.translate-toggle-btn {
    padding: 0.5rem 1rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.translate-toggle-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}


.shelf-form {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.shelf-form input {
    flex: 1;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
}

.shelf-form button {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.shelf-form button:hover {
    opacity: 0.9;
}

.shelf-list {
    margin-top: 1.5rem;
}

.shelf-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.shelf-item span {
    font-size: 1rem;
}

.delete-shelf-btn {
    padding: 0.5rem 1rem;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.delete-shelf-btn:hover {
    background: #d32f2f;
}