/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light theme colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-sidebar: #2c3e50;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-sidebar: #ecf0f1;
    --border-color: #dee2e6;
    --accent-color: #3498db;
    --accent-hover: #2980b9;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --transition-speed: 0.3s;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* Sidebar Navigation */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 70px;
    height: 100vh;
    background-color: var(--bg-sidebar);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    transition: width var(--transition-speed);
}

.sidebar:hover {
    width: 200px;
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-brand {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-icon {
    width: 32px;
    height: 32px;
    color: var(--text-sidebar);
    display: inline-block;
}

/* Navigation Items */
.nav-items {
    list-style: none;
    padding: 20px 0;
    flex: 1;
}

.nav-item {
    margin: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    color: var(--text-sidebar);
    text-decoration: none;
    transition: background-color var(--transition-speed);
    position: relative;
    overflow: hidden;
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.nav-link.active {
    background-color: var(--accent-color);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background-color: #fff;
}

.nav-icon {
    width: 24px;
    height: 24px;
    min-width: 24px;
    color: currentColor;
}

.nav-label {
    margin-left: 15px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--transition-speed);
}

.sidebar:hover .nav-label {
    opacity: 1;
}

/* Sidebar Bottom Controls */
.sidebar-bottom {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-toggle {
    width: 100%;
    padding: 10px;
    background-color: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 8px;
    color: var(--text-sidebar);
    cursor: pointer;
    transition: background-color var(--transition-speed);
    display: flex;
    justify-content: center;
    align-items: center;
}

.theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.theme-icon-light,
.theme-icon-dark {
    width: 20px;
    height: 20px;
}

.theme-icon-dark {
    display: none;
}

/* Bottom Navigation (Mobile Only) */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    z-index: 999;
    padding: 0 0 env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    text-decoration: none;
    color: var(--text-secondary);
    transition: color var(--transition-speed);
    position: relative;
    min-height: 56px;
    box-sizing: border-box;
}

.bottom-nav-item:hover {
    color: var(--accent-color);
}

.bottom-nav-item.active {
    color: var(--accent-color);
}

.bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background-color: var(--accent-color);
    border-radius: 0 0 2px 2px;
}

.bottom-nav-icon {
    width: 24px;
    height: 24px;
    margin-bottom: 2px;
}

.bottom-nav-label {
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    text-align: center;
}

/* Main Content Area */
.main-content {
    margin-left: 70px;
    min-height: 100vh;
    background-color: var(--bg-primary);
    transition: margin-left var(--transition-speed);
}

.content-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px;
}

/* Page Header */
.page-header {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.page-header h1 {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Empty States */
.placeholder-content {
    padding: 40px 0;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    background-color: var(--bg-secondary);
    border-radius: 12px;
}

.empty-icon {
    width: 64px;
    height: 64px;
    display: block;
    margin: 0 auto 20px;
    opacity: 0.3;
    color: var(--text-secondary);
}

.empty-state h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.empty-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 20px;
}

/* Settings Cards */
.settings-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.settings-card {
    background-color: var(--bg-secondary);
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.settings-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.settings-icon {
    width: 48px;
    height: 48px;
    display: block;
    margin: 0 auto 15px;
    color: var(--accent-color);
    opacity: 0.8;
}

.settings-card h3 {
    font-size: 1.25rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.settings-card p {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 0.875rem;
}

/* Settings Theme Toggle */
.settings-card .theme-icon-light,
.settings-card .theme-icon-dark {
    width: 48px;
    height: 48px;
    margin: 0 auto 15px;
    display: block;
    color: var(--accent-color);
}

.settings-card .theme-icon-dark {
    display: none;
}

#settingsThemeToggle {
    position: relative;
    overflow: hidden;
}

.theme-text-light,
.theme-text-dark {
    transition: opacity var(--transition-speed);
}

.theme-text-dark {
    display: none;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-speed);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

.btn-secondary {
    background-color: var(--text-secondary);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #5a6268;
}

.btn-scheduled {
    background-color: #f39c12;
    color: white;
}

.btn-scheduled:hover:not(:disabled) {
    background-color: #e67e22;
}

/* Series Grid Layout */
.series-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 40px;
}

/* Series Card */
.series-card {
    position: relative;
    background: var(--bg-primary);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
    display: flex;
    flex-direction: row;
    min-height: 200px;
    border: 1px solid var(--border-color);
}

.series-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

/* NEW Badge */
.new-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    background: #e74c3c;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 10;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

/* Card Thumbnail */
.card-thumbnail {
    position: relative;
    width: 140px;
    height: 100%;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--bg-secondary);
    display: block;
    text-decoration: none;
    transition: transform 0.2s ease;
}

.card-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-speed);
}

.series-card:hover .card-thumbnail img {
    transform: scale(1.05);
}

