:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #64748b;
    --danger: #ef4444;
    --success: #22c55e;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

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

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

.app {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 30px 0;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

main {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.scanner-section {
    text-align: center;
}

.scanner-container {
    max-width: 500px;
    margin: 0 auto 20px;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
}

#reader {
    width: 100%;
}

#reader img {
    width: 100%;
}

.scanner-hint {
    color: #fff;
    padding: 10px;
    background: rgba(0, 0, 0, 0.7);
    font-size: 0.9rem;
}

.scanner-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

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

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

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.select {
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.count {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
}

.actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.books-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 500px;
    overflow-y: auto;
}

.book-card {
    display: flex;
    gap: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

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

.book-cover {
    width: 60px;
    height: 80px;
    object-fit: cover;
    border-radius: 4px;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

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

.book-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.book-isbn {
    font-size: 0.75rem;
    color: var(--secondary);
    font-family: monospace;
}

.book-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.empty-message {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 1rem;
}

footer {
    text-align: center;
    padding: 30px 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading p {
    color: white;
    margin-top: 16px;
    font-size: 1rem;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.875rem;
    z-index: 1001;
    animation: fadeInUp 0.3s ease;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@media (max-width: 600px) {
    .app {
        padding: 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    section {
        padding: 16px;
    }

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

    .btn {
        width: 100%;
        justify-content: center;
    }

    .actions {
        flex-direction: column;
    }

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

    .book-cover {
        margin: 0 auto;
    }
}
