/* ==========================================
   GLOBAL LAYOUT & GRID
   ========================================== */
/* ==========================================
   PLUGIN CSS SHIELD (Overrides Theme Leakage)
   ========================================== */
/* Reset Box Sizing for all our elements so theme padding doesn't break grids */
.pub-container *, .pub-global-nav * {
    box-sizing: border-box !important;
}

/* Shield Inputs and Forms from Theme styles */
.pub-global-nav input[type="search"], 
.pub-global-nav input[type="text"],
.pub-sidebar-filters input[type="search"] {
    margin: 0 !important;
    box-shadow: none !important;
    height: auto !important;
    line-height: 1.5 !important;
}

/* Shield Lists (Stops theme from adding bullets or huge margins to our grids) */
.pub-specs-grid, .pub-filter-list, .pub-tab-links {
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
}
.pub-specs-grid li, .pub-filter-list li, .pub-tab-links li {
    background: transparent !important;
    border: none !important;
    list-style-type: none !important;
}
.pub-specs-grid li::before, .pub-filter-list li::before, .pub-tab-links li::before {
    display: none !important; /* Hides custom bullets injected by Graphene */
    content: none !important;
}

/* Force baseline for all Dashicons inside our plugin */
.pub-container .dashicons, .pub-global-nav .dashicons {
    vertical-align: middle;
    text-decoration: none !important;
}

.pub-container { max-width: 1200px; margin: 0 auto; padding: 20px 20px 80px 20px; /* Added 80px of padding to the bottom to clear the FAB! */ }

/* Grid Layout for Archive & Shortcodes (Compact Mobile-First) */
.pub-grid-container { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 768px) { .pub-grid-container { grid-template-columns: repeat(3, 1fr); gap: 20px; } }
@media (min-width: 1024px) { .pub-grid-container { grid-template-columns: repeat(4, 1fr); } }

/* ==========================================
   GLOBAL NAVIGATION BAR
   ========================================== */
