:root {
    --bg: #f4f7f6;
    --sidebar: #ffffff;
    --card: #ffffff;
    --primary: #00cfd5;
    --primary-dark: #00adb1;
    --text: #333333;
    --text-muted: #888888;
    --border: #eeeeee;
    --shadow: 0 4px 12px rgba(0,0,0,0.05);
    --success: #4caf50;
    --error: #f44336;
}

body.dark-theme {
    --bg: #0f172a;
    --sidebar: #1e293b;
    --card: #334155;
    --primary: #38bdf8;
    --primary-dark: #0ea5e9;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 12px rgba(0,0,0,0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

header {
    background-color: var(--sidebar);
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-actions .btn-sm {
    flex: initial;
    padding: 8px 15px;
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

header h1 span {
    color: var(--primary);
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--bg);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

body.dark-theme .sun, body:not(.dark-theme) .moon {
    display: none;
}

main {
    padding-top: 40px;
    padding-bottom: 40px;
}

/* Search Section */
.search-section {
    margin-bottom: 40px;
}

.search-container {
    position: relative;
    max-width: 700px;
    margin: 0 auto;
}

#searchInput {
    width: 100%;
    padding: 15px 25px;
    border-radius: 30px;
    border: 1px solid var(--border);
    background-color: var(--card);
    color: var(--text);
    box-shadow: var(--shadow);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#searchInput:focus {
    border-color: var(--primary);
}

.search-results {
    position: absolute;
    top: 110%;
    left: 0;
    right: 0;
    background-color: var(--card);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    max-height: 400px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.search-item {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background-color 0.2s;
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover {
    background-color: var(--bg);
}

.search-item .title {
    font-weight: 600;
    display: block;
}

.search-item .meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Sidebar Nav */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 25px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    width: 100%;
}

.nav-item:hover {
    background: var(--bg);
    color: var(--primary);
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

.nav-item svg {
    width: 20px;
    height: 20px;
}

/* Sidebar Library Actions */
.sidebar-actions {
    margin-bottom: 20px;
}

.library-stats-card h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
}

.library-stats-card p {
    font-size: 0.9rem;
    margin-bottom: 5px;
}

/* Library View */
.library-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.library-header h2 {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

#libraryGrid {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    padding-bottom: 20px;
}

.novel-card {
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border);
    position: relative;
    display: flex;
    flex-direction: column;
    cursor: pointer;
}

.novel-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

.card-cover {
    width: 100%;
    height: 240px;
    overflow: hidden;
    position: relative;
    background-color: var(--bg);
}

.card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.status-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 5;
}

.status-badge.synced { background-color: var(--success); }
.status-badge.update-available { background-color: var(--primary); }
.status-badge.unavailable { background-color: var(--error); }
.status-badge.archived { background-color: var(--text-muted); }

/* Update Ribbon */
.update-ribbon {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--error);
    color: white;
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 800;
    z-index: 10;
    border-bottom-right-radius: 12px;
    box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Floating Sync Bar */
.floating-sync-bar {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    border: 1px solid var(--primary);
    padding: 15px 25px;
    border-radius: 50px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 20px;
    z-index: 1000;
    transition: bottom 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.floating-sync-bar.show {
    bottom: 30px;
}

.sync-info {
    font-weight: 600;
}

.sync-count {
    color: var(--primary);
    font-size: 1.2rem;
}

/* Global Progress Bar */
#globalProgressBarContainer {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.global-progress-bar {
    height: 4px;
    background: var(--border);
    margin-top: 10px;
    margin-bottom: 10px;
    border-radius: 2px;
    overflow: hidden;
    display: none;
}

/* Toast Notifications */
.toast-notification {
    position: fixed;
    top: 20px;
    right: -300px;
    background: var(--primary);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 2000;
    transition: right 0.3s ease;
    font-weight: 600;
}

.toast-notification.show {
    right: 20px;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

.card-info {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
    color: var(--text);
}

.card-author {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
}

.card-actions {
    padding: 10px;
    display: flex;
    gap: 8px;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.75rem;
    border-radius: 20px;
    flex: 1;
}

/* Utils */
.w-100 { width: 100%; }
.mb-10 { margin-bottom: 10px; }

/* Dashboard Layout Adjustments */
@media (max-width: 900px) {
    .dashboard-container {
        flex-direction: column;
        height: auto;
    }
    .sidebar {
        flex: 1;
        height: auto;
    }
    .main-content {
        height: 80vh;
    }
}

section {
    background-color: var(--card);
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    margin-bottom: 20px;
}

h2 {
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: 20px;
    border-bottom: 2px solid var(--bg);
    padding-bottom: 10px;
}

/* Task List */
.tasks-card {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.task-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
    padding-right: 5px;
}

.task-list::-webkit-scrollbar {
    width: 6px;
}
.task-list::-webkit-scrollbar-track {
    background: transparent;
}
.task-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.empty-msg {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 20px;
}

.task-item {
    margin-bottom: 20px;
    background-color: var(--bg);
    padding: 15px;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.task-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.task-item.selected {
    background-color: var(--bg);
    border-left-width: 6px;
    box-shadow: inset 0 0 0 1px var(--primary);
}

.task-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.task-controls {
    display: flex;
    gap: 8px;
}

.task-controls button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 5px;
    border-radius: 4px;
    transition: background 0.2s;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.task-controls button:hover {
    background: var(--border);
    color: var(--primary);
}

.task-controls .cancel-btn:hover {
    color: var(--error);
}

.task-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.task-percent {
    color: var(--primary);
    font-weight: 600;
}

.progress-bar {
    background-color: var(--border);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    background-color: var(--primary);
    height: 100%;
    transition: width 0.3s;
}

.task-status {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Completed List */
.completed-section h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 15px;
}

.completed-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--success);
}

/* Log Viewer */
.logs-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.logs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.logs-header h2 {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.selected-task-info {
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 600;
}

.log-viewer {
    background-color: var(--bg);
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 12px;
    flex: 1;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--text);
    line-height: 1.6;
}

.log-viewer::-webkit-scrollbar {
    width: 6px;
}
.log-viewer::-webkit-scrollbar-track {
    background: transparent;
}
.log-viewer::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.log-entry {
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.log-entry .time { color: var(--text-muted); margin-right: 8px; }
.log-entry .level { font-weight: 600; margin-right: 8px; width: 50px; display: inline-block; }
.log-entry .level.INFO { color: var(--primary); }
.log-entry .level.SUCCESS { color: var(--success); }
.log-entry .level.WARNING { color: #ffa000; }
.log-entry .level.ERROR { color: var(--error); }
.log-entry.system { color: var(--text-muted); font-style: italic; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--card);
    color: var(--text);
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.2);
}

.modal h2 {
    margin-bottom: 25px;
    border-bottom: none;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}

.checkbox-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.checkbox-group label {
    font-weight: normal;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

#tasksInput, .text-input {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background-color: var(--bg);
    color: var(--text);
}

.input-with-button {
    display: flex;
    gap: 10px;
}

.input-with-button .text-input {
    flex: 1;
}

.input-with-button button {
    white-space: nowrap;
    padding: 8px 15px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 30px;
}

.btn-primary, .btn-secondary {
    padding: 10px 20px;
    border-radius: 30px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.2s;
}

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

.btn-primary:hover { background-color: var(--primary-dark); }

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

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

/* Preview Modal Specifics */
.preview-modal-content {
    max-width: 650px;
}

.preview-header {
    display: flex;
    gap: 20px;
    margin-bottom: 25px;
}

.preview-cover {
    flex: 0 0 140px;
    height: 200px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.preview-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-info {
    flex: 1;
}

.preview-info h2 {
    font-size: 1.4rem;
    color: var(--text);
    margin-bottom: 12px;
    border-bottom: none;
    padding-bottom: 0;
}

.preview-author, .preview-status {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.preview-author span, .preview-status span {
    color: var(--text);
    font-weight: 500;
}

.genres-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 15px;
}

.genre-tag {
    background: var(--bg);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.preview-stats {
    display: flex;
    justify-content: space-around;
    background: var(--bg);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 25px;
    border: 1px solid var(--border);
}

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

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.stat-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.preview-description h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--text);
}

.desc-content {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-muted);
    max-height: 200px;
    overflow-y: auto;
    padding-right: 10px;
}

