/* Filter bar styling */
#gridFilterButtons {
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
}

#gridFilterButtons .btn-group {
    display: inline-flex;
    flex-wrap: nowrap;
}

#gridFilterButtons .btn {
    flex-shrink: 0;
}

/* Search box styling */
#gridSearchRow input {
    width: 100%;
}

@media (max-width: 768px) {
    #gridSearchRow {
        max-width: 100% !important;
    }
}

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1.5rem;
    padding: 1rem 0;
}

.grid-item {
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Make comic files visually distinct */
.grid-item.file.has-comic {
    cursor: pointer;
}

.grid-item.file.has-comic:hover .thumbnail {
    opacity: 0.8;
}

.grid-item:hover {
    transform: translateY(-5px);
    z-index: 10;
    /* Bring hovered item to front */
}

/* Ensure dropdown is above everything */
.item-actions .dropdown-menu {
    z-index: 1050;
    /* Bootstrap default is 1000, go higher */
}

/* Ensure dropdown toggle button icon is always visible across all themes */
.item-actions .btn-link {
    color: #6c757d;
    /* Neutral gray that works on most backgrounds */
}

.item-actions .btn-link:hover {
    color: #495057;
    /* Slightly darker on hover */
}

.item-actions .btn-link i {
    color: inherit;
}

/* Make dropdown item hover more visible */
.dropdown-item:hover,
.dropdown-item:focus {
    background-color: #0d6efd;
    /* Primary color */
    color: white;
}

.thumbnail-container {
    position: relative;
    width: 100%;
    height: 248px;
    aspect-ratio: 2/3;
    /* background-color: #f8f9fa; */
    border-radius: 8px;
    overflow: clip;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    contain: layout;
}

.thumbnail {
    object-fit: cover;
    transition: opacity 0.3s;
}

/* Apply width/height to files (comics) so they scale to fit */
.grid-item.file .thumbnail {
    width: 100%;
    height: 100%;
}

/* Apply width/height to root-level folder thumbnails */
.grid-item.root-folder .thumbnail {
    width: 100%;
    height: 100%;
}

.icon-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.05);
    opacity: 0;
    /* Hidden by default for files with thumbnails */
}

.grid-item.folder .icon-overlay {
    opacity: 1;
    background-color: #e9ecef;
}

.grid-item.folder .thumbnail {
    display: none;
}

/* Folders with custom thumbnails */
/*
.grid-item.folder.has-thumbnail .thumbnail {
    display: block;
    object-fit: contain;
    max-width: 100%;
    max-height: 100%;
}

.grid-item.folder.has-thumbnail .thumbnail-container {
    overflow: visible;
    background-color: transparent;
}

.grid-item.folder.has-thumbnail .icon-overlay {
    opacity: 0;
    display: none;
} */

.grid-item.folder .icon-overlay i {
    font-size: 3rem;
    color: #ffc107;
    /* Folder color */
}

.item-info {
    margin-top: 0.5rem;
}

.item-name {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #333;
}

.item-meta {
    font-size: 0.75rem;
    color: #6c757d;
}

/* Metadata loading state for progressive loading */
.item-meta.metadata-loading {
    color: #999;
    font-style: italic;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Dark mode support if base.html supports it (assuming standard bootstrap dark mode or custom class) */
[data-bs-theme="dark"] .item-name {
    color: #e9ecef;
}

[data-bs-theme="dark"] .thumbnail-container {
    background-color: #2b3035;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

[data-bs-theme="dark"] .grid-item.folder .icon-overlay {
    background-color: #343a40;
}

/* Drag and drop styles */
.grid-item.drag-over {
    transform: scale(1.05);
    box-shadow: 0 8px 16px rgba(13, 110, 253, 0.3);
    border: 2px solid #0d6efd;
    background-color: rgba(13, 110, 253, 0.05);
}

.grid-item.folder.drag-over::after {
    content: '📁 Drop files here';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(13, 110, 253, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 10;
}

[data-bs-theme="dark"] .grid-item.drag-over {
    border-color: #4dabf7;
    background-color: rgba(77, 171, 247, 0.1);
    box-shadow: 0 8px 16px rgba(77, 171, 247, 0.3);
}

/* Comic Reader Modal Styles */
.comic-reader-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Prevent pull-to-refresh and bounce on mobile */
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
}

.comic-reader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 1;
}

.comic-reader-container {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 2;
    display: flex;
    flex-direction: column;
}

.comic-reader-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    z-index: 3;
    flex-shrink: 0;
}

.comic-reader-title {
    font-size: 1.1rem;
    font-weight: 500;
}

.comic-reader-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}

.comic-reader-progress-bar {
    width: 100px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.comic-reader-progress-fill {
    height: 100%;
    background: #4CAF50;
    width: 0%;
    transition: width 0.3s ease;
}

.comic-reader-progress-text {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    min-width: 35px;
}

.comic-reader-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.comic-reader-page-info {
    font-size: 0.9rem;
    opacity: 0.8;
}

#comicReaderClose {
    cursor: pointer;
}