.pub-global-nav {
    max-width: 1200px; margin: 0 auto 30px auto; box-sizing: border-box;
    display: flex; flex-wrap: wrap; gap: 15px; align-items: center; justify-content: space-between;
    background: #2c3e50; color: #fff; padding: 10px 20px; border-radius: 6px;
}
.pub-nav-link { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 6px; font-weight: bold; transition: color 0.2s; }
.pub-nav-link:hover { color: #f0ad4e; }
.pub-nav-right { margin-left: auto; }
.pub-nav-search { display: flex; flex: 1; max-width: 400px; margin: 0 15px; }
.pub-nav-search input { flex: 1; padding: 6px 12px; border: none; border-radius: 4px 0 0 4px; outline: none; color: #333; background-color: #fff; }
/* Shielded Search Button & Icon Alignment */
.pub-nav-search button { 
    background: #f0ad4e !important; 
    border: none !important; 
    padding: 6px 12px !important; 
    color: #fff !important; 
    cursor: pointer !important; 
    border-radius: 0 4px 4px 0 !important; 
    
    /* Forces absolute vertical and horizontal centering */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 35px !important; /* Prevents theme from squishing it */
}

.pub-nav-search button:hover { 
    background: #e67e22 !important; 
}

/* Strip theme margins/paddings off the icon itself */
.pub-nav-search button .dashicons {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    height: 20px !important;
    width: 20px !important;
    display: flex !important;
    align-items: center !important;
}

@media (max-width: 768px) {
    .pub-global-nav { 
        position: sticky; top: 0; z-index: 9999; flex-direction: row; flex-wrap: nowrap;
        padding: 8px 10px; margin: 0; width: 100%; border-radius: 0; box-shadow: 0 2px 10px rgba(0,0,0,0.2); justify-content: space-between;
    }
    .pub-nav-text { display: none !important; } 
    .pub-nav-link { flex: 0 0 auto; padding: 4px; }
    .pub-nav-search { flex: 1 1 auto; min-width: 0; margin: 0 10px; }
    .pub-nav-search input { width: 100%; min-width: 0; padding: 6px 10px; font-size: 16px; }
    .pub-nav-search button { flex: 0 0 auto; }
}

/* ==========================================
   BOOK CARDS (Grid Items)
   ========================================== */
.pub-card { border: 1px solid #eee; border-radius: 8px; overflow: hidden; padding: 10px; text-align: center; background: #fff; }

/* Typography */
.pub-card-title { font-size: 1em; margin: 8px 0; line-height: 1.3; }
.pub-card-title a, .pub-mini-title { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; }
.pub-card-price strong { color: #747474; font-size: 1.1em; }
.pub-card-price del { color: #999; margin-right: 5px; font-size: 0.9em; }

@media (max-width: 767px) { .pub-card-excerpt { display: none; } }
@media (min-width: 768px) {
    .pub-card { padding: 15px; }
    .pub-card-title { font-size: 1.1em; margin: 10px 0; }
    .pub-card-price strong { font-size: 1.2em; }
    .pub-card-excerpt { display: block; }
}

/* Badges (New, Promo, etc.) */
.pub-card-image { position: relative; } 
.pub-badge-container { position: absolute; top: 10px; left: -5px; z-index: 10; display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.pub-badge {
    background-color: #34495e; color: #fff; font-size: 0.75em; font-weight: bold;
    text-transform: uppercase; letter-spacing: 1px; padding: 4px 10px; border-radius: 0 4px 4px 0; box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
}
.pub-badge-new { background-color: #27ae60; }        
.pub-badge-promo { background-color: #e74c3c; }      
.pub-badge-bestseller { background-color: #f39c12; } 
.pub-badge-staffpick { background-color: #8e44ad; }  

/* Format Icons Overlay on Grid Cards */
.pub-card-format-icons {
    position: absolute; bottom: 0; left: 0; width: 100%; background: rgba(44, 62, 80, 0.85); color: #fff;
    display: flex; justify-content: center; gap: 12px; padding: 6px 0; border-radius: 0 0 2px 2px; backdrop-filter: blur(2px);
}
.pub-card-format-icons .dashicons { font-size: 16px; width: 16px; height: 16px; opacity: 0.9; }
.pub-card-format-icons:hover .dashicons { opacity: 1; }

/* ==========================================
   SINGLE BOOK PAGE
   ========================================== */
.pub-single-header { display: flex; flex-direction: column; gap: 30px; margin-bottom: 40px; }
@media (min-width: 768px) { .pub-single-header { flex-direction: row; } .pub-single-image { flex: 0 0 35%; } .pub-single-meta { flex: 1; } }

.pub-single-title { margin-top: 0; font-size: 2em; line-height: 1.2; }
.pub-meta-list p { margin: 5px 0; color: #555; }
.pub-meta-list a { color: #0066cc; text-decoration: none; }
.pub-meta-list a:hover { text-decoration: underline; }

.pub-single-image .pub-badge-container { top: 15px; left: -8px; }
.pub-single-image .pub-badge { font-size: 0.9em; padding: 6px 14px; }

/* Book Status Badge */
.pub-book-status { 
    display: inline-flex; 
    align-items: center; 
    gap: 5px; 
    padding: 4px 10px; 
    margin-top: 5px; /* FIXED: Changed from -10px so it sits cleanly below multi-line titles */
    margin-bottom: 15px; 
    border-radius: 4px; 
    font-size: 0.85em; 
    font-weight: bold; 
}
.pub-status-out { background-color: #fdf2e9; color: #e67e22; border: 1px solid #fad7a1; }
.pub-status-obs { background-color: #f9ebea; color: #c0392b; border: 1px solid #f5b7b1; }

/* Pricing & Action Buttons */
.pub-pricing-block { margin: 20px 0; padding: 15px 0; border-top: 1px dashed #ccc; border-bottom: 1px dashed #ccc; }
.pub-price-main strong, .pub-price-discount strong { font-size: 1.5em; color: #747474; margin-left: 10px; }
.pub-price-discount del { color: #888; font-size: 1.1em; }

.pub-action-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.pub-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; border: none; cursor: pointer; border-radius: 4px; font-weight: bold; }
.pub-btn-preview { background-color: #f0ad4e; color: #fff; }
.pub-btn-buy { background-color: #27ae60; color: #fff; text-decoration: none; transition: background 0.3s; }
.pub-btn-buy:hover { background-color: #219653; color: #fff; }
.pub-btn-favorite { background-color: #ecf0f1; color: #333; border: 1px solid #ccc; transition: all 0.2s ease-in-out; }
.pub-btn-favorite:hover { background-color: #e0e6ed; }
.pub-btn-favorite.is-favorited { background-color: #e74c3c !important; color: #fff !important; border-color: #c0392b !important; }
.pub-btn-view-favs { background-color: #8e44ad; color: #fff; text-decoration: none; transition: background 0.3s; }
.pub-btn-view-favs:hover { background-color: #732d91; color: #fff; }

/* Format Switcher Styles */
.pub-format-switcher { margin: 20px 0; padding-top: 15px; border-top: 1px dashed #ccc; }
.pub-format-label { margin-top: 0; margin-bottom: 10px; font-size: 0.95em; color: #555; }
.pub-format-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.pub-format-btn { padding: 8px 16px; border: 2px solid #bdc3c7; border-radius: 4px; color: #555; text-decoration: none; font-size: 0.95em; font-weight: 600; transition: all 0.2s ease-in-out; background-color: #fff; }
.pub-format-btn:hover { border-color: #2c3e50; color: #2c3e50; background-color: #f8f9fa; }
.pub-format-btn.active { background-color: #2c3e50; border-color: #2c3e50; color: #fff; cursor: default; pointer-events: none; }

/* Social Sharing Box */
.pub-social-share-box { margin-top: 25px; padding-top: 15px; border-top: 1px solid #eee; display: flex; align-items: center; gap: 12px; }
.pub-share-label { font-size: 0.9em; color: #888; font-weight: bold; }
.pub-share-icon { display: inline-flex; align-items: center; justify-content: center; width: 35px; height: 35px; border-radius: 50%; color: #fff; text-decoration: none; cursor: pointer; border: none; transition: transform 0.2s; }
.pub-share-icon:hover { transform: scale(1.1); color: #fff; }
.pub-share-icon svg, .pub-share-icon .dashicons { margin-top: 2px; }
.pub-wa { background-color: #25D366; } .pub-fb { background-color: #1877F2; } .pub-copy { background-color: #7f8c8d; }

/* ==========================================
   IMAGE GALLERY & BOOK COVERS
   ========================================== */

/* 1. Base Gallery Container (Restores the 15px gap!) */
.pub-image-gallery-container { 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    width: 100%;
}

/* Single Book Image */
.pub-single-image img { 
    width: 100%; 
    height: auto; 
    object-fit: contain; 
    border-radius: 2px 6px 6px 2px;
}

/* 2. Desktop Split-Screen Sizing (Smart Portrait/Horizontal Sizing) */
@media (min-width: 768px) {
    .pub-single-header { 
        gap: 40px; /* Keeps a nice wide gap between the cover and text column */
    }
    
    .pub-image-gallery-container { 
        /* Smart Flex Formula: Starts at 35% for Portrait, grows up to 45% for Horizontal */
        flex: 1 1 35% !important; 
        min-width: 30%; 
        max-width: 45%; 
    } 
    
    .pub-single-meta { 
        flex: 2 1 0%; /* Safely fills the remaining right-side space */
    }
}

/* 3. Grid Card Wrappers (Holds the height uniform) */
.pub-card-image { 
    position: relative; 
    height: 220px !important; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    background-color: transparent !important;
}
.pub-card-image a {
    display: flex; 
    align-items: center; 
    justify-content: center; 
    width: 100%; 
    height: 100%;
}

/* 4. The Actual Images (Allows the 3D shadow to strictly hug the cover) */
.pub-single-image img, 
.pub-card-image img { 
    max-width: 100%; 
    max-height: 100%; 
    width: auto !important; 
    height: auto !important; 
    object-fit: initial !important; /* Disables forced bounds */
    background-color: transparent !important; /* Strips away any white bleed */
}

/* 5. Mini Sidebar Cards (Keeps them tiny, but removes white boxes) */
.pub-mini-item img {
    width: 55px !important; 
    height: auto !important; 
    max-height: 85px; 
    object-fit: initial !important; 
    background-color: transparent !important;
}

/* 6. Ensure the 3D Shadow is properly applied without any white edges */
.pub-book-cover, 
.pub-card-image img, 
.pub-mini-item img {
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.15), -1px 0 3px rgba(0, 0, 0, 0.05);
    border-radius: 2px 6px 6px 2px; 
    
    /* CRITICAL FIX: Strip all spine effects, theme borders, and theme padding */
    border: none !important; 
    padding: 0 !important;
    background-color: transparent !important; 
    
    transition: transform 0.3s ease, box-shadow 0.3s ease; 
    display: block;
}

/* Restored the hover floating animation for all covers */
.pub-book-cover:hover, 
.pub-card-image a:hover img, 
.pub-mini-item a:hover img {
    transform: translateY(-5px); 
    box-shadow: 8px 12px 20px rgba(0, 0, 0, 0.2), -1px 0 3px rgba(0, 0, 0, 0.05);
}

.pub-gallery-thumbnails { display: flex; gap: 10px; flex-wrap: wrap; }
.pub-thumb { width: 60px; height: 80px; object-fit: cover; cursor: pointer; border: 2px solid transparent; border-radius: 4px; opacity: 0.6; transition: all 0.3s ease; }
.pub-thumb:hover { opacity: 1; transform: translateY(-2px); }
.pub-thumb.active { border-color: #f0ad4e; opacity: 1; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }

/* Tabs & Specs */
.pub-tabs-section { margin-top: 20px; }
.pub-tab-links { list-style: none; padding: 0; display: flex; flex-wrap: wrap; border-bottom: 2px solid #ddd; margin-bottom: 20px; }
.pub-tab-links li { margin-right: 5px; }
.pub-tab-links a { display: block; padding: 10px 20px; text-decoration: none; color: #333; background: #f9f9f9; border-radius: 4px 4px 0 0; }
.pub-tab-links li.active a { background: #fff; border: 1px solid #ddd; border-bottom: none; margin-bottom: -2px; font-weight: bold;}
.pub-tab-content { display: none; padding: 20px; border: 1px solid #ddd; background: #fff; }
.pub-tab-content.active { display: block; }
.pub-formatted-text p { margin-bottom: 15px; line-height: 1.6; }
.pub-section-title { margin-bottom: 20px; font-size: 1.5em; border-left: 4px solid #f0ad4e; padding-left: 10px; }

/* Specs Grid */
.pub-specs-box { background: #fdfdfd; border: 1px solid #eaeaea; border-radius: 8px; padding: 25px; margin: 0; }
.pub-specs-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 600px) { .pub-specs-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .pub-specs-grid { grid-template-columns: repeat(3, 1fr); gap: 25px 20px; } }
.pub-specs-grid li { font-size: 0.95em; color: #444; line-height: 1.5; position: relative; padding-left: 30px; }
.pub-specs-grid li .dashicons { position: absolute; left: 0; top: 2px; color: #999; font-size: 20px; }
.pub-specs-grid li strong { color: #222; font-size: 0.9em; text-transform: uppercase; letter-spacing: 0.5px; }

/* Video Gallery (Multi-Video) */
.pub-video-section { margin-top: 40px; }
.pub-video-gallery-layout { display: flex; flex-direction: column; gap: 15px; }
.pub-video-main { flex: 1; }
.pub-video-wrapper { position: relative; padding-bottom: 56.25%; height: 0; }
.pub-video-wrapper iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.pub-video-playlist { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 5px; }
.pub-video-thumb { flex: 0 0 120px; position: relative; cursor: pointer; border: 2px solid transparent; border-radius: 4px; transition: all 0.2s; }
.pub-video-thumb img { width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 2px; opacity: 0.7; display: block; }
.pub-video-thumb:hover img, .pub-video-thumb.active img { opacity: 1; }
.pub-video-thumb.active { border-color: #e74c3c; }
.pub-video-play-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #fff; background: rgba(0,0,0,0.6); border-radius: 50%; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; pointer-events: none; }
@media (min-width: 768px) {
    .pub-video-gallery-layout { flex-direction: row; }
    .pub-video-main { flex: 0 0 75%; }
    .pub-video-playlist { flex: 1; flex-direction: column; overflow-y: auto; max-height: 450px; }
    .pub-video-thumb { flex: 0 0 auto; width: 100%; }
}

/* Modals */
.pub-modal { display: none; position: fixed; z-index: 99999; left: 0; top: 0; width: 100%; height: 100%; align-items: center; justify-content: center;}
.pub-modal-backdrop { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.85); backdrop-filter: blur(5px); }
.pub-modal-content { background: #f5f5f5; width: 95%; max-width: 1000px; height: 90vh; position: relative; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); display: flex; flex-direction: column; overflow: hidden; }
.pub-modal-content iframe { width: 100%; height: 100%; border: none; position: relative; z-index: 2; }
.pub-modal-close { position: absolute; top: 10px; right: 10px; background: #e74c3c; color: white; border: none; border-radius: 4px; width: 40px; height: 40px; cursor: pointer; z-index: 10; display: flex; align-items: center; justify-content: center; transition: background 0.3s; }
.pub-modal-close:hover { background: #c0392b; }
.pub-iframe-loader { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #666; font-size: 1.2em; display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 1; }
.pub-iframe-loader .dashicons-update { font-size: 40px; width: 40px; height: 40px; animation: pub-spin 2s linear infinite; }
@keyframes pub-spin { 100% { transform: rotate(360deg); } }

/* Better UX: Shrink the Single Book cover on mobile */
@media (max-width: 767px) {
    .pub-single-image {
        max-width: 65%;
        margin: 0 auto 20px auto; /* Centers the image perfectly */
    }
}

/* ==========================================
   ARCHIVE PAGE & SIDEBARS
   ========================================== */
.pub-archive-header { margin-bottom: 40px; text-align: center; border-bottom: 1px solid #eee; padding-bottom: 20px;}
.pub-archive-title { font-size: 2.5em; margin-bottom: 10px; color: #2c3e50; }
.pub-archive-layout { display: flex; flex-direction: column; gap: 40px; }
@media (min-width: 768px) {
    .pub-archive-layout { flex-direction: row; align-items: flex-start; }
    .pub-sidebar-filters { flex: 0 0 250px; position: sticky; top: 20px; }
    .pub-main-catalog { flex: 1; }
}

/* Sidebar Widgets */
.pub-filter-widget { background: #fdfdfd; border: 1px solid #eaeaea; border-radius: 8px; padding: 20px; margin-bottom: 20px; }
.pub-widget-title { margin-top: 0; font-size: 1.2em; border-bottom: 2px solid #f0ad4e; padding-bottom: 10px; margin-bottom: 15px; }

/* Filter Lists */
.pub-filter-list { list-style: none; padding: 0; margin: 0; }
.pub-filter-list li { margin-bottom: 8px; }
.pub-checkbox-label { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 0.95em; color: #555; }
.pub-checkbox-label input[type="checkbox"] { margin-top: 4px; accent-color: #d35400; width: 16px; height: 16px; cursor: pointer; }
.pub-checkbox-label small { color: #aaa; }
.pub-checkbox-label:hover { color: #d35400; }
.pub-scrollable-list { max-height: 220px; overflow-y: auto; padding-right: 10px; }
.pub-scrollable-list::-webkit-scrollbar { width: 6px; }
.pub-scrollable-list::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
.pub-scrollable-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* ==========================================
   TAXONOMY TERM CARD (Author / Category Info)
   ========================================== */
.pub-term-card { 
    display: flex; 
    flex-direction: row; /* Force side-by-side layout on ALL devices */
    align-items: flex-start;
    background: #fdfdfd; 
    border: 1px solid #eaeaea; 
    border-radius: 8px; 
    padding: 15px; /* Tighter padding for mobile */
    margin-bottom: 30px; 
    gap: 15px; /* Tighter gap for mobile */
    box-shadow: 0 4px 10px rgba(0,0,0,0.03); 
}

.pub-term-image { 
    flex: 0 0 80px; /* Locks the image to a neat 80px wide on mobile */
}

.pub-term-image img { 
    width: 100%; 
    height: auto; 
    border-radius: 50%; /* Keeps headshots circular */
    border: 3px solid #eee; 
    object-fit: cover; 
    aspect-ratio: 1/1; 
}

.pub-term-content { flex: 1; min-width: 0; }

.pub-term-label { 
    display: inline-block; font-size: 0.75em; text-transform: uppercase; 
    letter-spacing: 1px; color: #d35400; font-weight: bold; margin-bottom: 5px; 
}

.pub-term-title { 
    margin-top: 0; margin-bottom: 10px; font-size: 1.5em; /* Slightly smaller for mobile */
    color: #2c3e50; line-height: 1.2; word-wrap: break-word;
}

.pub-term-description { color: #555; line-height: 1.6; font-size: 0.95em; }

/* Scale everything back up for Tablets and Desktops */
@media (min-width: 768px) { 
    .pub-term-card { padding: 25px; gap: 20px; }
    .pub-term-image { flex: 0 0 150px; /* Restores large 150px size */ } 
    .pub-term-title { font-size: 2em; margin-bottom: 15px; }
    .pub-term-label { font-size: 0.8em; }
    .pub-term-description { font-size: 1.05em; }
}

/* Sidebar Mini Lists (Recommendations & Bestsellers) */
.pub-mini-list { display: flex; flex-direction: column; gap: 8px; }

/* Scrollbar setup for the lists */
.pub-scrollable-mini-list { 
    max-height: 380px; /* Fits about 4.5 items before scrolling */
    overflow-y: auto; 
    padding-right: 8px; 
}
.pub-scrollable-mini-list::-webkit-scrollbar { width: 5px; }
.pub-scrollable-mini-list::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
.pub-scrollable-mini-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
.pub-scrollable-mini-list::-webkit-scrollbar-thumb:hover { background: #999; }

/* Tiny Item Styling */
.pub-mini-item { 
    display: flex; gap: 12px; text-decoration: none; color: #333; 
    align-items: flex-start; /* Changed from center so the title aligns with the top of the cover */
    transition: background 0.2s; padding: 6px; border-radius: 6px;
    border: 1px solid transparent;
}
.pub-mini-item:hover { background: #f9f9f9; border-color: #eee; }

.pub-mini-item img { 
    width: 55px; /* Fixed width */
    height: auto; /* Lets the height adjust naturally to the original book ratio */
    border-radius: 3px; 
    box-shadow: 1px 1px 4px rgba(0,0,0,0.15); 
    flex-shrink: 0; 
}
.pub-mini-info { display: flex; flex-direction: column; }
.pub-mini-title { font-weight: bold; font-size: 0.9em; line-height: 1.3; color: #2c3e50; }

/* Pagination & Loader */
#pub-catalog-wrapper { position: relative; min-height: 300px; }
#pub-catalog-wrapper.loading #pub-catalog-content { opacity: 0.4; pointer-events: none; }
#pub-ajax-loader { position: absolute; top: 100px; left: 50%; transform: translateX(-50%); font-size: 40px; color: #2c3e50; z-index: 10; }
#pub-ajax-loader .dashicons { width: 40px; height: 40px; font-size: 40px; animation: pub-spin 1.5s linear infinite; }
.pub-pagination { margin-top: 40px; display: flex; justify-content: center; gap: 10px; }
.pub-pagination .page-numbers { padding: 8px 16px; border: 1px solid #ddd; border-radius: 4px; text-decoration: none; color: #333; background: #fff;}
.pub-pagination .page-numbers.current { background: #2c3e50; color: #fff; border-color: #2c3e50; }
.pub-pagination .page-numbers:hover:not(.current) { background: #f5f5f5; }

/* ==========================================
   MY FAVORITES PAGE (/myfavorites/)
   ========================================== */
.pub-favorites-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; padding-bottom: 15px; border-bottom: 2px solid #2c3e50; }
.pub-favorites-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.pub-btn-whatsapp { background-color: #25D366; color: #fff; }
.pub-btn-email { background-color: #3498db; color: #fff; }
.pub-btn-danger { background-color: #e74c3c; color: #fff; border: none; cursor: pointer; }
.pub-btn-whatsapp:hover { background-color: #1ebe57; }
.pub-btn-email:hover { background-color: #2980b9; }
.pub-btn-danger:hover { background-color: #c0392b; }
@media (max-width: 600px) { .pub-favorites-header { flex-direction: column; align-items: flex-start; gap: 15px; } }

/* ==========================================
   DYNAMIC SIDEBAR LAYOUT (Single Page)
   ========================================== */
.pub-single-wrapper.has-sidebar {
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.pub-single-main-content {
    flex: 1;
    min-width: 0; /* Prevents flex blowouts */
}

.pub-single-sidebar-area {
    flex: 0 0 300px; /* Fixed sidebar width */
}

/* On desktops, put the sidebar on the right */
@media (min-width: 900px) {
    .pub-single-wrapper.has-sidebar {
        flex-direction: row;
        align-items: flex-start;
    }
    .pub-single-sidebar-area {
        position: sticky;
        top: 20px;
    }
}

/* CSS Line-Clamping for Titles (Max 3 Rows) */
.pub-card-title a, .pub-mini-title {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================
   BACK TO TOP BUTTON (Floating Action Button)
   ========================================== */
.pub-back-to-top {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 45px;
    height: 45px;
    background-color: #2c3e50; /* Matches your Top Nav */
    color: #fff;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    cursor: pointer;
    z-index: 9998; /* Sits above content but below modals */
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Animation settings */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.pub-back-to-top.show {
    opacity: 0.6; /* Ghost mode: slightly see-through so content underneath is visible */
    visibility: visible;
    transform: translateY(0);
}

.pub-back-to-top:hover,
.pub-back-to-top:active,
.pub-back-to-top:focus {
    opacity: 1; /* Turn completely solid when hovered or tapped */
    background-color: #f0ad4e; /* Highlights to orange */
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.4);
}

.pub-back-to-top .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
}

/* Adjust slightly for mobile screens */
@media (max-width: 768px) {
    .pub-back-to-top {
        bottom: 20px;
        right: 20px;
        width: 40px;
        height: 40px;
    }
}

/* Restrict ALL filter lists to ~4 items tall with a clean scrollbar */
.pub-filter-list { 
    max-height: 135px; /* Fits exactly 4 checkboxes */
    overflow-y: auto; 
    padding-right: 5px; 
}
.pub-filter-list::-webkit-scrollbar { width: 5px; }
.pub-filter-list::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
.pub-filter-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* ==========================================
   MOBILE ARCHIVE LAYOUT (Magic Reordering)
   ========================================== */
.pub-btn-mobile-filter {
    width: 100%; margin-bottom: 20px; background-color: #2c3e50;
    color: #fff; display: flex; justify-content: center; align-items: center;
    font-size: 1.1em; padding: 12px;
}

@media (max-width: 767px) {
    /* 1. Mobile Filter Toggle */
    .pub-btn-mobile-filter { display: flex !important; }
    #pub-filter-wrapper { display: none; background: #f9f9f9; padding: 15px; border-radius: 8px; margin-bottom: 20px; border: 1px solid #ddd; }
    #pub-filter-wrapper.active { display: block; }
    
    /* 2. Magic Reordering: Move Highlights to the bottom of the page! */
    .pub-archive-layout { display: flex; flex-direction: column; }
    .pub-sidebar-filters { display: contents; } /* Unboxes the sidebar so we can reorder its children */
    
    #pub-mobile-filter-toggle { order: 1; }
    #pub-filter-wrapper { order: 2; }
    .pub-main-catalog { order: 3; }
    .pub-sidebar-highlights { order: 4; margin-top: 30px; } /* Drops below the results */

    /* 3. Hide Pagination Numbers on Mobile (Keeps true infinite scroll feel) */
    .pub-pagination a.page-numbers, .pub-pagination span.page-numbers { display: none !important; }
    .pub-pagination { padding: 10px 0; min-height: 20px; } /* Leaves invisible target for lazy-load to trigger */
}

/* ==========================================
   TYPOGRAPHY (System Font Stack for Chinese)
   ========================================== */
.pub-container {
    /* Prioritizes Apple's PingFang/Heiti for Mac/iOS, and Microsoft JhengHei for PC */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang TC", "Heiti TC", "Microsoft JhengHei", "微軟正黑體", sans-serif;
}

/* ==========================================
   DARK MODE (Auto-detects User OS Settings)
   ========================================== */
@media (prefers-color-scheme: dark) {
    /* 1. Base Backgrounds & Borders */
    .pub-card, 
    .pub-tab-content, 
    .pub-specs-box, 
    .pub-term-card, 
    .pub-filter-widget, 
    .pub-modal-content, 
    #pub-filter-wrapper {
        background-color: #1e1e1e !important;
        border-color: #333333 !important;
        box-shadow: 0 4px 10px rgba(0,0,0,0.5) !important;
    }
    
    /* Global Container Background (if the theme doesn't handle it) */
    .pub-container { color: #e0e0e0; }

    /* 2. Text Colors */
    .pub-single-title, 
    .pub-archive-title, 
    .pub-card-title a, 
    .pub-term-title, 
    .pub-widget-title, 
    .pub-mini-title,
    .pub-specs-title,
    .pub-section-title {
        color: #f5f5f5 !important; /* Bright white/grey for headings */
    }
    
    .pub-meta-list p, 
    .pub-term-description, 
    .pub-formatted-text p, 
    .pub-card-excerpt, 
    .pub-checkbox-label,
    .pub-format-label {
        color: #b0b0b0 !important; /* Soft grey for reading paragraphs */
    }

    .pub-meta-list strong, 
    .pub-specs-grid li strong {
        color: #d0d0d0 !important; /* Off-white for labels like 'Author:' */
    }

    .pub-meta-list a { color: #5dade2 !important; } /* Lighter blue for dark mode links */
    .pub-meta-list a:hover { color: #3498db !important; }

    /* 3. Inputs and Search Bars */
    .pub-search-field, 
    .pub-nav-search input, 
    #pub-sort-select {
        background-color: #2a2a2a !important;
        color: #ffffff !important;
        border-color: #444444 !important;
    }

    /* 4. Tabs */
    .pub-tab-links a { 
        background-color: #2a2a2a !important; 
        color: #b0b0b0 !important; 
        border-color: #444 !important; 
    }
    .pub-tab-links li.active a { 
        background-color: #1e1e1e !important; 
        color: #77dd77 !important; /* Keeps your custom active color */
        border-bottom-color: #1e1e1e !important;
    }

    /* 5. Pricing (Keeping it Red/Unattractive as requested) */
    .pub-card-price strong, 
    .pub-price-main strong, 
    .pub-price-discount strong { 
        color: #b7a8a8 !important; 
    }
    .pub-price-discount del { color: #7f8c8d !important; }

    /* 6. Buttons & Interactives */
    .pub-btn-favorite { 
        background-color: #2a2a2a !important; 
        color: #e0e0e0 !important; 
        border-color: #444 !important; 
    }
    .pub-btn-favorite:hover { background-color: #333333 !important; }
    
    .pub-format-btn { 
        background-color: #2a2a2a !important; 
        color: #b0b0b0 !important; 
        border-color: #555 !important; 
    }
    .pub-format-btn:hover { background-color: #333333 !important; color: #fff !important; }
    
    /* In dark mode, Dark Blue blends in too much, so we use Orange for the active format */
    .pub-format-btn.active { 
        background-color: #f0ad4e !important; 
        color: #fff !important; 
        border-color: #f0ad4e !important; 
    } 

    .pub-mini-item:hover { background: #2a2a2a !important; border-color: #444 !important; }

    /* 7. Image Handling */
    .pub-book-cover, .pub-card-image img {
        /* Removes bright white background from transparent images in dark mode */
        background-color: transparent !important; 
        box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.6), -1px 0 3px rgba(0, 0, 0, 0.4) !important;
    }
}

/* ==========================================
   RELATED READING & RECENTLY VIEWED
   ========================================== */
/* Guarantee wide spacing above Related Reading */
.pub-related-section { 
    margin-top: 60px !important; 
    padding-top: 30px !important; 
    border-top: 2px solid #eaeaea !important; 
    width: 100%; 
    display: block;
    clear: both; /* Forces it to drop below any floating elements or videos */
}

/* Spacing for Recent Browsing */
.pub-recent-section {
    margin-top: 50px; 
    padding-top: 30px; 
    border-top: 2px solid #eee;
    width: 100%;
    display: block;
    clear: both;
}

/* ==========================================
   ENHANCED PRINT TEMPLATE STYLES
   ========================================== */
@media print {
    /* 1. Global Print Resets */
    body, .pub-container { background: #fff !important; color: #000 !important; margin: 0 !important; padding: 0 !important; }
    
    /* Reveal Print Banners */
    .pub-print-banner { display: block !important; margin-bottom: 20px !important; padding-bottom: 10px !important; border-bottom: 2px solid #000 !important; font-family: monospace; color: #333 !important; }

    /* 2. Hide interactive/web-only elements */
    .pub-global-nav, .pub-action-buttons, .pub-social-share-box, 
    .pub-format-switcher, .pub-tab-links, .pub-btn, .pub-search-wrap,
    #pub-sort-widget, #pub-recent-browsing-container, .pub-pagination {
        display: none !important;
    }

    /* ================= SINGLE BOOK PAGE ================= */
    .pub-single-header { display: flex; flex-direction: row; align-items: flex-start; page-break-inside: avoid; }
    .pub-single-image { flex: 0 0 200px; margin-right: 30px; position: relative !important; }
    .pub-single-image img { border: none !important; box-shadow: none !important; }

    /* HIDE the giant web badges on the cover image */
    .pub-single-image > .pub-badge-container { display: none !important; }
    
    /* REVEAL the relocated Print-only badges below the price */
    .pub-print-only-tags { 
        display: flex !important; 
        flex-direction: row !important; /* Force them into a horizontal row */
        flex-wrap: wrap !important; 
        position: static !important;    /* CRITICAL FIX: Stops them from flying to the left edge */
        margin: 10px 0 20px 0 !important; /* Adds neat spacing above and below */
    }
    .pub-print-only-tags .pub-badge { 
        font-size: 0.85em !important; 
        padding: 4px 10px !important; 
        border: 1px solid #333 !important; 
        color: #000 !important; 
        background: #fff !important; 
        box-shadow: none !important; 
        border-radius: 4px !important; 
    }

    /* Expand all Tabs */
    .pub-tabs-section { border: none; margin-top: 30px; }
    .pub-tab-content { display: block !important; border: none !important; padding: 0 !important; margin-bottom: 30px !important; page-break-inside: auto; }
    
    /* Tab Headers for Print */
    #tab-desc::before { content: "產品資訊 Product Info:"; font-weight: bold; font-size: 1.2em; display: block; margin-bottom: 10px; border-bottom: 1px solid #000; }
    #tab-toc::before { content: "目錄 Table of Contents:"; font-weight: bold; font-size: 1.2em; display: block; margin-bottom: 10px; border-bottom: 1px solid #000; }
    #tab-recommend::before { content: "內容推介 Recommendation:"; font-weight: bold; font-size: 1.2em; display: block; margin-bottom: 10px; border-bottom: 1px solid #000; }
    #tab-specs::before { content: "產品規格 Specifications:"; font-weight: bold; font-size: 1.2em; display: block; margin-bottom: 10px; border-bottom: 1px solid #000; }
    #tab-companion::before { content: "配套推薦 Companion:"; font-weight: bold; font-size: 1.2em; display: block; margin-bottom: 10px; border-bottom: 1px solid #000; }
    #tab-series::before { content: "系列 Series:"; font-weight: bold; font-size: 1.2em; display: block; margin-bottom: 10px; border-bottom: 1px solid #000; }

    /* Expand Specifications to 3 Columns */
    .pub-specs-grid { display: grid !important; grid-template-columns: repeat(3, 1fr) !important; gap: 15px !important; }
    .pub-specs-grid li { page-break-inside: avoid; }

    /* Video Presentation Printout */
    .pub-video-section { display: block !important; margin-top: 30px; }
    .pub-video-gallery-layout { display: none !important; } /* Hide Web View gallery completely */
    .pub-print-video-info { display: grid !important; grid-template-columns: repeat(2, 1fr) !important; gap: 30px !important; margin-top: 15px; width: 100% !important; }
    .pub-print-video-row { page-break-inside: avoid; width: 100% !important; }
    .pub-print-video-thumb { width: 100% !important; max-width: 100% !important; height: auto !important; border: 1px solid #ccc; margin-bottom: 8px; display: block; }
    .pub-print-video-info p { margin: 0; font-size: 1em; font-family: monospace; word-break: break-all; }

    /* ================= ARCHIVE & GRIDS ================= */
    /* Book Grids: Force 4 Columns */
    .pub-grid-container { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: 10px !important; }
    
    /* Clean up the Grid Cards */
    .pub-card { position: relative !important; border: 1px solid #ccc !important; padding: 10px !important; page-break-inside: avoid !important; text-align: left !important; }
    .pub-card-image img { max-width: 80px !important; height: auto !important; margin: 0 !important; }
    
    /* Reposition Badges to Top-Right inside Grid Cards */
    .pub-card .pub-badge-container { display: flex !important; position: absolute !important; top: 5px !important; right: 5px !important; left: auto !important; align-items: flex-end !important; gap: 3px !important; }
    .pub-card .pub-badge { font-size: 0.65em !important; padding: 2px 6px !important; border: 1px solid #333 !important; color: #000 !important; background: #fff !important; box-shadow: none !important; border-radius: 4px !important; }
    
    /* Format Indicators Extraction */
    .pub-card-format-icons { position: static !important; background: transparent !important; color: #333 !important; padding: 8px 0 0 0 !important; text-align: left !important; backdrop-filter: none !important; }
    .pub-card-format-icons .dashicons { display: none !important; }
    .pub-card-format-icons::after { content: attr(title); font-size: 0.85em; font-weight: bold; display: block; }

    /* Archive Sidebar Filters: Auto-Columns */
    #pub-filter-form { display: grid !important; grid-template-columns: repeat(3, 1fr) !important; gap: 5px 15px !important; border-bottom: 2px solid #000; padding-bottom: 10px !important; margin-bottom: 15px !important; }
    .pub-widget-title { margin-bottom: 5px !important; padding-bottom: 5px !important; border-width: 1px !important; font-size: 1.1em !important; }

    /* Compact Sidebar Highlights (Top Sellers) */
    .pub-sidebar-highlights { margin-top: 15px !important; }
    .pub-sidebar-grid { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: 10px !important; }
    .pub-mini-item { padding: 5px !important; }
    .pub-mini-item img { width: 45px !important; max-width: 45px !important; } /* Make images smaller for print */

    .pub-sidebar-filters { width: 100% !important; display: block !important; }
    .pub-sidebar-filters .pub-filter-widget:not(.pub-sidebar-highlights) { margin: 0 !important; padding: 0 !important; border: none !important; }
    
    /* NEW: Print-only Filter Logic (Hide Unchecked Items) */
    .pub-filter-list li:not(:has(input:checked)) {
        display: none !important; /* Hides unchecked list items */
    }
    .pub-filter-widget:has(input[type="checkbox"]):not(:has(input:checked)) {
        display: none !important; /* Hides the ENTIRE widget if nothing is checked */
    }
    .pub-checkbox-label input[type="checkbox"] {
        display: none !important; /* Hides the actual checkbox square for clean printing */
    }
    .pub-checkbox-label {
        font-weight: bold; color: #000 !important;
    }

    /* Archive Sidebar Highlights: Force into Full 4-Column Rows */
    .pub-print-full-row { width: 100% !important; grid-column: 1 / -1 !important; display: block !important; margin-top: 20px !important; page-break-inside: avoid; border: none !important; padding: 0 !important; }
    .pub-sidebar-grid { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: 15px !important; }
    
    /* NEW: Limit the printed highlights to exactly 4 items */
    .pub-sidebar-highlights .pub-mini-item:nth-child(n+5) {
        display: none !important;
    }
    
    /* Disable the scrollbar for printing and expand the list */
    .pub-scrollable-mini-list { max-height: none !important; overflow: visible !important; }
    
    /* Turn the mini-list into a 4-column grid for print */
    .pub-mini-list { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: 15px !important; }
    
    .pub-mini-item { flex-direction: column !important; text-align: center !important; border: 1px solid #ccc !important; padding: 10px !important; }
    .pub-mini-item img { width: 60px !important; max-width: 60px !important; margin: 0 auto 5px auto !important; }

    /* Hide Sidebar when Printing */
    .pub-single-sidebar-area { display: none !important; }

    /* Hide Back to Top button when Printing */
    .pub-back-to-top { display: none !important; }

    /* Archive Print: Term Card (Author Info) Side-by-Side */
    .pub-term-card { 
        page-break-inside: avoid !important; /* Prevents breaking into 2 pages */
        display: flex !important; 
        flex-direction: row !important; 
        align-items: flex-start !important; 
        padding: 15px !important;
    }
    .pub-term-image { 
        flex: 0 0 100px !important; /* Locks photo to 100px wide */
        margin-right: 20px !important; 
        margin-bottom: 0 !important;
    }
    .pub-term-image img { 
        width: 100px !important; 
        height: auto !important; 
    }
    .pub-term-content { 
        flex: 1 !important; 
    }

    /* Hide Author/Taxonomy links in Grid and Mini Cards for a cleaner printout */
    .pub-card-author, 
    .pub-mini-author, 
    .pub-card-excerpt { 
        display: none !important; 
    }

}