/* ============================================
   Ngày ngày đọc sách - Custom CSS v4.1
   Consolidated styles for the entire site
   Strict adherence to PicoCSS v2 Standards
   ============================================ */

/* ==== CSS Variables & Theme Configuration ==== */

:root {
    /* Fonts */
    --pico-font-family: 'Athiti', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Layout Variables */
    --nav-height: 65px;
}

/* ==== Component Overrides ==== */



/* Navbar Scoped Styles to prevent global pollution */
.site-header {
    background: var(--pico-card-background-color);
    padding: 0;
    border-bottom: none;
}

/* Sticky Navigation - only when class is applied */
.site-header.sticky {
    position: sticky;
    top: 0;
    z-index: 80;
    /* Base sticky level, below reader nav (90) */
}


.navbar-top .container {
    padding: 0 1.5rem;
    /* Specific padding for top nav */
}


.navbar-secondary .container {
    padding: 0 1rem;
    /* Specific padding for secondary nav */
}

.navbar-top .container,
.navbar-secondary .container {
    display: flex;
    /* Ensure two-column layout */
    justify-content: space-between;
    align-items: center;
    height: 100%;
    /* Strict vertical spacing reset */
}

/* --- Utility Classes (Added v9.8) --- */
.text-center {
    text-align: center;
}

/* Specific override for flex items in dropdowns */
.navbar-secondary details[open]>ul li a.nav-item-flex {
    display: flex !important;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

/* Ensure Nav elements have defined height for centering */
.site-header nav {
    min-height: var(--nav-height, 65px);
    padding: 0 !important;
    /* Force no padding on nav element itself */
    margin: 0 !important;
    /* Force no margin */
    display: flex;
    align-items: center;
}

.navbar-secondary {
    min-height: var(--nav-height);
    /* Match top navbar height */
    height: var(--nav-height);
    background: var(--pico-card-sectioning-background-color);
    border-top: 1px solid var(--pico-muted-border-color);
    /* Add top border */
    border-bottom: 1px solid var(--pico-muted-border-color);
    /* Add bottom border */
}

/* Navbar Top - Flex Layout */
.navbar-top ul {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
}

.navbar-top li {
    list-style: none;
    padding: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--pico-color);
    text-decoration: none;
}

/* Icon Inline Vertical Align */
.icon-inline {
    vertical-align: text-bottom;
    margin-right: 0.25rem;
}

/* Hamburger Visibility - Desktop Hidden */
.hamburger-btn-wrapper {
    display: none;
}

@media (max-width: 768px) {
    .hamburger-btn-wrapper {
        display: block;
    }

    .navbar-secondary {
        display: none;
    }

    .navbar-top .btn-nav {
        display: none;
    }
}