.comic-reader-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.75rem 2rem;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    z-index: 3;
}

.comic-reader-footer .swiper-pagination {
    position: static;
    width: auto;
}

.comic-reader-footer .swiper-pagination-bullet {
    background: white;
    opacity: 0.5;
}

.comic-reader-footer .swiper-pagination-bullet-active {
    opacity: 1;
}

.comic-reader-swiper {
    flex: 1;
    width: 100%;
    height: 100%;
}

.comic-reader-swiper .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: black;
    overflow: hidden;
}

/* Swiper zoom container styles */
.comic-reader-swiper .swiper-zoom-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.comic-reader-swiper .swiper-slide img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: pan-x pan-y pinch-zoom;
}

.comic-reader-swiper .swiper-button-next,
.comic-reader-swiper .swiper-button-prev {
    color: white;
    background-color: rgba(0, 0, 0, 0.5);
    width: 50px;
    height: 50px;
    border-radius: 50%;
}

.comic-reader-swiper .swiper-button-next:after,
.comic-reader-swiper .swiper-button-prev:after {
    font-size: 1.5rem;
}

.comic-reader-swiper .swiper-pagination {
    bottom: 20px;
}

.comic-reader-swiper .swiper-pagination-bullet {
    background-color: white;
    opacity: 0.5;
}

.comic-reader-swiper .swiper-pagination-bullet-active {
    opacity: 1;
}

/* Loading spinner for comic pages */
.comic-page-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: white;
}

