/* ============================================================
   KANUPAPA E-LIBRARY (కనుపాప గ్రంథాలయం) STYLESHEET
   Smart TV & Mobile Large-Print PDF Reader
   ============================================================ */

.library-section {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 20px 40px;
    animation: fadeIn 0.25s ease-out;
}

.library-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-library-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(30, 41, 59, 0.85);
    color: #f1f5f9;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-library-back:hover,
.btn-library-back:focus {
    background: #0284c7;
    border-color: #38bdf8;
    transform: translateY(-1px);
    outline: none;
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.4);
}

.library-header-title {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #f59e0b, #f97316);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 10px;
}

.library-filter-bar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.library-top-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

/* Language Dropdown Selector */
.library-lang-dropdown-wrap {
    min-width: 140px;
    max-width: 170px;
}

.library-lang-select {
    width: 100%;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.95);
    color: #38bdf8;
    border: 1.5px solid rgba(56, 189, 248, 0.4);
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    outline: none;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.library-lang-select:focus,
.library-lang-select:hover {
    border-color: #38bdf8;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

/* Sub-category Dropdown */
.library-cat-dropdown-wrap {
    min-width: 250px;
    flex: 1;
    max-width: 380px;
}

.library-cat-select {
    width: 100%;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.9);
    color: #f1f5f9;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.library-cat-select:focus,
.library-cat-select:hover {
    border-color: #38bdf8;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

.library-search-input-wrap {
    width: 100%;
}

.library-search-input {
    width: 100%;
    padding: 10px 16px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: #ffffff;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.library-search-input:focus {
    border-color: #0ea5e9;
    box-shadow: 0 0 14px rgba(14, 165, 233, 0.3);
}

/* ========================================================
   COMPACT INDEX TABLE VIEW (Eliminates excessive scrolling)
   ======================================================== */
.library-table-container {
    width: 100%;
    overflow-x: auto;
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    margin-bottom: 20px;
}

.library-index-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.library-index-table thead tr {
    background: rgba(30, 41, 59, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.library-index-table th {
    padding: 12px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.library-book-row {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
    user-select: none;
}

.library-book-row:last-child {
    border-bottom: none;
}

.library-book-row:hover {
    background: rgba(56, 189, 248, 0.1);
}

.library-book-row:focus {
    background: rgba(14, 165, 233, 0.2);
    outline: 2px solid #38bdf8;
    outline-offset: -2px;
}

.library-book-row td {
    padding: 12px 14px;
    vertical-align: middle;
}

.book-row-icon {
    font-size: 1.4rem;
    display: inline-block;
}

.book-row-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.book-row-title {
    font-size: 1rem;
    font-weight: 700;
    color: #f8fafc;
    line-height: 1.35;
}

.book-row-author {
    font-size: 0.8rem;
    color: #f59e0b;
    font-weight: 500;
}

.book-row-bookmark {
    font-size: 0.72rem;
    color: #34d399;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.35);
    padding: 2px 8px;
    border-radius: 6px;
    align-self: flex-start;
    margin-top: 3px;
    font-weight: 600;
}

.book-row-cat-pill {
    font-size: 0.8rem;
    font-weight: 600;
    color: #cbd5e1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 4px 10px;
    border-radius: 8px;
    display: inline-block;
    white-space: nowrap;
}

.book-row-pages-badge {
    font-size: 0.85rem;
    font-weight: 700;
    color: #e2e8f0;
    white-space: nowrap;
}

.btn-table-read {
    padding: 7px 14px;
    background: linear-gradient(135deg, #0284c7, #0ea5e9);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, filter 0.15s ease;
    white-space: nowrap;
}

.library-book-row:hover .btn-table-read,
.library-book-row:focus .btn-table-read {
    filter: brightness(1.15);
    transform: scale(1.05);
}

/* ========================================================
   DEDICATED MOBILE 2-LINE CLEAN LIST VIEW
   ======================================================== */
.library-mobile-list {
    display: none;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    margin-bottom: 20px;
}

.mobile-book-item {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mobile-book-item:active,
.mobile-book-item:focus {
    background: rgba(14, 165, 233, 0.18);
    border-color: #38bdf8;
    transform: scale(0.99);
    outline: none;
}

.mobile-book-line1 {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.mobile-book-title {
    font-size: 0.96rem;
    font-weight: 700;
    color: #f8fafc;
    line-height: 1.35;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-book-pages {
    font-size: 0.78rem;
    font-weight: 700;
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.25);
    padding: 2px 7px;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.mobile-book-line2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.mobile-book-author {
    font-size: 0.8rem;
    color: #f59e0b;
    font-weight: 500;
}

.mobile-book-bookmark {
    font-size: 0.72rem;
    color: #34d399;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.35);
    padding: 2px 7px;
    border-radius: 6px;
    font-weight: 600;
    white-space: nowrap;
}

/* Legal Notice Banner */
.library-legal-notice {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    color: #94a3b8;
    font-size: 0.82rem;
    line-height: 1.45;
}

.legal-notice-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.legal-notice-text strong {
    color: #f1f5f9;
    display: block;
    margin-bottom: 2px;
}

.book-cover-banner {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.book-cover-icon {
    font-size: 2.8rem;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
}

.book-category-badge {
    background: rgba(0, 0, 0, 0.4);
    color: #ffffff;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 0.82rem;
    font-weight: 700;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.book-card-body {
    padding: 18px 20px 20px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.book-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: #f8fafc;
    margin-bottom: 6px;
    line-height: 1.4;
}

.book-author {
    font-size: 0.92rem;
    color: #f59e0b;
    font-weight: 600;
    margin-bottom: 10px;
}

.book-desc {
    font-size: 0.92rem;
    color: #94a3b8;
    line-height: 1.5;
    flex: 1;
    margin-bottom: 14px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-resume-tag {
    background: rgba(16, 185, 129, 0.18);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.35);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.book-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.book-size-tag {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 600;
}

.btn-read-book {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    color: #ffffff;
    border: 1px solid rgba(56, 189, 248, 0.4);
    padding: 8px 18px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-read-book:hover,
.btn-read-book:focus {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    box-shadow: 0 0 16px rgba(14, 165, 233, 0.4);
    outline: none;
}

/* ============================================================
   FULLSCREEN TV BOOK READER MODAL
   ============================================================ */

.book-reader-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background 0.3s ease;
}

.book-reader-modal.hidden {
    display: none !important;
}

/* Eye Comfort Themes */
.book-reader-modal.theme-sepia {
    background: #fbf0d9;
    color: #382a17;
}

.book-reader-modal.theme-sepia #book-reader-canvas {
    box-shadow: 0 8px 30px rgba(56, 42, 23, 0.25);
}

.book-reader-modal.theme-night {
    background: #090d16;
    color: #e2e8f0;
}

.book-reader-modal.theme-night #book-reader-canvas {
    filter: invert(90%) hue-rotate(180deg) contrast(108%);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8);
}

.book-reader-modal.theme-day {
    background: #e2e8f0;
    color: #0f172a;
}

.book-reader-modal.theme-day #book-reader-canvas {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

/* Persistent Always-Visible Back to Library Button */
.btn-reader-persistent-back {
    position: fixed;
    top: 10px;
    left: 14px;
    z-index: 120;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(15, 23, 42, 0.94);
    color: #38bdf8;
    border: 1.5px solid rgba(56, 189, 248, 0.5);
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 0.92rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(14px);
    transition: all 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-reader-persistent-back:hover,
.btn-reader-persistent-back:focus {
    background: #0284c7;
    color: #ffffff;
    border-color: #7dd3fc;
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.6);
    transform: scale(1.04);
    outline: none;
}

.btn-reader-persistent-back:active {
    transform: scale(0.96);
}

/* Floating Toolbar */
.book-reader-toolbar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px 20px 10px 155px; /* Offset for persistent back button */
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.book-reader-toolbar.toolbar-hidden {
    transform: translateY(-105%);
    opacity: 0;
    pointer-events: none;
}

.reader-toolbar-left,
.reader-toolbar-center,
.reader-toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.book-reader-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: #f8fafc;
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-reader-ctrl {
    background: rgba(30, 41, 59, 0.85);
    color: #f1f5f9;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-reader-ctrl:hover,
.btn-reader-ctrl:focus {
    background: #0284c7;
    border-color: #38bdf8;
    color: #ffffff;
    outline: none;
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.4);
}

.book-page-indicator {
    font-size: 1rem;
    font-weight: 800;
    color: #38bdf8;
    background: rgba(15, 23, 42, 0.8);
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.book-zoom-badge {
    font-size: 0.9rem;
    font-weight: 700;
    color: #f59e0b;
}

/* Canvas Viewport */
.book-reader-canvas-container {
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 80px 20px 40px;
    scroll-behavior: smooth;
}

#book-reader-canvas {
    max-width: 96%;
    height: auto;
    border-radius: 6px;
    margin: 0 auto;
    transition: filter 0.2s ease;
}

/* Loading & Spinners */
.book-reader-loader {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 150;
    color: #f1f5f9;
}

.book-spinner-circle {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: #f97316;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

/* Floating Mobile Dock (Library & Panchangam side-by-side) */
.mobile-bottom-left-dock {
    display: none;
    position: fixed;
    bottom: 22px;
    left: 14px;
    z-index: 95;
    align-items: center;
    gap: 8px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-mobile-bottom-library,
.btn-mobile-bottom-panchang {
    display: flex;
    position: static;
    height: 48px;
    padding: 0 16px 0 12px;
    border-radius: 9999px;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.25);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-mobile-bottom-library {
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
    color: #ffffff;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.45);
}

.btn-mobile-bottom-panchang {
    background: linear-gradient(135deg, #d97706, #b45309);
    color: #ffffff;
    box-shadow: 0 8px 20px rgba(217, 119, 6, 0.45);
}

.btn-mobile-bottom-library:hover,
.btn-mobile-bottom-panchang:hover {
    transform: scale(1.04);
}

.btn-mobile-bottom-library:active,
.btn-mobile-bottom-panchang:active {
    transform: scale(0.95);
}

.btn-mobile-bottom-library .lib-floating-icon,
.btn-mobile-bottom-panchang .panchang-floating-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.btn-mobile-bottom-library .lib-floating-text,
.btn-mobile-bottom-panchang .panchang-floating-text {
    letter-spacing: 0.3px;
    white-space: nowrap;
}

/* Dedicated Bottom Navigation Bar for PDF Reader */
.book-reader-bottom-bar {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
    background: rgba(15, 23, 42, 0.96);
    backdrop-filter: blur(18px);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    z-index: 105;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.45);
}

.book-reader-bottom-bar.toolbar-hidden {
    transform: translateY(105%);
    opacity: 0;
    pointer-events: none;
}

.btn-reader-page-nav {
    flex: 1;
    max-width: 150px;
    height: 50px;
    background: rgba(30, 41, 59, 0.95);
    border: 1.5px solid rgba(56, 189, 248, 0.45);
    color: #ffffff;
    border-radius: 14px;
    font-size: 1.08rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.18s ease;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    -webkit-tap-highlight-color: transparent;
}

.btn-reader-page-nav:active {
    transform: scale(0.94);
}

.btn-reader-page-nav.next-page-nav {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    border-color: #38bdf8;
    color: #ffffff;
}

.btn-reader-page-nav.prev-page-nav {
    background: linear-gradient(135deg, #334155, #1e293b);
    border-color: rgba(148, 163, 184, 0.4);
    color: #e2e8f0;
}

.btn-reader-page-nav:disabled,
.btn-reader-page-nav[disabled] {
    opacity: 0.35;
    pointer-events: none;
}

.reader-page-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    text-align: center;
    user-select: none;
}

.reader-page-status .page-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #94a3b8;
    letter-spacing: 0.5px;
    line-height: 1;
    margin-bottom: 2px;
}

.reader-page-status .page-numbers {
    font-size: 1.15rem;
    font-weight: 900;
    color: #38bdf8;
    line-height: 1.2;
}

@media (max-width: 768px) {
    /* 1. Eliminate bulky header to save 25% screen space on mobile */
    .library-header-row {
        display: none !important;
    }

    .library-section {
        padding: 10px 10px 30px;
    }

    .library-filter-bar {
        gap: 8px;
        margin-bottom: 12px;
    }

    /* 2. Top controls compact layout */
    .library-top-controls {
        flex-direction: row;
        gap: 8px;
        flex-wrap: nowrap;
    }

    .library-lang-dropdown-wrap {
        width: 120px;
        min-width: 110px;
        flex-shrink: 0;
    }

    .library-cat-dropdown-wrap {
        flex: 1;
        min-width: 0;
        max-width: none;
    }

    .library-lang-select,
    .library-cat-select {
        padding: 9px 10px;
        font-size: 0.88rem;
    }

    .library-search-input {
        padding: 8px 12px;
        font-size: 0.88rem;
    }

    /* 3. Hide desktop table, show dedicated mobile clean 2-line list */
    .library-table-container {
        display: none !important;
    }

    .library-mobile-list {
        display: flex !important;
    }

    .mobile-bottom-left-dock {
        display: flex !important;
    }

    .btn-mobile-bottom-library,
    .btn-mobile-bottom-panchang {
        display: flex !important;
    }

    .book-reader-bottom-bar {
        display: flex;
    }

    .book-reader-title {
        max-width: 130px;
        font-size: 0.9rem;
    }

    .reader-toolbar-center {
        display: none;
    }

    .btn-reader-persistent-back {
        padding: 6px 12px;
        font-size: 0.85rem;
        top: 8px;
        left: 8px;
    }

    .book-reader-toolbar {
        padding: 8px 12px 8px 115px;
    }

    .book-reader-canvas-container {
        padding: 62px 6px 82px 6px;
    }

    .library-legal-notice {
        padding: 10px 12px;
        font-size: 0.78rem;
    }
}

body.role-mobile .library-header-row {
    display: none !important;
}

body.role-mobile .library-table-container {
    display: none !important;
}

body.role-mobile .library-mobile-list {
    display: flex !important;
}

body.role-mobile .mobile-bottom-left-dock {
    display: flex !important;
}

body.role-mobile .btn-mobile-bottom-library,
body.role-mobile .btn-mobile-bottom-panchang {
    display: flex !important;
}

body.role-mobile .book-reader-bottom-bar {
    display: flex;
}

body.role-mobile .reader-toolbar-center {
    display: none;
}

body.role-mobile .book-reader-canvas-container {
    padding: 62px 6px 82px 6px;
}

