🎨 CSS y JavaScript Completos

Estilos y funcionalidad JavaScript del sistema

1. static/css/styles.css - Estilos Completos (500+ líneas)

Ubicación: static/css/styles.css
Descripción: Estilos CSS completos para todo el sistema.

/* ========== RESET Y VARIABLES ========== */
:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

body {
    font-family: var(--font-family);
    line-height: 1.6;
    color: #333;
    background: #f5f5f5;
}

/* ========== NAVBAR ========== */
.navbar {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
}

.navbar .logo {
    color: white;
    font-size: 1.5em;
    font-weight: bold;
    text-decoration: none;
    transition: transform 0.3s;
}

.navbar .logo:hover {
    transform: scale(1.05);
}

.nav-menu {
    list-style: none;
    display: flex;
    gap: 30px;
    align-items: center;
}

.nav-menu a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    padding: 8px 15px;
    border-radius: 5px;
    transition: all 0.3s;
}

.nav-menu a:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* ========== MAIN CONTENT ========== */
.main-content {
    min-height: calc(100vh - 140px);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ========== HERO SECTION ========== */
.hero-section {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 80px 20px;
    text-align: center;
}

.hero-section h1 {
    font-size: 3em;
    margin-bottom: 20px;
    animation: fadeInDown 0.8s;
}

.hero-section p {
    font-size: 1.3em;
    margin-bottom: 30px;
    opacity: 0.9;
}

.hero-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ========== BUTTONS ========== */
.btn {
    display: inline-block;
    padding: 12px 30px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.btn-secondary {
    background: white;
    color: var(--primary-color);
    border: 2px solid white;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.btn-sm {
    padding: 8px 20px;
    font-size: 0.9em;
}

.btn-lg {
    padding: 15px 40px;
    font-size: 1.1em;
}

/* ========== STATS SECTION ========== */
.stats-section {
    padding: 60px 20px;
    background: white;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
}

.stat-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    transition: all 0.3s;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.stat-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.stat-icon {
    font-size: 3em;
    margin-bottom: 15px;
}

.stat-number {
    font-size: 2.5em;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.stat-label {
    font-size: 1.1em;
    color: #666;
}

/* ========== FEATURES SECTION ========== */
.features-section {
    padding: 60px 20px;
    background: #f8f9fa;
}

.features-section h2 {
    text-align: center;
    font-size: 2.5em;
    margin-bottom: 50px;
    color: var(--dark-color);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
}

.feature-card {
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    transition: all 0.3s;
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.feature-card h3 {
    font-size: 1.8em;
    margin-bottom: 15px;
    color: var(--primary-color);
}

.feature-card p {
    color: #666;
    margin-bottom: 20px;
}

/* ========== CATALOGO LAYOUT ========== */
.page-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 40px 20px;
    text-align: center;
}

.catalogo-layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 30px;
    margin-top: 30px;
}

.filters-sidebar {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    height: fit-content;
    position: sticky;
    top: 90px;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.filter-group select,
.filter-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
}

/* ========== LIBROS GRID ========== */
.libros-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
}

.libro-card {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: all 0.3s;
}

.libro-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
}

.libro-imagen {
    height: 200px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.libro-placeholder {
    font-size: 5em;
    opacity: 0.3;
}

.libro-info {
    padding: 20px;
}

.libro-info h3 {
    font-size: 1.2em;
    margin-bottom: 10px;
    color: var(--dark-color);
}

.libro-autor {
    color: #666;
    font-size: 0.95em;
    margin-bottom: 8px;
}

.libro-editorial {
    color: #999;
    font-size: 0.9em;
    margin-bottom: 15px;
}

.libro-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

/* ========== BADGES ========== */
.badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
}

.badge-categoria {
    background: #e3f2fd;
    color: #1976d2;
}

.badge-disponible {
    background: #e8f5e9;
    color: #388e3c;
}

.badge-prestado {
    background: #ffebee;
    color: #d32f2f;
}

.badge-danger {
    background: #dc3545;
    color: white;
}

/* ========== PAGINATION ========== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 40px;
}

.pagination .btn {
    padding: 8px 15px;
}

.pagination span {
    color: #666;
}

/* ========== DETALLE LIBRO ========== */
.breadcrumb {
    padding: 20px 0;
    color: #666;
}

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

.libro-detalle-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 40px;
    margin: 30px 0;
}

