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

:root {
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-primary: #2c3e50;
    --color-accent: #3498db;
    --color-accent-hover: #2980b9;
    --color-text: #333333;
    --color-text-muted: #777777;
    --color-border: #e0e0e0;
    --color-error: #e74c3c;
    --color-success: #27ae60;
    --color-want: #f39c12;
    --color-reading: #3498db;
    --color-read: #27ae60;
    --color-abandoned: #95a5a6;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    --radius: 8px;
    --transition: 0.2s ease;
}

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

/* === Header === */
header {
    background: var(--color-primary);
    color: white;
    padding: 1.25rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-md);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header-btn {
    margin-top: 0.5rem;
    padding: 0.35rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* === Main === */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* === Suchbereich === */
#search-section {
    margin-bottom: 1.5rem;
}

.search-box {
    display: flex;
    gap: 0.5rem;
    max-width: 600px;
    margin: 0 auto;
}

.search-box input {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--transition);
}

.search-box input:focus {
    border-color: var(--color-accent);
}

.search-box button {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    background: var(--color-accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
    white-space: nowrap;
}

.search-box button:hover:not(:disabled) {
    background: var(--color-accent-hover);
}

.search-box button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* === Fehlermeldung === */
.error-message {
    max-width: 600px;
    margin: 0.75rem auto 0;
    padding: 0.75rem 1rem;
    background: #fdeaea;
    color: var(--color-error);
    border: 1px solid #f5c6c6;
    border-radius: var(--radius);
    text-align: center;
    font-size: 0.9rem;
}

/* === Hidden === */
.hidden {
    display: none !important;
}

/* === Vorschau & Detail-Card === */
.book-detail-card {
    display: flex;
    gap: 1.5rem;
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.book-detail-cover {
    flex-shrink: 0;
}

.book-detail-cover {
    position: relative;
}

.book-detail-cover img {
    width: 180px;
    height: auto;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.btn-upload {
    display: block;
    margin-top: 0.5rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    text-align: center;
    transition: background var(--transition);
}

.btn-upload:hover {
    background: #1a252f;
}

.paste-hint {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-align: center;
}

.book-detail-info {
    flex: 1;
    min-width: 0;
}

.book-detail-info h3 {
    font-size: 1.4rem;
    margin-bottom: 0.25rem;
    color: var(--color-primary);
}

.subtitle {
    font-size: 1rem;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
    font-style: italic;
}

.meta {
    font-size: 0.9rem;
    margin-bottom: 0.35rem;
}

.meta strong {
    color: var(--color-primary);
}

.description {
    margin-top: 1rem;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--color-text);
    max-height: 200px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* === Vorschau Aktionen === */
#preview-section {
    margin-bottom: 2rem;
}

#preview-section h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--color-primary);
}

.preview-actions,
.modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.25rem;
    align-items: center;
    flex-wrap: wrap;
}

.preview-actions select,
.modal-actions select {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
    cursor: pointer;
}

.btn-save {
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--color-success);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-save:hover {
    background: #219a52;
}

.btn-cancel {
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
    background: var(--color-border);
    color: var(--color-text);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-cancel:hover {
    background: #ccc;
}

.btn-refresh {
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--color-accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-refresh:hover:not(:disabled) {
    background: var(--color-accent-hover);
}

.btn-refresh:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-delete {
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--color-error);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-delete:hover {
    background: #c0392b;
}

/* === Lese-Challenge === */
.challenge-section {
    margin-bottom: 1.5rem;
}

.challenge-header {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.challenge-header h2 {
    font-size: 1.1rem;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
}

.challenge-progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.challenge-progress + .challenge-progress {
    margin-top: 0.4rem;
}

.challenge-progress-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    min-width: 80px;
}

.challenge-progress-bar {
    flex: 1;
    height: 12px;
    background: var(--color-border);
    border-radius: 6px;
    overflow: hidden;
}

.challenge-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-accent), var(--color-accent-hover));
    border-radius: 6px;
    transition: width 0.4s ease;
    width: 0%;
}