/* Secondary Navbar */
.navbar-secondary ul {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Fix Dropdown Positioning: Relative on Parent LI */
.navbar-secondary li {
    position: relative;
    list-style: none;
}

/* Links in Navbar */
.nav-link-item,
.navbar-secondary summary {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem;
    color: var(--pico-color);
    text-decoration: none;
    cursor: pointer;
    border-radius: var(--pico-border-radius);
    transition: background-color 0.2s;
    font-weight: 500;
}

.nav-link-item:hover,
.navbar-secondary summary:hover,
.navbar-secondary details[open] summary {
    background-color: var(--pico-muted-border-color);
    text-decoration: none;
    border-color: transparent;
    /* Remove border on hover/open if needed */
    background: transparent;
    /* Ensure clean look */
    color: var(--pico-primary);
}

.navbar-secondary summary {
    margin-bottom: 0;
    border: none !important;
    /* Force remove border */
    background: transparent !important;
    outline: none !important;
    box-shadow: none !important;
}

.navbar-secondary details {
    margin-bottom: 0;
    border-bottom: none;
}

/* Dropdowns */
/* Dropdowns */
.navbar-secondary details[open]>ul {
    margin-top: 0;
    position: absolute;
    top: 100%;
    left: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    /* Ensures no space between items */
    min-width: 220px;
    max-width: 300px;
    width: max-content;
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    opacity: 1;
    z-index: 1000;
    padding: 0 !important;
    /* Strict reset to zero */
    overflow: hidden;
    /* Clips children to border radius */
}

.navbar-secondary details[open]>ul li {
    width: 100%;
    margin: 0 !important;
    /* Zero margin */
    padding: 0 !important;
    /* Zero padding */
    position: relative;
    list-style: none;
}

.navbar-secondary details[open]>ul li a {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem !important;
    /* Internal padding for click area */
    font-size: 0.875rem;
    color: var(--pico-color);
    text-decoration: none;
    border-radius: 0;
    transition: background-color 0.1s;
    margin: 0 !important;
    border: none !important;
    white-space: nowrap;
}

.navbar-secondary details[open]>ul li a:hover {
    background-color: var(--pico-muted-border-color);
    color: var(--pico-primary);
}


/* Search Form */
.search-wrapper {
    display: flex;
    align-items: center;
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 99px;
    padding: 0.25rem 0.75rem;
    width: 280px;
    transition: width 0.2s;
}

.search-input {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 0.5rem !important;
    margin: 0 !important;
    height: auto !important;
    width: 100%;
}

.search-icon {
    opacity: 0.6;
}

/* Mobile Header Optimizations */
@media (max-width: 768px) {

    /* Mobile-specific Header Styling */
    .site-header {
        background-color: #fbfcfc;
        border-bottom: 1px solid var(--pico-muted-border-color);
    }

    [data-theme="dark"] .site-header {
        background-color: var(--pico-card-background-color);
    }

    .navbar-top .container {
        padding: 0 1rem;
        gap: 0.25rem;
    }

    /* Flex behavior for navbar lists */
    .navbar-top ul:first-child {
        flex: 1;
        min-width: 0;
        gap: 0.5rem;
        width: 100%;
    }

    .navbar-top ul:last-child {
        flex-shrink: 0;
        gap: 0.25rem;
    }

    .logo-text {
        display: none;
    }

    .search-form-container {
        flex: 1;
        min-width: 0;
        margin: 0;
    }

    .search-wrapper {
        width: 100%;
        padding: 0.25rem 0.5rem;
        height: 36px;
    }

    .search-input {
        font-size: 0.9rem !important;
        width: 100%;
    }

    /* Ensure icon spacing & touch targets */
    .dark-mode-toggle,
    .hamburger-btn {
        padding: 0;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        background: transparent;
    }

    /* Force 2-column layout on mobile sidebar using custom class */
    .mobile-split-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
        width: 100%;
        align-items: start;
        box-sizing: border-box;
    }

    .mobile-split-layout aside {
        min-width: 0;
        width: 100%;
        overflow-wrap: break-word;
        /* Prevent overflow */
    }

    /* Ensure lists inside Right Column stack vertically */
    .mobile-split-layout aside nav ul {
        flex-direction: column !important;
        align-items: flex-start !important;
        width: 100%;
    }

    /* Hide button text in bottom nav on mobile to prevent overflow */
    .chapter-nav-bottom-buttons .btn-text {
        display: none;
    }
}

/* Utilities for Alignment and Spacing (Replacing Inline Styles) */
.nav-align-right {
    margin-left: auto !important;
}

/* Ensure navbar list takes full width for auto margin to work */
.navbar-secondary ul {
    width: 100%;
}

.mt-1 {
    margin-top: 0.5rem !important;
}

.mt-2 {
    margin-top: 1rem !important;
}

.pt-1 {
    padding-top: 0.5rem !important;
}

.border-top-muted {
    border-top: 1px solid var(--pico-muted-border-color);
}




.search-input:focus {
    box-shadow: none !important;
    /* Remove focus ring inside wrapper */
}

/* Dark Mode Toggle */
.dark-mode-toggle {
    background: transparent;
    border: 1px solid var(--pico-muted-border-color);
    color: var(--pico-color);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    transition: all 0.2s;
}

.dark-mode-toggle:hover {
    background: var(--pico-muted-border-color);
    border-color: var(--pico-primary);
    color: var(--pico-primary);
}

/* Reader Content Typography */
#reader-content {
    line-height: 1.8;
    text-align: justify;
}

#reader-content h1,
#reader-content h2,
#reader-content h3 {
    text-align: center;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: var(--pico-primary);
}

