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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

html.dark {
    --primary: #3b82f6;
    --primary-dark: #60a5fa;
    --bg: #0f172a;
    --card-bg: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

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

nav {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
    cursor: pointer;
}

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

.nav-links a, .nav-links button {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    background: none;
}

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

main { padding: 1rem; max-width: 1200px; margin: 0 auto; }
main.wide { max-width: 100%; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

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

.card-clickable { cursor: pointer; transition: transform 0.1s; }
.card-clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

.card h3 { margin-bottom: 0.5rem; }
.card .muted { color: var(--text-muted); font-size: 0.875rem; }

.card-compact { padding: 0.5rem 0.75rem; }
.card-compact h3 { margin-bottom: 0; font-size: 1rem; }

.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; font-size: 0.875rem; }
.form-group input, .form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.form-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.form-row .form-group { flex: 1; }

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

.search-bar input { flex: 1; min-width: 200px; }
.search-bar select { width: auto; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.page-header h1 { font-size: 1.5rem; }

.breadcrumb {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.breadcrumb a { color: var(--primary); text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb span { color: var(--text-muted); }

.shelf-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    background: var(--card-bg);
}

.shelf-header {
    padding: 0.5rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.shelf-books {
    padding: 0.75rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.book-card {
    width: 100px;
    text-align: center;
    flex-shrink: 0;
    cursor: pointer;
}

.book-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: 4px;
    background: var(--bg);
    margin-bottom: 0.25rem;
}

.book-cover-placeholder {
    width: 100%;
    aspect-ratio: 2/3;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 4px;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem;
}

.book-title { font-size: 0.75rem; font-weight: 600; line-height: 1.2; }
.book-author { font-size: 0.625rem; color: var(--text-muted); }

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
}

.modal {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    z-index: 201;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h2 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

.hidden { display: none !important; }

.isbn-results {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 0.5rem;
}

.isbn-result {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.isbn-result:hover { background: var(--bg); }
.isbn-result:last-child { border-bottom: none; }
.isbn-result img { width: 30px; height: 45px; object-fit: cover; border-radius: 2px; }

.alert { padding: 0.75rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.875rem; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

@media (max-width: 640px) {
    nav { flex-direction: column; gap: 0.5rem; }
    .card-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .search-bar { flex-direction: column; }
    .modal { width: 95%; padding: 1rem; }
}