.challenge-read-fill {
    background: linear-gradient(90deg, var(--color-success), #1e8449);
}

.challenge-progress-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-primary);
    white-space: nowrap;
}

/* === Genre-Select (inline in Metadaten) === */
.genre-select-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.genre-select {
    padding: 0.2rem 0.5rem;
    font-size: 0.85rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition);
}

.genre-select:focus {
    border-color: var(--color-accent);
}

/* === Admin-Sektion === */
.admin-section {
    margin-bottom: 1.5rem;
}

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

.admin-header h2 {
    font-size: 1.2rem;
    color: var(--color-primary);
}

.admin-add {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.admin-add input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--transition);
}

.admin-add input:focus {
    border-color: var(--color-accent);
}

.admin-genre-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.admin-genre-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.35rem 0.5rem 0.35rem 0.75rem;
}

.admin-genre-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text);
}

.admin-genre-delete {
    padding: 0.15rem 0.4rem !important;
    font-size: 0.7rem !important;
    border-radius: 4px !important;
}

/* === Migration === */
.admin-migrate {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.admin-migrate h3 {
    font-size: 1rem;
    color: var(--color-primary);
    margin-bottom: 0.35rem;
}

.admin-migrate-desc {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}

.btn-migrate {
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--color-want);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-migrate:hover {
    background: #e08e0b;
}

.admin-migrate-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-import-label {
    display: inline-block;
    text-align: center;
}

/* === Lesemonat === */
.readmonth-wrap {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary);
    white-space: nowrap;
}

.readmonth-wrap label {
    cursor: default;
}

.readmonth-wrap input[type="month"] {
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition);
}

.readmonth-wrap input[type="month"]:focus {
    border-color: var(--color-accent);
}

.challenge-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.challenge-checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-accent);
    cursor: pointer;
}

.book-card-challenge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    padding: 0.15rem 0.4rem;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 4px;
    background: var(--color-accent);
    color: white;
    letter-spacing: 0.3px;
}

/* === Bibliothek === */
#library-section {
    margin-top: 1rem;
}

.library-header {
    margin-bottom: 1rem;
}

.library-header h2 {
    font-size: 1.3rem;
    color: var(--color-primary);
    margin-bottom: 0.75rem;
}

.badge {
    display: inline-block;
    background: var(--color-accent);
    color: white;
    font-size: 0.8rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    vertical-align: middle;
    margin-left: 0.25rem;
}

.library-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.library-controls input,
.library-controls select {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--transition);
}

.library-controls input {
    flex: 1;
    min-width: 180px;
}

.library-controls input:focus {
    border-color: var(--color-accent);
}

/* === Buch-Grid === */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.25rem;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
    font-size: 1rem;
}

.empty-state p + p {
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

/* === Buch-Card === */
.book-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
}

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

.book-card-cover {
    position: relative;
    background: #e8e8e8;
    aspect-ratio: 2 / 3;
    overflow: hidden;
}

.book-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-card-status {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 4px;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.status-want {
    background: var(--color-want);
}

.status-reading {
    background: var(--color-reading);
}

.status-read {
    background: var(--color-read);
}

.status-abandoned {
    background: var(--color-abandoned);
}

.book-card-info {
    padding: 0.75rem;
}

.book-card-title {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-card-author {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    overflow-y: auto;
}

.modal-content {
    position: relative;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-muted);
    cursor: pointer;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background var(--transition), color var(--transition);
    z-index: 1;
}

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

/* === Responsive === */
@media (max-width: 640px) {
    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    main {
        padding: 1rem;
    }

    .book-detail-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .book-detail-cover img {
        width: 140px;
    }

    .book-detail-info {
        text-align: left;
    }

    .preview-actions,
    .modal-actions {
        justify-content: center;
    }

    .library-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.75rem;
    }

    .library-controls {
        flex-direction: column;
    }

    .search-box {
        flex-direction: column;
    }

    .search-box button {
        width: 100%;
    }
}
