/* =========================================================
   LIBRERIA — Solo recensioni, lettura a pagina piena
========================================================= */

html, body {
    height: 100%;
    overflow: hidden;
}

.library-page {
    --vish-green: #1B4332;
    --vish-purple: #4A3F6B;
    --vish-gold: #c9a84c;
    --vish-bg: #F8F8F6;
    --vish-white: #FFFFFF;
    --vish-text: #1a1a1a;
    --vish-text-secondary: #555550;
    --color-border-secondary: #e7e5e0;
    --border-radius-md: 8px;

    margin: -1.5rem -5px calc(-2rem - 2rem) -5px;
    height: calc(100vh - 65px - 1.5rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--vish-white);
    color: var(--vish-text);
}

/* =========================================================
   TOPBAR
========================================================= */

.library-topbar {
    position: relative;
    flex-shrink: 0;
    height: 52px;
    display: flex;
    align-items: center;
    padding: 0 18px;
    background: var(--vish-white);
    border-bottom: 1px solid #e7e5e0;
}

.library-topbar-left {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: baseline;
    gap: 12px;
    min-width: 0;
    max-width: calc(100% - 60px);
    overflow: hidden;
}

.library-topbar-left h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--vish-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-tags {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.library-tag {
    font-size: 11px;
    line-height: 1.4;
    padding: 2px 8px;
    border-radius: 999px;
    color: var(--vish-text-secondary);
    background: var(--vish-bg);
    border: 1px solid #e7e5e0;
    white-space: nowrap;
}

.library-topbar-buy {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
    color: #FF9900;
    text-decoration: none;
    border: 1px solid #FF9900;
    border-radius: 999px;
    padding: 4px 12px;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.library-topbar-buy:hover {
    background: #FF9900;
    color: #111;
}

.library-topbar-buy[hidden] {
    display: none;
}

/* =========================================================
   TAB MOBILE (Opzione A) — nascosta di default, mostrata solo
   sotto la soglia mobile (vedi @media più sotto). I 3 pannelli
   restano gli stessi nodi DOM del layout desktop a 3 colonne;
   qui si passa solo a "un pannello visibile alla volta".
========================================================= */

.library-mobile-tabs {
    display: none;
}

/* =========================================================
   BODY ROW
========================================================= */

.library-body {
    flex: 1;
    height: calc(100% - 52px);
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* =========================================================
   SIDEBAR SINISTRA — copertine
========================================================= */

.library-sidebar-left {
    flex-shrink: 0;
    width: 220px;
    min-width: 220px;
    height: 100%;
    background: var(--vish-bg);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 8px;
    box-sizing: border-box;
    border-right: 1px solid #e7e5e0;
}

.library-card-list {
    display: flex;
    flex-direction: column;
}

/* Card recensione */
.book-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 8px;
    border: 2px solid transparent;
    transition: all 0.2s;
    text-align: center;
}

.book-card:hover {
    background: #f3f4f6;
}

.book-card.active {
    border-color: var(--vish-green);
    background: rgba(27, 67, 50, 0.06);
}

/* Copertina placeholder — stesso template per tutte le recensioni */
.book-cover-placeholder {
    width: 80px;
    height: 110px;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    color: white;
    padding: 8px 6px;
    box-sizing: border-box;
    box-shadow: 2px 3px 8px rgba(0, 0, 0, 0.25);
    margin-bottom: 8px;
    background: linear-gradient(160deg, var(--vish-green) 0%, #24344a 55%, var(--vish-purple) 100%);
    border: 1px solid rgba(201, 168, 76, 0.35);
}

/* Copertina reale — stessa impronta (dimensioni/ombra) del placeholder */
.book-cover-img {
    width: 80px;
    height: 110px;
    border-radius: 4px;
    object-fit: cover;
    box-shadow: 2px 3px 8px rgba(0, 0, 0, 0.25);
    margin-bottom: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.book-cover-mark {
    font-family: Georgia, serif;
    font-size: 8px;
    letter-spacing: 0.18em;
    color: rgba(201, 168, 76, 0.85);
    text-transform: uppercase;
}

.book-cover-title {
    font-family: Georgia, serif;
    font-size: 10px;
    line-height: 1.3;
}

.book-card-title {
    font-size: 12px;
    font-weight: 600;
    color: #1f2937;
    line-height: 1.3;
    margin-bottom: 2px;
    text-decoration: none;
}

.book-card-author {
    font-size: 10px;
    color: #6b7280;
}

/* Link Amazon nella sidebar */
.book-card-amazon {
    display: inline-block;
    margin-top: 6px;
    font-size: 10px;
    font-weight: 600;
    color: #FF9900;
    text-decoration: none;
    border: 1px solid #FF9900;
    border-radius: 10px;
    padding: 2px 8px;
    transition: background 0.15s, color 0.15s;
}

.book-card-amazon:hover {
    background: #FF9900;
    color: #111;
}

/* =========================================================
   AREA DI LETTURA — SFOGLIO A LIBRO
========================================================= */

.library-reader {
    flex: 1;
    overflow: hidden;
    background: #e8e4df;
    box-sizing: border-box;
    position: relative;
    min-width: 0;
    height: 100%;
}

.library-reader-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--vish-text-secondary);
    font-size: 14px;
    font-family: Georgia, serif;
    font-style: italic;
}

.book-spread[hidden],
.library-reader-placeholder[hidden] {
    display: none;
}

.book-spread {
    display: flex;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    transition: opacity 0.15s ease;
}

.book-spread.spread-fade {
    opacity: 0;
}

.book-page {
    flex: 1;
    min-width: 0;
    height: 100%;
    background: #faf9f7;
    padding: 48px 56px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.12);
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.book-page-left {
    border-right: 1px solid #e2d9c8;
}

.book-page::before {
    content: 'ValueInvestorsHub.com';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 2.2rem;
    color: rgba(0, 0, 0, 0.08);
    pointer-events: none;
    white-space: nowrap;
    font-family: Georgia, serif;
    z-index: 0;
    user-select: none;
}

.book-cover-page::before {
    content: none;
}

.book-page > * {
    position: relative;
    z-index: 1;
}

.book-page-content {
    flex: 1;
    overflow: hidden;
}

.page-number {
    position: absolute;
    bottom: 20px;
    right: 28px;
    font-size: 0.8rem;
    color: #888;
    font-family: Georgia, serif;
    font-style: italic;
    z-index: 1;
}

/* Pagina di misurazione invisibile (off-screen) */
.book-page-measure {
    position: absolute;
    visibility: hidden;
    pointer-events: none;
    top: -9999px;
    left: -9999px;
    padding: 48px 56px;
    box-sizing: border-box;
    height: auto;
}

/* =========================================================
   COPERTINA (pagina 0) — stesso template per ogni recensione,
   cambiano solo i testi.
========================================================= */

.book-cover-page {
    color: #fff;
    padding: 0;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: linear-gradient(160deg, var(--vish-green) 0%, #24344a 55%, var(--vish-purple) 100%);
}

.book-cover-page::after {
    content: '';
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    bottom: 16px;
    border: 1.5px solid rgba(201, 168, 76, 0.5);
    pointer-events: none;
    z-index: 2;
}

.cover-header {
    position: absolute;
    top: 40px;
    left: 0;
    right: 0;
    text-align: center;
    z-index: 3;
}

.cover-brand {
    display: block;
    font-family: Georgia, serif;
    font-size: 1rem;
    letter-spacing: 0.2em;
    color: rgba(255, 255, 255, 0.85);
    text-transform: uppercase;
}

.cover-subtitle {
    display: block;
    font-family: Georgia, serif;
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    color: rgba(255, 255, 255, 0.55);
    margin-top: 8px;
    font-style: italic;
}

.cover-title {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    padding: 0 48px;
    text-align: center;
    z-index: 3;
}

.cover-title h1 {
    font-family: Georgia, serif;
    font-size: 2rem;
    color: #ffffff;
    letter-spacing: 0.04em;
    line-height: 1.3;
    margin: 0 0 16px;
    font-weight: normal;
}

.cover-title .cover-line {
    width: 60px;
    height: 2px;
    background: var(--vish-gold);
    margin: 0 auto 14px;
}

.cover-title .cover-author {
    font-family: Georgia, serif;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.cover-image-wrap {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    justify-content: center;
    z-index: 3;
}

.cover-image {
    max-width: min(70%, 260px);
    max-height: 62vh;
    object-fit: contain;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    border-radius: 2px;
}

.cover-footer {
    position: absolute;
    bottom: 32px;
    left: 40px;
    right: 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 3;
}

.cover-footer-meta {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 0.1em;
}

.cover-footer-page {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.35);
}

/* =========================================================
   BLOCCHI INTERNI
========================================================= */

.book-head {
    font-family: Georgia, serif;
    font-size: 1.15rem;
    font-weight: bold;
    color: #1a3a5c;
    margin: 1.5rem 0 1rem;
    border-bottom: 1px solid #e2d9c8;
    padding-bottom: 0.4rem;
}

.book-page-content > .book-head:first-child {
    margin-top: 0;
}

.book-p {
    font-family: Georgia, serif;
    font-size: 1.05rem;
    line-height: 1.85;
    color: #2d2d2d;
    margin: 0 0 1rem;
    text-align: justify;
    hyphens: auto;
}

.book-quote {
    border-left: 3px solid var(--vish-gold);
    padding: 10px 18px;
    background: #f5f0e8;
    font-style: italic;
    font-size: 0.95rem;
    margin: 1rem 0;
    color: #4a4a4a;
}

.book-quote p {
    margin: 0;
}

.book-quote cite {
    display: block;
    font-size: 0.8rem;
    color: #888;
    margin-top: 6px;
    font-style: normal;
    text-align: right;
}

/* =========================================================
   FRECCE LATERALI
========================================================= */

.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 200px;
    display: flex;
    align-items: center;
    opacity: 0.5;
    transition: opacity 0.2s;
    cursor: pointer;
    z-index: 10;
    pointer-events: all;
}

.nav-arrow:hover {
    opacity: 1;
}

.nav-arrow-left {
    left: 0;
    justify-content: flex-start;
    padding-left: 12px;
}

.nav-arrow-right {
    right: 0;
    justify-content: flex-end;
    padding-right: 12px;
}

.nav-arrow span {
    font-size: 3.5rem;
    color: #1a3a5c;
    opacity: 0.5;
    user-select: none;
}

.nav-arrow:hover span {
    opacity: 1;
}

/* =========================================================
   SIDEBAR DESTRA — I Nostri Libri
========================================================= */

.library-sidebar-right {
    flex-shrink: 0;
    width: 200px;
    min-width: 200px;
    height: 100%;
    border-left: 1px solid #e5e7eb;
    background: #f9fafb;
    padding: 16px 12px;
    overflow-y: auto;
    box-sizing: border-box;
}

.library-panel-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #1a3a5c;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 16px;
}

.our-book-card {
    margin-bottom: 20px;
    text-align: center;
    padding: 8px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.our-book-card:hover {
    background: #f3f4f6;
}

.our-book-card.active {
    border-color: var(--vish-green);
    background: rgba(27, 67, 50, 0.06);
}

.our-book-cover-img {
    width: 90px;
    height: 125px;
    border-radius: 4px;
    object-fit: cover;
    margin: 0 auto 8px;
    box-shadow: 2px 3px 8px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: block;
}

.our-book-title {
    font-size: 11px;
    font-weight: 600;
    color: #1f2937;
    display: block;
    margin-bottom: 4px;
    text-decoration: none;
}

.our-book-author {
    font-size: 10px;
    color: #6b7280;
    display: block;
    margin-bottom: 4px;
}

.our-book-amazon {
    display: inline-block;
    margin-top: 6px;
    font-size: 10px;
    font-weight: 600;
    color: #FF9900;
    text-decoration: none;
    border: 1px solid #FF9900;
    border-radius: 10px;
    padding: 2px 8px;
    transition: background 0.15s, color 0.15s;
}

.our-book-amazon:hover {
    background: #FF9900;
    color: #111;
}

/* =========================================================
   RESPONSIVE — MOBILE
========================================================= */

@media (max-width: 768px) {
    .library-mobile-tabs {
        display: flex;
        flex-shrink: 0;
        height: 44px;
        border-bottom: 1px solid #e7e5e0;
        background: var(--vish-white);
    }

    .library-mobile-tab {
        flex: 1;
        border: none;
        background: transparent;
        font-family: inherit;
        font-size: 13px;
        font-weight: 600;
        color: var(--vish-text-secondary);
        cursor: pointer;
        border-bottom: 2px solid transparent;
    }

    .library-mobile-tab.active {
        color: var(--vish-green);
        border-bottom-color: var(--vish-green);
    }

    .library-body {
        height: calc(100% - 52px - 44px);
    }

    /* Un solo pannello visibile alla volta, scelto da libreria.js via
       data-active-panel su #library-body (vedi setActivePanel()). Gli
       altri due sono display:none — restano flex-child rimossi dal
       flusso, quindi quello visibile (flex:1 preesistente su
       .library-reader, o qui forzato sulle sidebar) riempie da solo
       tutta la larghezza, senza toccare .library-body stesso. */
    .library-sidebar-left,
    .library-reader,
    .library-sidebar-right {
        display: none;
        width: 100%;
        min-width: 0;
        flex: 1 1 auto;
    }

    .library-body[data-active-panel="index"] .library-sidebar-left,
    .library-body[data-active-panel="reader"] .library-reader,
    .library-body[data-active-panel="books"] .library-sidebar-right {
        display: block;
    }

    /* bordi di separazione tra colonne: superflui con un solo pannello visibile */
    .library-sidebar-left {
        border-right: none;
    }

    .library-sidebar-right {
        border-left: none;
    }

    .book-spread {
        position: relative;
    }

    .book-page-left {
        display: none;
    }

    .book-page-right {
        flex: 1 0 100%;
    }

    .nav-arrow {
        width: 44px;
        height: 140px;
    }

    .nav-arrow span {
        font-size: 2.5rem;
    }

    .book-page {
        padding: 32px 24px;
    }

    .book-page-measure {
        padding: 32px 24px;
    }
}