.libro-imagen-grande {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    height: 450px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.libro-placeholder-grande {
    font-size: 10em;
    opacity: 0.3;
}

.libro-detalle-info h1 {
    font-size: 2.5em;
    color: var(--dark-color);
    margin-bottom: 15px;
}

.libro-autor-grande {
    font-size: 1.3em;
    color: var(--primary-color);
    margin-bottom: 30px;
}

.libro-meta-info {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
}

.meta-item {
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
}

.meta-item:last-child {
    border-bottom: none;
}

.libro-descripcion {
    margin-bottom: 30px;
}

.libro-descripcion h3 {
    margin-bottom: 15px;
    color: var(--dark-color);
}

.libro-acciones {
    margin-top: 30px;
}

/* ========== SEARCH PAGE ========== */
.search-page h1 {
    text-align: center;
    margin-bottom: 30px;
    color: var(--dark-color);
}

.search-form-container {
    max-width: 800px;
    margin: 0 auto 40px;
}

.search-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-input-group input {
    flex: 1;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
}

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

.search-filters {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.search-filters select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

/* ========== FOOTER ========== */
.footer {
    background: var(--dark-color);
    color: white;
    padding: 30px 20px;
    text-align: center;
}

.footer p {
    margin: 5px 0;
    opacity: 0.8;
}

/* ========== ANIMATIONS ========== */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.5s;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .navbar .container {
        flex-direction: column;
        height: auto;
        padding: 15px;
    }
    
    .nav-menu {
        flex-direction: column;
        gap: 10px;
    }
    
    .hero-section h1 {
        font-size: 2em;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .catalogo-layout {
        grid-template-columns: 1fr;
    }
    
    .filters-sidebar {
        position: static;
    }
    
    .libro-detalle-layout {
        grid-template-columns: 1fr;
    }
}

2. static/js/main.js - JavaScript Completo (200+ líneas)

Ubicación: static/js/main.js
Descripción: Funcionalidad JavaScript con AJAX, animaciones y más.

// ========== CONFIGURACIÓN GLOBAL ==========
const API_BASE_URL = '/api';
const SEARCH_DEBOUNCE_MS = 300;

// ========== UTILIDADES ==========
const debounce = (func, wait) => {
    let timeout;
    return function executedFunction(...args) {
        const later = () => {
            clearTimeout(timeout);
            func(...args);
        };
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
    };
};

const showLoading = () => {
    const loader = document.createElement('div');
    loader.className = 'loader';
    loader.innerHTML = '⏳ Cargando...';
    document.body.appendChild(loader);
};

const hideLoading = () => {
    const loader = document.querySelector('.loader');
    if (loader) loader.remove();
};

// ========== BÚSQUEDA EN TIEMPO REAL ==========
const searchInput = document.getElementById('search-input');
if (searchInput) {
    const performSearch = async (query) => {
        if (query.length < 3) return;
        
        try {
            const response = await fetch(`${API_BASE_URL}/libros/?search=${encodeURIComponent(query)}`);
            const data = await response.json();
            
            updateSearchResults(data.results || data);
        } catch (error) {
            console.error('Error en búsqueda:', error);
        }
    };
    
    const debouncedSearch = debounce(performSearch, SEARCH_DEBOUNCE_MS);
    
    searchInput.addEventListener('input', (e) => {
        debouncedSearch(e.target.value);
    });
}

const updateSearchResults = (libros) => {
    const resultsContainer = document.getElementById('search-results');
    if (!resultsContainer) return;
    
    if (libros.length === 0) {
        resultsContainer.innerHTML = '

No se encontraron resultados

'; return; } const html = libros.map(libro => `
📖

${libro.titulo}

${libro.autor_nombre}

${libro.categoria_nombre} ${libro.stock_disponible > 0 ? 'Disponible' : 'No disponible'}
Ver
`).join(''); resultsContainer.innerHTML = html; }; // ========== FILTROS DINÁMICOS ========== const filterForm = document.getElementById('filtros-form'); if (filterForm) { filterForm.addEventListener('change', (e) => { e.preventDefault(); const formData = new FormData(filterForm); const params = new URLSearchParams(formData); // Recargar con los nuevos parámetros window.location.href = `?${params.toString()}`; }); } // ========== SOLICITAR PRÉSTAMO (Envío tradicional con validación) ========== const prestamoForm = document.querySelector('.prestamo-form'); if (prestamoForm) { prestamoForm.addEventListener('submit', function(e) { const terminos = prestamoForm.querySelector('input[name="acepto_terminos"]'); if (!terminos || !terminos.checked) { e.preventDefault(); alert('⚠️ Debes aceptar los términos y condiciones'); return false; } // Permitir el envío normal del formulario (POST tradicional) // El formulario se enviará a la URL especificada en el atributo action return true; }); } // ========== RENOVAR PRÉSTAMO ========== document.querySelectorAll('.btn-renovar').forEach(btn => { btn.addEventListener('click', async (e) => { e.preventDefault(); const prestamoId = btn.dataset.prestamoId; if (!confirm('¿Deseas renovar este préstamo por 14 días más?')) { return; } try { showLoading(); const response = await fetch(`/renovar-prestamo/${prestamoId}/`, { method: 'POST', headers: { 'X-CSRFToken': getCsrfToken(), }, }); hideLoading(); if (response.ok) { showNotification('✅ Préstamo renovado exitosamente', 'success'); setTimeout(() => location.reload(), 1500); } else { showNotification('❌ No se pudo renovar el préstamo', 'error'); } } catch (error) { hideLoading(); console.error('Error:', error); showNotification('❌ Error de conexión', 'error'); } }); }); // ========== NOTIFICACIONES ========== const showNotification = (message, type = 'info') => { const notification = document.createElement('div'); notification.className = `notification notification-${type}`; notification.textContent = message; document.body.appendChild(notification); // Animar entrada setTimeout(() => notification.classList.add('show'), 10); // Remover después de 3 segundos setTimeout(() => { notification.classList.remove('show'); setTimeout(() => notification.remove(), 300); }, 3000); }; // Estilos de notificación (agregar al CSS) const notificationStyles = ` .notification { position: fixed; top: 20px; right: 20px; padding: 15px 25px; border-radius: 5px; color: white; font-weight: 600; box-shadow: 0 5px 15px rgba(0,0,0,0.3); transform: translateX(400px); transition: transform 0.3s; z-index: 9999; } .notification.show { transform: translateX(0); } .notification-success { background: #28a745; } .notification-error { background: #dc3545; } .notification-info { background: #17a2b8; } `; // ========== CSRF TOKEN ========== const getCsrfToken = () => { const name = 'csrftoken'; let cookieValue = null; if (document.cookie && document.cookie !== '') { const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); if (cookie.substring(0, name.length + 1) === (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; }; // ========== CALCULAR FECHA DE DEVOLUCIÓN ========== const calculateReturnDate = (dias) => { const date = new Date(); date.setDate(date.getDate() + parseInt(dias)); return date.toISOString().split('T')[0]; }; // ========== ANIMACIONES AL SCROLL ========== const observeElements = () => { const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('fade-in'); } }); }, { threshold: 0.1 }); document.querySelectorAll('.stat-card, .feature-card, .libro-card').forEach(el => { observer.observe(el); }); }; // ========== GRÁFICOS DE ESTADÍSTICAS ========== const loadCharts = async () => { const categoriasCanvas = document.getElementById('chart-categorias'); const prestamosCanvas = document.getElementById('chart-prestamos'); if (!categoriasCanvas || !prestamosCanvas) return; // Aquí se integraría Chart.js console.log('Cargar gráficos con Chart.js'); }; // ========== SMOOTH SCROLL ========== document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); // ========== INICIALIZACIÓN ========== document.addEventListener('DOMContentLoaded', () => { console.log('🚀 Sistema de Biblioteca iniciado'); observeElements(); loadCharts(); // Agregar estilos de notificación const style = document.createElement('style'); style.textContent = notificationStyles; document.head.appendChild(style); }); // ========== LOADER CSS (agregar al styles.css) ========== /* .loader { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0, 0, 0, 0.8); color: white; padding: 20px 40px; border-radius: 10px; font-size: 1.2em; z-index: 9999; } */

✅ Resumen de CSS y JavaScript

Se han documentado 2 archivos completos:

styles.css (500+ líneas):
- Variables CSS personalizadas
- Navbar sticky responsive
- Sistema de grid para catálogo
- Cards animadas
- Badges y badges de estado
- Sistema de paginación
- Diseño responsive completo
- Animaciones CSS

main.js (200+ líneas):
- Búsqueda AJAX en tiempo real
- Sistema de notificaciones
- Filtros dinámicos
- Préstamos con AJAX
- Manejo de CSRF tokens
- Animaciones al scroll
- Smooth scroll
- Debounce para optimización

Características:
✅ Totalmente responsive
✅ Animaciones suaves
✅ AJAX para mejor UX
✅ Sistema de notificaciones
✅ Compatible con API REST
✅ Manejo de errores

Para implementar:
1. Crea la carpeta static/css/
2. Crea la carpeta static/js/
3. Copia styles.css y main.js
4. Ejecuta python manage.py collectstatic
5. Asegúrate de incluir los archivos en base.html

✅ Ir al Inicio del Sistema ← Ver Templates ← Ver Views y URLs