/* Scrollbar styling for description */
.desc-content::-webkit-scrollbar {
    width: 4px;
}
.desc-content::-webkit-scrollbar-track {
    background: var(--bg);
}
.desc-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* Selection Modal Specifics */
.selection-modal-content {
    max-width: 700px;
    height: 80vh;
    display: flex;
    flex-direction: column;
}

.selection-search {
    margin-bottom: 15px;
}

#chapterSearchInput {
    width: 100%;
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background-color: var(--bg);
    color: var(--text);
    outline: none;
    font-size: 0.95rem;
}

#chapterSearchInput:focus {
    border-color: var(--primary);
}

.chapter-tree-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    background: var(--bg);
}

.loading-msg {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.volume-item {
    margin-bottom: 15px;
}

.volume-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text);
    padding: 8px;
    background: var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
}

.volume-header:hover {
    background: var(--bg);
}

.volume-header input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.chapter-list {
    padding-left: 25px;
}

.chapter-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 4px;
    transition: background 0.1s;
    font-size: 0.9rem;
}

.chapter-item:hover {
    background: var(--border);
}

.chapter-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.chapter-item.locked {
    opacity: 0.5;
    color: var(--text-muted);
}

.chapter-item.locked input[type="checkbox"] {
    cursor: not-allowed;
}

.chapter-item.hidden {
    display: none;
}

.volume-item.hidden {
    display: none;
}

.selection-footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.selection-stats {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
}

#selectedChaptersCount {
    color: var(--primary);
    font-weight: 700;
}