.comic-page-loading .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Mobile responsive styles for comic reader */
@media (max-width: 768px) {
    .comic-reader-header {
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .comic-reader-title {
        font-size: 0.9rem;
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .comic-reader-progress {
        display: none;
    }

    .comic-reader-controls {
        gap: 0.5rem;
    }

    .comic-reader-page-info {
        font-size: 0.8rem;
    }

    .comic-reader-footer {
        padding: 0.5rem 1rem;
    }

    .comic-reader-swiper .swiper-button-next,
    .comic-reader-swiper .swiper-button-prev {
        width: 36px;
        height: 36px;
        opacity: 0.7;
    }

    .comic-reader-swiper .swiper-button-next:after,
    .comic-reader-swiper .swiper-button-prev:after {
        font-size: 1rem;
    }

    /* Ensure images fit properly on mobile */
    .comic-reader-swiper .swiper-slide img {
        width: auto;
        height: auto;
        max-width: 100%;
        max-height: 100%;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .comic-reader-header {
        padding: 0.4rem 0.75rem;
    }

    .comic-reader-title {
        font-size: 0.8rem;
        max-width: 60%;
    }

    .comic-reader-page-info {
        font-size: 0.75rem;
    }

    .comic-reader-swiper .swiper-button-next,
    .comic-reader-swiper .swiper-button-prev {
        width: 32px;
        height: 32px;
    }

    /* Hide navigation arrows on very small screens - use swipe */
    .comic-reader-swiper .swiper-button-next,
    .comic-reader-swiper .swiper-button-prev {
        display: none;
    }
}

/* Zoom indicator hint */
.comic-reader-zoom-hint {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 10;
}

.comic-reader-zoom-hint.visible {
    opacity: 1;
}

/* Next Issue Overlay Styles */
.next-issue-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.next-issue-panel {
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    max-width: 320px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.next-issue-panel h4 {
    color: white;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.next-issue-thumbnail-container {
    width: 140px;
    height: 200px;
    margin: 0 auto 1rem;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.next-issue-thumbnail-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.next-issue-name {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.next-issue-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.next-issue-buttons .btn {
    min-width: 100px;
}

/* Mobile responsive for next issue overlay */
@media (max-width: 480px) {
    .next-issue-panel {
        padding: 1.5rem;
        max-width: 280px;
    }

    .next-issue-panel h4 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }

    .next-issue-thumbnail-container {
        width: 100px;
        height: 150px;
    }

    .next-issue-name {
        font-size: 0.85rem;
    }

    .next-issue-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .next-issue-buttons .btn {
        width: 100%;
    }
}

/* Resume Reading Overlay */
.resume-reading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

.resume-reading-panel {
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    max-width: 320px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.resume-reading-panel h4 {
    color: white;
    margin-bottom: 1rem;
    font-weight: 600;
}

.resume-reading-info {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
    margin-bottom: 1.5rem;
}

.resume-reading-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.resume-reading-buttons .btn {
    min-width: 100px;
}

/* Mobile responsive for resume reading overlay */
@media (max-width: 480px) {
    .resume-reading-panel {
        padding: 1.5rem;
        max-width: 280px;
    }

    .resume-reading-panel h4 {
        font-size: 1.1rem;
    }

    .resume-reading-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .resume-reading-buttons .btn {
        width: 100%;
    }
}

/* Loading more indicator for progressive loading */
#loading-more-indicator {
    position: sticky;
    bottom: 20px;
    z-index: 100;
    margin: 1rem auto;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

#loading-more-indicator.fade-out {
    animation: fadeOut 0.3s ease-out;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* Info Button Styling */
.thumbnail-container {
    position: relative;
}

.info-button {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
    cursor: pointer;
    z-index: 10;
}

.info-button i {
    color: white;
    font-size: 16px;
}

.thumbnail-container:hover .info-button {
    opacity: 1;
}

.info-button:hover {
    background: rgba(0, 0, 0, 0.9);
}

.info-button:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Text File Viewer Modal Styling */
.text-file-content {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 1rem;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 70vh;
    overflow-y: auto;
}

.text-file-content pre {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
}

/* Favorite Button Styling */
.favorite-button {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.favorite-button i {
    color: white;
    font-size: 16px;
}

.thumbnail-container:hover .favorite-button,
.dashboard-card-img-container:hover .favorite-button {
    opacity: 1;
}

.favorite-button:hover {
    background: rgba(0, 0, 0, 0.9);
}

.favorite-button.favorited {
    opacity: 1;
    background: rgba(255, 193, 7, 0.9);
}

.favorite-button.favorited i {
    color: #212529;
}

.favorite-button.favorited:hover {
    background: rgba(255, 193, 7, 1);
}

/* To Read Button Styling */
.to-read-button {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.to-read-button i {
    color: white;
    font-size: 16px;
}

.thumbnail-container:hover .to-read-button,
.dashboard-card-img-container:hover .to-read-button {
    opacity: 1;
}

.to-read-button:hover {
    background: rgba(0, 0, 0, 0.9);
}

.to-read-button:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

.to-read-button.marked {
    opacity: 1;
    background: rgba(255, 193, 7, 0.9);
}

.to-read-button.marked i {
    color: #212529;
}

.to-read-button.marked:hover {
    background: rgba(255, 193, 7, 1);
}

/* Issue Number Badge Styling */
.issue-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgb(253 200 63 / 85%);
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    z-index: 10;
    border: black;
    border-style: solid;
    border-width: thin;
}

.issue-badge .read-icon {
    margin-left: 4px;
    font-size: 0.65rem;
}

/* Dashboard Section Styles */
.dashboard-section {
    position: relative;
}

.dashboard-swiper {
    padding: 10px 5px 30px 5px;
    /* Bottom padding for pagination/scrollbar if needed */
    overflow: hidden;
}

.dashboard-swiper .swiper-slide {
    width: 165px;
}

.dashboard-card {
    width: 100%;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.dashboard-card:hover {
    transform: translateY(-5px);
}

.dashboard-card-img-container {
    position: relative;
    width: 100%;
    height: 247px;
    aspect-ratio: auto;
    border-radius: 8px;
    overflow: hidden;
    background-color: #f8f9fa;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    contain: layout;
}

.dashboard-card-img-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Dashboard cards with folder thumbnails */
.dashboard-card.has-thumbnail .dashboard-card-img-container {
    /* overflow: visible; */
    background-color: transparent;
}

.dashboard-card .icon-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #e9ecef;
}

.dashboard-card .icon-overlay i {
    font-size: 3rem;
    color: #ffc107;
}

.dashboard-card.has-thumbnail .icon-overlay {
    display: none;
}

.dashboard-card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.dashboard-card:hover .dashboard-card-overlay {
    opacity: 1;
}

.dashboard-card-overlay i {
    font-size: 3rem;
    color: rgba(255, 255, 255, 0.9);
}

.dashboard-card-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.dashboard-card-body h6 {
    margin-bottom: 2px;
    font-weight: 600;
    color: var(--bs-body-color);
}

/* Swiper Navigation Customization */
.dashboard-swiper .swiper-button-next,
.dashboard-swiper .swiper-button-prev {
    width: 32px;
    height: 32px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    color: #333;
}

.dashboard-swiper .swiper-button-next:after,
.dashboard-swiper .swiper-button-prev:after {
    font-size: 14px;
    font-weight: bold;
}

.dashboard-swiper .swiper-button-disabled {
    opacity: 0;
    cursor: default;
}

[data-bs-theme="dark"] .dashboard-card-img-container {
    background-color: #2b3035;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

[data-bs-theme="dark"] .dashboard-card .icon-overlay {
    background-color: #343a40;
}

[data-bs-theme="dark"] .dashboard-swiper .swiper-button-next,
[data-bs-theme="dark"] .dashboard-swiper .swiper-button-prev {
    background-color: rgba(40, 40, 40, 0.9);
    color: #fff;
}

/* =============================================================================
   Drag-Drop Upload Zone for Edit Modal
   ============================================================================= */

#editCBZModal .modal-body.drag-over {
    background-color: rgba(33, 150, 243, 0.1);
    border: 2px dashed #2196f3;
    transition: all 0.2s ease;
}

#editCBZModal .modal-body.drag-over::after {
    content: "Drop files to add";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(33, 150, 243, 0.9);
    color: white;
    padding: 1rem 2rem;
    border-radius: 0.5rem;
    font-weight: bold;
    font-size: 1.2rem;
    z-index: 9999;
    pointer-events: none;
}