/* Card Content */
.card-content {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.series-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.4;
}

.series-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.series-title a:hover {
    color: var(--accent-color);
}

/* Merged with main .card-thumbnail rule above */
/* .card-thumbnail hover effect is handled by .series-card:hover .card-thumbnail img */

.series-title {
    max-height: 2.8em; /* Max height for 2 lines instead of min-height */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0; /* Prevent title from shrinking */
}

.chapter-info {
    margin-bottom: 8px;
    flex-shrink: 0;
}

.chapter-number {
    display: inline-block;
    background: var(--accent-color);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
}

.chapter-title {
    display: block;
    font-size: 0.813rem;
    color: var(--text-secondary);
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Meta Info */
.meta-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.813rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    flex-shrink: 0;
}

/* Spacer to push buttons to bottom */
.card-content-spacer {
    flex-grow: 1;
}

.time-ago {
    font-style: italic;
}

/* Source label styling is now handled via inline styles in templates */

/* Card Actions */
.card-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0; /* Prevent button area from shrinking */
    margin-top: auto; /* Push to bottom */
}

.card-actions .btn {
    padding: 6px 12px;
    font-size: 0.875rem;
    text-transform: none;
    letter-spacing: normal;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-icon {
    width: 16px;
    height: 16px;
}

/* Pagination */
.pagination {
    margin-top: 40px;
    padding: 20px 0;
    border-top: 1px solid var(--border-color);
}

.pagination-info {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    transition: all var(--transition-speed);
}

.pagination-btn:hover:not(.disabled) {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.pagination-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-icon {
    width: 16px;
    height: 16px;
}

.page-numbers {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Responsive Design - Keep 2 columns always */

@media (max-width: 768px) {
    /* Hide sidebar on mobile */
    .sidebar {
        display: none;
    }
    
    /* Show bottom navigation on mobile */
    .bottom-nav {
        display: flex;
    }
    
    /* Adjust main content for mobile */
    .main-content {
        margin-left: 0;
    }
    
    .content-wrapper {
        padding: 15px 15px calc(15px + 85px + env(safe-area-inset-bottom, 0));
    }
    
    .page-header h1 {
        font-size: 1.5rem;
    }
    
    /* Keep 2 columns but adjust gap and card layout */
    .series-grid {
        gap: 10px;
    }
    
    .series-grid:not(.list-view) .series-card {
        flex-direction: column;
        height: auto;
    }
    
    /* Ensure list view stays horizontal on mobile */
    .series-grid.list-view .series-card {
        flex-direction: row;
        height: auto;
    }
    
    .series-grid:not(.list-view) .card-thumbnail {
        width: 100%;
        height: 240px;
    }
    
    .card-content {
        padding: 12px;
    }
    
    .series-title {
        font-size: 0.9rem;
        max-height: 2.52em; /* Adjust for smaller font (0.9rem * 1.4 * 2) */
    }
    
    .chapter-info {
        margin-bottom: 8px;
    }
    
    .chapter-number {
        font-size: 0.75rem;
        padding: 2px 6px;
    }
    
    .meta-info {
        font-size: 0.75rem;
        margin-bottom: 8px;
    }
    
    .card-actions .btn {
        padding: 4px 8px;
        font-size: 0.75rem;
    }
    
    .btn-icon {
        width: 14px;
        height: 14px;
    }
    
    .new-badge {
        top: 8px;
        left: 8px;
        padding: 2px 6px;
        font-size: 0.65rem;
    }
}

/* Extra small screens - still maintain 2 columns */
@media (max-width: 480px) {
    .main-content::after {
        content: '';
        display: block;
        height: 46px;
        width: 100%;
    }
    
    .content-wrapper {
        padding: 10px;
    }
    
    .series-grid {
        gap: 4px;
    }
    
    .series-grid:not(.list-view) .card-thumbnail {
        height: 200px;
    }
    
    .card-content {
        padding: 8px;
    }
    
    .series-title {
        font-size: 0.85rem;
        max-height: 2.38em; /* Adjust for even smaller font (0.85rem * 1.4 * 2) */
        margin-bottom: 4px;
    }
    
    /* Stack buttons vertically on very small screens */
    .card-actions {
        flex-direction: column;
        gap: 4px;
    }
    
    .card-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Library Page Specific Styles */

/* Header with button - DEPRECATED: Now using page-header-content structure */
/* .header-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.add-series-btn {
    white-space: nowrap;
} */

/* Filters Bar */
.filters-bar {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-bottom: 20px;
    padding: 12px 16px !important;
    background: transparent !important;
    border: none !important;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.filter-select {
    padding: 8px 12px !important;
    border: 2px solid var(--border-color) !important;
    border-radius: 4px !important;
    background: var(--bg-primary) !important;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important;
    background-position: right 8px center !important;
    background-repeat: no-repeat !important;
    background-size: 16px !important;
    padding-right: 32px !important;
}

.filter-select:hover {
    border-color: var(--accent-color);
    background-color: rgba(52, 152, 219, 0.05);
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent-color);
    background-color: var(--bg-primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* View Toggle Buttons */
.view-toggle {
    margin-left: auto;
    display: flex;
    gap: 4px;
    background: var(--bg-primary);
    padding: 4px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.view-btn {
    padding: 6px 10px;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color var(--transition-speed);
    display: flex;
    align-items: center;
    color: var(--text-secondary);
}

.view-btn:hover {
    background: var(--bg-secondary);
}

.view-btn.active {
    background: var(--accent-color);
    color: white;
}

.view-btn .view-icon {
    width: 18px;
    height: 18px;
    stroke: var(--text-secondary) !important;
}

.view-btn.active .view-icon {
    stroke: white !important;
}

/* Unread Badge */
.unread-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--accent-color);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 24px;
    text-align: center;
    z-index: 10;
}

/* Series Status Badges */
.series-status {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.status-badge,
.type-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
}

.status-badge {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.status-badge.status-ongoing {
    background: #27ae60;
    color: white;
}

.status-badge.status-completed {
    background: #2c3e50;
    color: white;
}

.status-badge.status-hiatus {
    background: #e67e22;
    color: white;
}

.type-badge {
    background: var(--accent-color);
    color: white;
    opacity: 0.8;
}

.no-chapters {
    display: inline-block;
    padding: 4px 8px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 4px;
    font-size: 0.813rem;
    font-style: italic;
}

/* List View Mode */
.series-grid.list-view {
    grid-template-columns: 1fr;
    gap: 12px;
}

.series-grid.list-view .series-card {
    min-height: 160px;
}

.series-grid.list-view .card-thumbnail {
    width: 160px;
    height: 160px;
}

.series-grid.list-view .card-content {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto 1fr auto;
    gap: 4px;
}

.series-grid.list-view .series-title {
    grid-column: 1;
    grid-row: 1;
}

.series-grid.list-view .chapter-info {
    grid-column: 1;
    grid-row: 2;
}

.series-grid.list-view .meta-info {
    grid-column: 1;
    grid-row: 3;
}


.series-grid.list-view .series-status {
    grid-column: 1;
    grid-row: 4;
    align-self: center;
}

.series-grid.list-view .card-actions {
    grid-column: 2;
    grid-row: 1 / -1;
    flex-direction: column;
    justify-content: center;
    margin-top: 0;
}

/* Responsive adjustments for Library filters */
@media (max-width: 768px) {
    /* DEPRECATED: Now using page-header-content structure
    .header-content {
        flex-direction: column;
    }
    
    .add-series-btn {
        width: 100%;
    } */
    
    .filters-bar {
        padding: 8px 12px;
        gap: 10px;
    }
    
    .view-toggle {
        margin-left: auto;
        flex-shrink: 0;
    }
    
    .unread-badge {
        top: 8px;
        right: 8px;
        font-size: 0.65rem;
        padding: 2px 6px;
        min-width: 20px;
    }
    
    /* Mobile list view - adjust thumbnail size for smaller screens */
    .series-grid.list-view .card-thumbnail {
        width: 140px;
        height: 140px;
    }
    
    .series-grid.list-view .series-card {
        min-height: 140px;
    }
    
    /* Mobile list view - completely override desktop layout */
    .series-grid.list-view .card-content {
        display: flex !important;
        flex-direction: column !important;
        gap: 4px;
        padding: 12px;
    }
    
    .series-grid.list-view .card-actions {
        display: flex !important;
        flex-direction: row !important;
        gap: 4px;
        margin-top: 4px;
        order: 999; /* Force to bottom */
    }
    
    /* Force all elements to use normal flow on mobile */
    .series-grid.list-view .series-title,
    .series-grid.list-view .chapter-info,
    .series-grid.list-view .meta-info,
    .series-grid.list-view .series-status,
    .series-grid.list-view .card-actions {
        position: static !important;
        grid-area: unset !important;
        grid-column: unset !important;
        grid-row: unset !important;
    }
}


/* User Info in Sidebar */
.user-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 6px;
    transition: all var(--transition-speed);
}

.username {
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: all var(--transition-speed);
    text-decoration: none;
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.logout-btn svg {
    width: 16px;
    height: 16px;
}

/* Hide username text when sidebar is collapsed */
.sidebar:not(:hover) .username {
    display: none;
}

/* Center logout button when collapsed */
.sidebar:not(:hover) .user-info {
    justify-content: center;
}

.sidebar:not(:hover) .logout-btn {
    margin-right: 0;
}