:root {
    --primary-color: #1e3a8a;
    --primary-hover: #1d4ed8;
    --accent-color: #0284c7;
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --status-success-bg: #dcfce7;
    --status-success-text: #15803d;
    --status-error-bg: #fee2e2;
    --status-error-text: #b91c1c;
}

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

html, body {
    height: auto !important;
    min-height: 0 !important;
}

body { 
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
    width: 100%;
}

/* Header Navigation */
.header {
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

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

.logo img {
    max-height: 50px;
    width: auto;
}

.nav-links {
    display: flex;
    gap: 1.25rem;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.925rem;
    transition: color 0.2s ease;
}

.nav-links a:hover {
    color: var(--primary-color);
}

/* Hero Banner */
.hero-banner {
    width: 100%;
    height: 140px;
    border-radius: 12px;
    overflow: hidden;
    background: linear-gradient(135deg, #1e3a8a, #0284c7);
    margin-bottom: 1.5rem;
    position: relative;
}

.hero-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    mix-blend-mode: overlay;
    opacity: 0.6;
}

/* Search Box */
.search-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.75rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.search-form {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.search-select {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #fff;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
}

.search-input-group {
    flex: 1;
    display: flex;
    min-width: 280px;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

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

.btn-search {
    background-color: var(--primary-color);
    color: #ffffff;
    border: none;
    padding: 0 1.5rem;
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

/* Main Content Section */
.content-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 3rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.content-card h2 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-weight: 700;
}

.content-card p {
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-size: 1rem;
}

/* Pestañas (Tabs) de Resultados Multisitio */
.tabs-container {
    margin-top: 1.5rem;
}

.nav-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1.5rem;
}

.tab-button {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.tab-button:hover {
    border-color: var(--accent-color);
    color: var(--primary-color);
}

.tab-button.active {
    background-color: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
}

.badge-count {
    background-color: rgba(0, 0, 0, 0.08);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.tab-button.active .badge-count {
    background-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Listado de Libros / Resultados */
.results-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

.results-list li {
    display: flex;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
    align-items: flex-start;
}

.results-list li:last-child {
    border-bottom: none;
}

.result-number {
    font-weight: 600;
    color: var(--text-muted);
    min-width: 25px;
    text-align: right;
}

.result-body {
    flex: 1;
}

.book-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--primary-color);
    text-decoration: none;
    display: inline-block;
    margin-bottom: 0.25rem;
}

.book-title:hover {
    text-decoration: underline;
}

.book-author, .book-publisher {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}

/* Paginación */
.pagination {
    display: flex;
    list-style: none;
    padding: 0;
    gap: 0.25rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.page-item .page-link {
    display: block;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--primary-color);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: background-color 0.2s;
}

.page-item.active .page-link {
    background-color: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
}

.page-item .page-link:hover {
    background-color: var(--bg-color);
}

/* Alertas de error / reintento */
.alert-error {
    background-color: var(--status-error-bg);
    color: var(--status-error-text);
    border: 1px solid #f5c6cb;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-info {
    background-color: #e2e3e5;
    color: #383d41;
    border: 1px solid #d6d8db;
    padding: 1rem;
    border-radius: 8px;
}

/* Overlay de Carga */
#loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 99999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #e0e0e0;
    border-top: 6px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading-overlay p {
    font-size: 18px;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0;
}

/* Institution List Grid */
.institution-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.institution-section h3 {
    font-size: 1.15rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

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

.institution-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-main);
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.institution-item:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color);
}

.badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-weight: 600;
}

.badge-online {
    background-color: var(--status-success-bg);
    color: var(--status-success-text);
}

.badge-offline {
    background-color: var(--status-error-bg);
    color: var(--status-error-text);
}

/* ========================================================================= */
/* MEDIA QUERIES PARA ADAPTACIÓN A SMARTPHONES Y TABLETS                     */
/* ========================================================================= */

@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }

    /* Header y Navegación */
    .header-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .logo img {
        max-height: 42px;
    }

    .nav-links {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.85rem;
    }

    .hero-banner {
        height: 100px;
        margin-bottom: 1rem;
    }

    /* Tarjetas principales */
    .search-card {
        padding: 1.25rem;
        margin-bottom: 1.25rem;
    }

    .content-card {
        padding: 1.25rem;
        margin-bottom: 1.5rem;
    }

    /* Formulario de Búsqueda adaptable en teléfonos */
    .search-form {
        flex-direction: column;
        gap: 0.65rem;
    }

    .search-select {
        width: 100%;
        /* Font-size 16px evita el zoom automático de iOS */
        font-size: 1rem; 
    }

    .search-input-group {
        width: 100%;
        min-width: 0;
        flex-direction: column;
        gap: 0.65rem;
    }

    .search-input {
        width: 100%;
        border-radius: 8px;
        font-size: 1rem;
    }

    .btn-search {
        width: 100%;
        padding: 0.85rem;
        border-radius: 8px;
        justify-content: center;
        font-size: 1rem;
    }

    /* Pestañas (Tabs) en Móviles */
    .nav-tabs {
        flex-direction: column;
        border-bottom: none;
        gap: 0.4rem;
    }

    .tab-button {
        width: 100%;
        justify-content: space-between;
        padding: 0.75rem 1rem;
    }

    /* Listado de Resultados */
    .results-list li {
        gap: 0.5rem;
        padding: 0.85rem 0;
    }

    .result-number {
        min-width: 20px;
        font-size: 0.9rem;
    }

    .book-title {
        font-size: 1rem;
    }

    .book-author, .book-publisher {
        font-size: 0.85rem;
    }

    /* Grid de Instituciones en 1 sola columna */
    .institution-grid {
        grid-template-columns: 1fr;
    }

    /* Paginación adaptable */
    .pagination {
        justify-content: center;
        gap: 0.3rem;
    }

    .page-item .page-link {
        padding: 0.5rem 0.7rem;
        font-size: 0.85rem;
    }
}
