:root {
    --color-primario: #324759;
    --color-primario-light: #46627c;
    --color-acento: #f24822;
    --color-acento-soft: rgba(242, 72, 34, 0.18);
    --color-fondo: #eef1f4;
    --color-panel: #1f2d3a;
    --color-panel-soft: #2a3a49;
    --color-texto: #202b35;
    --color-texto-claro: #f2f2f2;
    --color-borde: rgba(255, 255, 255, 0.1);
    --sombra: 0 14px 30px rgba(0, 0, 0, 0.18);
    --borde-radio: 14px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Roboto", sans-serif;
    background: radial-gradient(circle at top right, #5d7a96 0%, #324759 40%, #1a2630 100%);
    color: var(--color-texto);
    min-height: 100vh;
}

.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 25px 0;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.logo-header {
    height: 100px;
    max-height: none;
    width: auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.nav-links {
    display: flex;
    gap: 30px;
    align-items: center;
}

.nav-link {
    color: var(--color-primario);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.nav-link:hover {
    color: var(--color-acento);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--color-acento);
    transition: width 0.3s;
}

.nav-link:hover::after {
    width: 100%;
}

.main {
    max-width: 1400px;
    margin: 18px auto 0;
    padding: 0 20px 22px;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(300px, 40%) minmax(320px, 60%);
    gap: 18px;
    /* Altura fija: equivalente a ~7 book-cards para que el visor no se estire */
    height: calc(100vh - 200px);
    max-height: calc(100vh - 200px);
}

.panel {
    border-radius: var(--borde-radio);
    overflow: hidden;
    box-shadow: var(--sombra);
    min-height: 0; /* Permitir que el grid item se comprima */
}

.catalog-panel {
    background: linear-gradient(180deg, #223241 0%, #1d2935 100%);
    color: var(--color-texto-claro);
    display: flex;
    flex-direction: column;
}

.catalog-header {
    padding: 18px;
    border-bottom: 1px solid var(--color-borde);
}

.catalog-header h2 {
    margin: 0 0 8px;
    font-family: "Montserrat", sans-serif;
    font-size: 1.35rem;
}

.catalog-header p {
    margin: 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 0.93rem;
}

.catalog-controls {
    padding: 14px 18px;
    border-bottom: 1px solid var(--color-borde);
}

.search-input {
    width: 100%;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 11px 12px;
    font-size: 0.95rem;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    margin-bottom: 12px;
}

.search-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.filters-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.84rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    padding: 6px 10px;
}

.catalog-list {
    overflow-y: auto;
    padding: 14px;
    display: grid;
    gap: 12px;
    /* Scroll interno para que la lista no empuje el layout */
    flex: 1;
    min-height: 0;
}

.book-card {
    background: var(--color-panel-soft);
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 12px;
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.book-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
}

.book-card.selected {
    border-color: var(--color-acento);
    box-shadow: 0 0 0 2px var(--color-acento-soft);
}

.book-cover {
    width: 72px;
    height: 96px;
    border-radius: 8px;
    object-fit: cover;
    background: linear-gradient(135deg, #4f667d 0%, #2c3c4d 100%);
}

.book-meta h3 {
    margin: 0 0 6px;
    font-size: 0.98rem;
    font-family: "Montserrat", sans-serif;
}

.book-meta p {
    margin: 0;
    color: rgba(255, 255, 255, 0.86);
    font-size: 0.84rem;
}

.book-tag {
    margin-top: 6px;
    display: inline-block;
    border-radius: 999px;
    padding: 3px 8px;
    background: rgba(242, 72, 34, 0.16);
    color: #ffd1c6;
    font-size: 0.75rem;
    font-weight: 600;
}

.viewer-panel {
    background: #f7f8fa;
    display: flex;
    flex-direction: column;
    /* El visor no debe crecer más allá del workspace */
    min-height: 0;
    overflow: hidden;
}

.viewer-header {
    border-bottom: 1px solid #dce2e8;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.viewer-title h2 {
    margin: 0;
    font-family: "Montserrat", sans-serif;
    font-size: 1.1rem;
    color: var(--color-primario);
}

.viewer-title p {
    margin: 2px 0 0;
    color: #617486;
    font-size: 0.84rem;
}

.viewer-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn {
    border: none;
    border-radius: 10px;
    padding: 8px 12px;
    background: var(--color-primario);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.84rem;
}

.btn.secondary {
    background: #d9e2ea;
    color: #1f2d3a;
}

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

.page-indicator {
    cursor: pointer;
    user-select: none;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.2s ease;
    font-size: 0.88rem;
    white-space: nowrap;
}

.page-indicator:hover {
    background: rgba(50, 71, 89, 0.1);
}

.page-input {
    width: 60px;
    padding: 4px 6px;
    border: 2px solid var(--color-acento);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    color: var(--color-primario);
    background: #fff;
    outline: none;
}

.page-input::-webkit-inner-spin-button,
.page-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.page-input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.viewer-body {
    flex: 1;
    overflow: auto;
    padding: 18px;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, #edf1f4 0%, #e2e8ee 100%);
    /* Scroll interno para el PDF */
    min-height: 0;
}

#pdf-canvas {
    max-width: 100%;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.25);
    border-radius: 6px;
    background: #fff;
}

.state-box {
    text-align: center;
    color: #5a6772;
    max-width: 420px;
}

.state-box h3 {
    margin: 0 0 8px;
    font-family: "Montserrat", sans-serif;
    color: var(--color-primario);
}

.state-box p {
    margin: 0 0 14px;
    font-size: 0.92rem;
}

.spinner {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 4px solid rgba(50, 71, 89, 0.2);
    border-top-color: var(--color-acento);
    margin: 0 auto 12px;
    animation: spin 0.9s linear infinite;
}

.hidden {
    display: none !important;
}

.footer {
    color: rgba(255, 255, 255, 0.86);
    text-align: center;
    padding: 10px 16px 14px;
    font-size: 0.86rem;
}

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

@media (max-width: 980px) {
    .workspace {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
    }

    .catalog-panel {
        max-height: 50vh;
    }

    .catalog-list {
        max-height: none;
    }

    .viewer-panel {
        height: 70vh;
        min-height: 400px;
    }

    .logo-header {
        height: 60px;
    }

    .nav-links {
        flex-direction: column;
        gap: 15px;
    }
}