/* Breadcrumbs - Remove custom styles, rely on Pico if possible, or minimal override */
nav[aria-label="breadcrumb"] {
    /* font-size: 0.9rem; <-- Removed */
}

nav[aria-label="breadcrumb"] ul li {
    color: var(--pico-muted-color);
}

/* Centered Pagination */
.pagination-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.pagination-label {
    font-weight: bold;
    color: var(--pico-muted-color);
}

.pagination-center ul {
    justify-content: center;
    margin-bottom: 0;
}

/* Ensure Search Form Expands */
.search-form {
    width: 100%;
    display: flex;
}

/* Footer */
.site-footer {
    background: var(--pico-card-background-color);
    border-top: 1px solid var(--pico-muted-border-color);
    padding: 2rem 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
    margin-top: 2rem;
}

/* Badges (Utility) */
.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: bold;
    background: var(--pico-muted-border-color);
    color: var(--pico-color);
}

.badge-success {
    background: #2ecc71;
    color: #fff;
}

.badge-warning {
    background: #f1c40f;
    color: #000;
}

.badge-danger {
    background: #e74c3c;
    color: #fff;
}

/* Alerts */
.alert {
    padding: var(--pico-block-spacing-vertical) var(--pico-block-spacing-horizontal);
    border-radius: var(--pico-border-radius);
    margin-bottom: var(--pico-block-spacing-vertical);
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

[data-theme="dark"] .alert-success {
    background: #155724;
    color: #d4edda;
}

[data-theme="dark"] .alert-error {
    background: #721c24;
    color: #f8d7da;
}


/* Chapter Navigation */
.chapter-nav-wrapper,
.chapter-nav-bottom {
    text-align: center;
    padding: 0.75rem 1rem;
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    margin: 0.25rem 0;
}

.chapter-nav-row1 {
    font-size: 0.95rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.chapter-nav-row1 a {
    color: var(--pico-primary);
    text-decoration: none;
}

.chapter-nav-row2 {
    font-size: 0.85rem;
    color: var(--pico-muted-color);
    margin-bottom: 0.5rem;
}

.chapter-nav-row3 {
    font-size: 0.75rem;
    color: var(--pico-muted-color);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: nowrap;
}

.chapter-nav-row3 .sep {
    color: var(--pico-muted-border-color);
}

.chapter-nav-row3 .action {
    color: var(--pico-primary);
    cursor: pointer;
}

.chapter-nav-row3 .action:hover {
    text-decoration: underline;
}

.chapter-nav-row3 .action.disabled {
    color: var(--pico-muted-color);
    cursor: not-allowed;
}

.chapter-nav-row4,
.nav-buttons-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: nowrap;
}

/* .nav-btn styles removed to use PicoCSS defaults */

.chapter-comments {
    margin-top: 0.5rem;
    color: var(--pico-muted-color);
    font-size: 0.75rem;
    cursor: pointer;
}

.chapter-comments:hover {
    color: var(--pico-primary);
}

/* ==== Book Card ==== */
.book-card {
    background: var(--pico-card-background-color, #fff);
    border: 1px solid var(--pico-muted-border-color, #ddd);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Override PicoCSS article padding */
main.container div.grid-cards article.book-card {
    padding: 0 !important;
    margin: 0 !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    /* Add transition */
}

.book-card:hover {
    transform: translateY(-5px);
    /* Lift effect */
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    /* Stronger shadow on hover */
}

.book-cover-link {
    display: block;
    width: 100%;
    background: #f5f5f5;
}

.book-cover-img {
    width: 100%;
    height: auto;
    display: block;
}

.book-info {
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.book-info hgroup {
    margin-bottom: 0.5rem;
}

.book-title {
    font-size: 1.1rem;
    /* Adjusted for hgroup */
    font-weight: 700;
    margin: 0;
    line-height: applied;
    color: var(--pico-color);
}

.book-author {
    font-size: 0.9rem;
    color: var(--pico-muted-color);
    margin: 0;
    font-weight: normal;
}

.book-desc {
    font-size: 0.875rem;
    color: var(--pico-muted-color);
    line-height: 1.5;
    margin-bottom: auto;
    /* Push footer down */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-divider {
    margin: 0.75rem 0;
    border-top: 1px solid var(--pico-muted-border-color);
    opacity: 0.5;
}

.book-genres {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 0.4rem;
    align-items: center;
}


.genre-badge {
    font-size: 0.75rem !important;
    /* Force override */
    padding: 0.1rem 0.35rem;
    background: var(--pico-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 3px;
    color: var(--pico-muted-color);
    text-decoration: none;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    line-height: 1.2;
}

/* Target font-size explicitly as requested */
div.book-genres a[role="button"] {
    font-size: 0.75rem;
}

div.book-genres a[role="button"]:hover,
.story-tags a.tag-sm:hover {
    background-color: var(--pico-secondary-background);
    color: var(--pico-secondary-inverse);
    border-color: var(--pico-secondary-background);
}

/* Action Buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 50px;
    /* Pill shape */
    padding: 0.5rem 1.25rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.action-btn svg {
    width: 1.2em;
    height: 1.2em;
}

/* Rating Stars Enhancement */
.rating-stars {
    display: inline-flex;
    flex-direction: row-reverse;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    gap: 0;
    vertical-align: middle;
}

/* Fix spacing issue by overriding PicoCSS default margin */
.rating-stars [type="radio"]~label:not(:last-of-type) {
    margin-inline-end: 0 !important;
}

.rating-stars input {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.rating-stars label {
    cursor: pointer;
    color: #ddd;
    margin: 0 2px;
    padding: 0;
    transition: color 0.2s;
    display: inline-block;
    font-size: 1.5rem;
    line-height: 1;
}

.rating-stars label:before {
    content: "★";
    display: inline-block;
}

.rating-stars input:checked~label,
.rating-stars label:hover,
.rating-stars label:hover~label {
    color: #f1c40f;
}

/* Rated state - show selection, disable interaction */
.rating-stars.rated {
    pointer-events: none;
}

.rating-stars.rated input:checked~label {
    color: #f1c40f;
}

/* Rating score styling */
.story-rating-score {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--pico-color);
    margin-right: 0.5rem;
}

.rating-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 0.5rem 0;
    font-size: 0.9rem;
}


/* Book Info Compact - Admin Tables */
.book-info-compact {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    line-height: 1.3;
}

.book-info-compact strong {
    font-size: 0.9rem;
}

.book-info-compact small {
    font-size: 0.75rem;
}

/* Story Cover - Detail Page */
.story-cover {
    width: 100%;
    height: auto;
    border-radius: var(--pico-border-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}


/* Dark Mode Toggle Icon Fix */
.dark-mode-toggle svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* Tiny Tag Utility (extends Pico button) */
.tag-sm {
    --pico-font-size: 0.7rem;
    --pico-form-element-spacing-vertical: 0.15rem;
    --pico-form-element-spacing-horizontal: 0.5rem;
    border-radius: 4px;
    /* Slightly tighter radius for small tags */
    vertical-align: middle;
}

/* Ensure hover effect (Pico default outline fills on hover, but we can enforce/tweak if needed) */
.tag-sm:hover {
    text-decoration: none;
    /* Optional: custom hover color if default secondary isn't desired */
}



/* Story Detail Layout - Grid 2 columns */
.story-layout {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: 1fr;
    /* Mobile: single column */
}

@media (min-width: 768px) {
    .story-layout {
        grid-template-columns: 200px 1fr;
        align-items: start;
    }
}

.story-layout figure {
    margin: 0;
}

/* Story Detail Components */
.story-meta {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.story-rating {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.story-rating-score {
    color: #f1c40f;
    font-weight: bold;
}

.story-views {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--pico-muted-color);
    font-size: 0.9rem;
}

.story-tags {
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.story-actions {
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.story-status-container {
    margin-top: 1rem;
    border-top: 1px solid var(--pico-muted-border-color);
    padding-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--pico-muted-color);
}

.story-status-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.status-item {
    margin-right: 1.5rem;
}

.status-item:last-child {
    margin-right: 0;
}

.status-views {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* Scrollable Chapter List (Fixed v8.1.1) */
.chapter-list-container {
    max-height: 400px;
    /* Approx 10 rows */
    overflow-y: auto;
    padding-right: 0.25rem;
    /* Space for scrollbar */
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    padding: 0.5rem;
    background: var(--pico-card-background-color);
}

.chapter-list-container ul {
    margin: 0;
    padding: 0;
    list-style: none;
    /* Ensure no bullet */
    border: none;
    /* Removed border */
}

.chapter-list-container ul li {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
    margin: 0;
}

.chapter-list-container ul li:last-child {
    border-bottom: none;
}

.chapter-list-container ul li a {
    display: block;
    width: 100%;
    color: var(--pico-color);
    text-decoration: none;
}

.chapter-list-container ul li a:hover {
    color: var(--pico-primary);
}

.chapter-list-container ul li a.disabled {
    color: var(--pico-muted-color);
    pointer-events: none;
}

/* Story Tabs (Redesigned v8.2) */
.story-tabs-container {
    margin-top: 2rem;
}

.story-tabs {
    display: flex;
    gap: 1.5rem;
    /* Space between textual tabs */
    border-bottom: 2px solid var(--pico-muted-border-color);
    /* Base line */
    margin-bottom: 1.5rem;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on mobile */
}

.story-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    /* Highlight line placeholder */
    color: var(--pico-muted-color);
    padding: 0.5rem 0.25rem;
    /* Minimal padding */
    cursor: pointer;
    font-weight: 700;
    font-size: 1.1rem;
    /* Heading-like size */
    transition: all 0.2s ease;
    white-space: nowrap;
    border-radius: 0;
    margin-bottom: -2px;
    /* Overlap the base line */
    opacity: 0.7;
}

.tab-btn:hover {
    color: var(--pico-primary);
    opacity: 1;
}

.tab-btn.active {
    color: var(--pico-primary);
    border-bottom-color: var(--pico-primary);
    opacity: 1;
}

/* Ensure no focus outline on click to keep it clean */
.tab-btn:focus {
    box-shadow: none;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading Spinner */
.loading-spinner {
    color: var(--pico-muted-color);
    font-style: italic;
}



@media (max-width: 768px) {

    /* Center Metadata on Mobile */
    .story-layout>div {
        text-align: center;
    }

    .story-layout hgroup h1,
    .story-layout hgroup p {
        text-align: center;
    }

    .story-meta,
    .story-tags,
    .story-actions,
    .story-rating {
        justify-content: center;
    }

    .story-status-row {
        justify-content: center;
        gap: 1rem;
    }

    .status-item {
        margin-right: 0;
    }

    .status-views {
        justify-content: center;
        width: 100%;
        /* Force new line centered */
    }
}


/* Utility: Small Button (Uses CSS Variables - no !important needed) */
.btn-sm {
    --pico-font-size: 0.75rem;
    --pico-form-element-spacing-vertical: 0.25rem;
    --pico-form-element-spacing-horizontal: 0.5rem;
    line-height: 1;
}


.grid-cards {
    display: grid;
    /* Use CSS custom property with fallback */
    grid-template-columns: repeat(var(--grid-cols-sm, auto-fill), minmax(160px, 1fr));
    gap: 0.75rem;
    row-gap: 90px;
}

@media (min-width: 768px) {
    .grid-cards {
        grid-template-columns: repeat(var(--grid-cols, 4), 1fr);
    }
}

/* ==== Admin Layout ==== */
.admin-layout {
    display: grid;
    grid-template-columns: auto 1fr;
    min-height: 100vh;
}

.admin-sidebar {
    width: 260px;
    background: var(--pico-card-sectioning-background-color);
    border-right: 1px solid var(--pico-muted-border-color);
    padding: 1.5rem;
}

.admin-sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.admin-sidebar li {
    margin-bottom: 0.25rem;
}

.admin-sidebar a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--pico-color);
    transition: 0.2s;
}

.admin-sidebar a:hover,
.admin-sidebar a.active {
    background: var(--pico-primary-background);
    color: var(--pico-primary);
}

.admin-sidebar details summary {
    list-style: none;
    padding: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--pico-h2-color);
}

.admin-sidebar details[open] summary {
    margin-bottom: 0.5rem;
}

.admin-sidebar details ul {
    padding-left: 1rem;
    margin-top: 0.25rem;
    border-left: 1px solid var(--pico-muted-border-color);
}

.admin-content {
    padding: 2rem;
    overflow-x: auto;
}


/* ==== Mobile Responsive ==== */
@media (max-width: 768px) {
    .navbar-top {
        min-height: 45px;
        padding: 0.25rem 0;
    }

    /* IMPORTANT: Hide secondary navbar on mobile */
    .navbar-secondary {
        display: none !important;
    }

    /* IMPORTANT: Show hamburger on mobile */
    .hamburger-btn-wrapper {
        display: block !important;
    }

    .nav-container {
        padding: 0 0.5rem;
        gap: 0.5rem;
        justify-content: space-between !important;
    }

    /* Fix search form width on mobile */
    .search-form-container {
        flex: 1;
        display: flex;
        justify-content: center;
        margin: 0 0.5rem;
    }

    .navbar-top ul {
        gap: 0.5rem;
    }

    .logo-text {
        display: none;
    }

    .user-greeting {
        display: none;
    }

    .search-form {
        max-width: 100%;
        width: 100%;
    }

    .search-wrapper {
        height: 32px;
        padding: 0 8px;
    }

    .search-input {
        font-size: 13px;
        height: 30px;
        line-height: 30px;
    }

    .btn-nav {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }

    .dark-mode-toggle {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        border-radius: 50%;
    }

    .dm-icon {
        font-size: 0.75rem;
    }

    .dm-icon svg {
        width: 16px;
        height: 16px;
    }

    .nav-menu {
        gap: 0;
        overflow-x: auto;
    }

    .nav-link {
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
    }

    /* Mobile handled by .mobile-nav-menu */


    .admin-layout {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        display: none;
    }

    .grid-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    /* .book-title { font-size: 0.75rem; } <-- Removed to inherit global size */

    .chapter-nav-row3,
    .chapter-nav-row4,
    .nav-buttons-row {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .btn-nav {
        padding: 0.2rem 0.4rem;
    }
}

/* ==== Button Groups ==== */
.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.btn-group a[role="button"],
.btn-group button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    margin: 0;
}

.btn-group.compact a[role="button"],
.btn-group.compact button {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

/* ==== Mobile Hamburger Navigation ==== */
.hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    cursor: pointer;
    gap: 5px;
    font-size: 1.2rem;
}

.hamburger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--pico-color, #333);
    border-radius: 1px;
    transition: all 0.3s;
}

/* Mobile Nav Overlay */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s;
}

/* Mobile Nav replaced by Pico Dialog */



/* Utilities */
.icon-inline {
    vertical-align: text-bottom;
}

.icon-middle {
    vertical-align: middle;
}


.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}


.error-container {
    padding: 4rem 1rem;
    text-align: center;
}


.badge-tag {
    font-size: 0.85rem;
    text-decoration: none;
    margin-right: 0.25rem;
}

/* Admin Badges */
.badge {
    padding: 0.25em 0.5em;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: bold;
}

.badge-success {
    background-color: var(--pico-color-jade-600);
    color: white;
}

.badge-secondary {
    background-color: var(--pico-color-slate-500);
    color: white;
}

.badge-calibre {
    background-color: var(--pico-color-amber-600);
    color: white;
}

.badge-epub {
    background-color: var(--pico-color-lime-600);
    color: white;
}



.book-scroll-list {
    max-height: 400px;
    overflow-y: auto;
    list-style: none inside;
    padding: 0;
    margin: 0;
}

.book-scroll-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

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

.book-actions {
    display: flex;
    gap: 0.5rem;
}

.book-actions a {
    font-size: 0.9rem;
}

.badge-html {
    background-color: var(--pico-color-cyan-600);
    color: white;
}

.badge-folder {
    background-color: var(--pico-color-fuchsia-600);
    color: white;
}

/* Mobile Nav Menu v5.1 */
#mobile-menu {
    padding: 0;
    border: none;
    background: transparent;
    width: 100%;
    max-width: 100%;
}

#mobile-menu::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

#mobile-menu>article {
    max-width: min(95vw, 650px);
    width: 95vw;
    margin: 0 auto;
    padding-bottom: 2rem;
}

/* Force 2 columns on mobile for the menu */
.mobile-auto-cols {
    grid-template-columns: 1fr 1fr !important;
    gap: 1.5rem;
    align-items: start;
}

/* Vertical navigation in sidebars */
.mobile-auto-cols aside nav,
.mobile-auto-cols aside nav ul {
    display: flex;
    flex-direction: column !important;
    align-items: flex-start;
    padding: 0;
    margin: 0;
    width: 100%;
}

.mobile-auto-cols aside nav ul li {
    list-style: none;
    width: 100%;
    padding: 0.1rem 0;
}

.mobile-auto-cols aside nav ul li strong {
    display: block;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
}

.mobile-auto-cols aside nav ul li a {
    display: block;
    width: 100%;
    padding: 0.4rem 0.5rem;
    border-radius: var(--pico-border-radius);
    text-decoration: none;
    color: var(--pico-color);
}

.mobile-auto-cols aside nav ul li a:hover {
    background-color: var(--pico-muted-border-color);
    color: var(--pico-primary);
}

@media (max-width: 400px) {
    .mobile-auto-cols {
        grid-template-columns: 1fr !important;
    }
}

/* Login button hidden on mobile */
@media (max-width: 768px) {
    .login-btn-wrapper {
        display: none;
    }
}

/* ============================================
   Utility Classes (v8.5.9)
   ============================================ */

/* Text Alignment */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

/* Font Sizes */
.text-sm {
    font-size: 0.85rem;
}

.text-xs {
    font-size: 0.8rem;
}

/* Spacing */
.mb-0 {
    margin-bottom: 0;
}

.mb-1 {
    margin-bottom: 1rem;
}

.mb-2 {
    margin-bottom: 2rem;
}

.mt-0 {
    margin-top: 0;
}

.mt-1 {
    margin-top: 1rem;
}

.mt-2 {
    margin-top: 2rem;
}

.ml-1 {
    margin-left: 1rem;
}

.p-3 {
    padding: 3rem;
}

/* Gap */
.gap-1 {
    gap: 1rem;
}

.gap-2 {
    gap: 2rem;
}

.gap-sm {
    gap: 0.5rem;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 2rem;
}

.pagination-dots {
    padding: 0.5rem;
}

/* ==== Page-Specific Styles ==== */

/* Genre Page */
.genre-header {
    padding: 1.5rem;
    margin-bottom: 2rem;
    background: var(--pico-card-sectioning-background-color);
}

.genre-header h1 {
    margin-bottom: 0.5rem;
}

.genre-header p {
    color: var(--pico-muted-color);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.genre-header p:last-child {
    margin-bottom: 0;
}

.genre-title-center {
    text-align: center;
    margin-bottom: 1rem;
}

.genre-subtitle {
    text-align: center;
    color: var(--pico-muted-color);
    margin-bottom: 2rem;
}

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

.genre-card {
    padding: 1rem;
}

.genre-card header h4 {
    margin: 0;
}

.genre-card header h4 a {
    text-decoration: none;
}

.genre-card p {
    margin: 0.5rem 0 0 0;
    color: var(--pico-muted-color);
    font-size: 0.9rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
}

/* Dynamic Grid Columns (responsive based on settings) */
@media (min-width: 900px) {
    .grid-cards-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .grid-cards-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .grid-cards-5 {
        grid-template-columns: repeat(5, 1fr);
    }

    .grid-cards-6 {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Author/Series Page */
.author-header {
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.author-avatar {
    max-width: 100%;
    height: auto;
    display: block;
}

.author-bio {
    color: var(--pico-muted-color);
    line-height: 1.6;
}

/* Series Page */
.series-info {
    margin-bottom: 2rem;
    padding: 1rem;
}

.series-desc {
    color: var(--pico-muted-color);
}

/* ==== Toast Notifications ==== */
#pico-toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast-message {
    margin: 0;
    padding: 0.75rem 1.25rem;
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-background-color);
    color: var(--pico-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-left: 4px solid var(--pico-primary-background);
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    font-size: 0.95rem;
    pointer-events: auto;
}

.toast-message.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-success {
    border-left-color: var(--pico-color-green-500);
}

.toast-error {
    border-left-color: var(--pico-color-red-500);
}

.toast-info {
    border-left-color: var(--pico-primary-background);
}