/* --- Design Tokens & Global Reset --- */
:root {
    /* Dark Mode (Default) */
    --bg-main: #09090b;
    --glass-bg: rgba(24, 24, 27, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --accent-primary: #8b5cf6;
    --accent-secondary: #06b6d4;
    --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));

    /* Dimensions */
    --radius-md: 12px;
    --radius-lg: 24px;
    --item-scale: 4;
    --image-base-size: 15px;
    --title-base-font-size: 0.275rem;
    --category-base-font-size: 0.225rem;
    --checkbox-base-size: 6px;
    --padding-base-size: 0.25rem;
    --margin-base-size: 0.375rem;
}

/* Light Mode Overrides */
:root[data-theme="light"],
[data-theme="light"] {
    --bg-main: #f4f4f5;
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(0, 0, 0, 0.1);
    --text-primary: #18181b;
    --text-secondary: #52525b;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main) !important;
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem 1rem;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- Background & Overlay --- */
.background-overlay {
    position: fixed;
    inset: 0;
    z-index: -2;
    background: radial-gradient(circle at 15% 15%, rgba(139, 92, 246, 0.15), transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(6, 182, 212, 0.15), transparent 40%);
}

/* --- TOP LOADING BAR STYLES --- */
.top-loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
    transition: opacity 0.5s ease, visibility 0.5s ease, transform 0.5s ease;
}

.top-loading-bar.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-100%);
}

#loading-progress-bar {
    width: 90%;
    max-width: 600px;
    height: 6px;
    background: var(--glass-border);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

#loading-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--progress, 0%);
    background: var(--accent-gradient);
    box-shadow: 0 0 10px var(--accent-primary), 0 0 20px var(--accent-secondary);
    transition: width 0.15s ease-out;
    border-radius: 3px;
}

.loading-status-text {
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 6px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* --- SKELETON SHIMMER ANIMATION --- */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

.skeleton-image {
    background: linear-gradient(90deg,
            rgba(139, 92, 246, 0.15) 0%,
            rgba(6, 182, 212, 0.3) 25%,
            rgba(139, 92, 246, 0.4) 50%,
            rgba(6, 182, 212, 0.3) 75%,
            rgba(139, 92, 246, 0.15) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
    border: 1px solid rgba(139, 92, 246, 0.2);
}

/* Skeleton for list item thumbnails */
.skeleton-image.list-item-thumb {
    width: calc(var(--image-base-size) * var(--item-scale));
    height: calc(var(--image-base-size) * var(--item-scale));
    border-radius: 6px;
    margin-right: calc(var(--margin-base-size) * var(--item-scale));
    flex-shrink: 0;
}

/* Skeleton for carousel image */
.skeleton-image.carousel-item-image {
    width: 100%;
    max-width: 400px;
    height: 40vh;
    max-height: 300px;
    margin-bottom: 1rem;
}

/* Skeleton for grid item image */
.skeleton-image.grid-item-image {
    width: 100%;
    aspect-ratio: 1;
    margin-bottom: 0.75rem;
    border-radius: 8px;
}

/* Image fade-in when loaded */
img.list-item-thumb,
img.carousel-item-image,
img.grid-item-image {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.list-item-thumb.loaded,
.carousel-item-image.loaded,
.grid-item-image.loaded {
    opacity: 1;
}

/* --- App Layout --- */
.app-container {
    max-width: 1200px;
    margin: 3rem auto 0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    transition: background 0.3s ease, border 0.3s ease;
}

/* Header & Theme Toggle */
.header-layout {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

h1 {
    font-weight: 700;
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

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

.theme-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.theme-btn:hover {
    background-color: var(--glass-border);
}

[data-theme="light"] .sun-icon {
    display: none;
}

[data-theme="light"] .moon-icon {
    display: block;
}

.sun-icon {
    display: block;
}

.moon-icon {
    display: none;
}

/* --- Main Content Grid --- */
.main-content-grid {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 1.5rem;
    align-items: flex-start;
}

/* --- Left Panel: List View --- */
.list-panel {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    height: 70vh;
}

.list-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

select {
    width: 100%;
    padding: 0.6rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
}

.toggle-group {
    margin-top: 0.5rem;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: var(--text-primary);
}

.toggle-label input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-primary);
}

#checklist-container {
    overflow-y: auto;
    flex-grow: 1;
    padding-right: 5px;
}

#checklist-container::-webkit-scrollbar {
    width: 6px;
}

#checklist-container::-webkit-scrollbar-thumb {
    background-color: var(--glass-border);
    border-radius: 10px;
}

/* --- List Item Styling --- */
.checklist-item {
    display: flex;
    align-items: center;
    padding: calc(var(--padding-base-size) * var(--item-scale));
    border-bottom: 1px solid var(--glass-border);
    transition: background-color 0.2s ease;
    cursor: pointer;
}

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

.checklist-item:hover {
    background-color: rgba(125, 125, 125, 0.1);
}

.checklist-item.active {
    background: var(--accent-gradient);
}

.checklist-item.active h3,
.checklist-item.active p {
    color: white;
}

.checklist-item.checked .item-details h3 {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.checklist-item.checked.active .item-details h3 {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: line-through;
}

.list-item-thumb {
    width: calc(var(--image-base-size) * var(--item-scale));
    height: calc(var(--image-base-size) * var(--item-scale));
    border-radius: 6px;
    object-fit: cover;
    margin-right: calc(var(--margin-base-size) * var(--item-scale));
    background-color: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.item-details {
    flex-grow: 1;
}

.item-details h3 {
    font-size: calc(var(--title-base-font-size) * var(--item-scale));
    font-weight: 600;
    margin-bottom: calc(0.1rem * var(--item-scale));
    color: var(--text-primary);
}

.item-details p {
    font-size: calc(var(--category-base-font-size) * var(--item-scale));
    color: var(--text-secondary);
}

/* --- Checkbox Styling --- */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    background-color: #27272a;
    border: 1px solid #52525b;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, border-color 0.2s;
}

.checklist-item input[type="checkbox"] {
    width: calc(var(--checkbox-base-size) * var(--item-scale));
    height: calc(var(--checkbox-base-size) * var(--item-scale));
    flex-shrink: 0;
    margin-left: calc(var(--margin-base-size) * var(--item-scale));
}

.carousel-item-checkbox {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

input[type="checkbox"]::after {
    content: "";
    width: 30%;
    height: 60%;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) scale(0);
    opacity: 0;
    transition: all 0.2s ease-in-out;
    position: absolute;
    top: 10%;
}

input[type="checkbox"]:checked {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

input[type="checkbox"]:checked::after {
    transform: rotate(45deg) scale(1);
    opacity: 1;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

/* --- Right Panel: Carousel View --- */
.carousel-panel {
    height: 70vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
}

#carousel-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow-y: auto;
    padding: 1rem;
    width: 100%;
}

.carousel-placeholder {
    color: var(--text-secondary);
}

.carousel-item-image {
    max-width: 100%;
    max-height: 40vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    flex-shrink: 1;
}

.carousel-item-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    line-height: 1.2;
    flex-shrink: 0;
}

.carousel-item-category {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.carousel-item-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    background-color: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-primary);
    transition: background 0.2s;
    flex-shrink: 0;
}

.carousel-item-checkbox-label:hover {
    background-color: var(--glass-border);
}

.carousel-navigation {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
    border-top: 1px solid var(--glass-border);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

.nav-arrow {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    font-size: 1.5rem;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-arrow:hover {
    background-color: var(--glass-border);
}

#progress-container {
    flex-grow: 1;
    height: 2rem;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    position: relative;
    overflow: hidden;
}

#progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    transition: width 0.4s ease-in-out;
}

#progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 600;
    color: #ffffff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    font-size: 0.9rem;
    white-space: nowrap;
}

/* --- Footer --- */
.footer-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.slider-group {
    flex-grow: 1;
    max-width: 300px;
}

input[type="range"] {
    width: 100%;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

#clear-all-button {
    padding: 0.75rem 1.5rem;
    border: 1px solid #ef4444;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    color: #ef4444;
    background-color: transparent;
    transition: background-color 0.2s ease, color 0.2s ease;
}

#clear-all-button:hover {
    background-color: #ef4444;
    color: white;
}

/* --- Header Controls & View Toggle --- */
.header-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.header-slider {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    width: 120px;
    margin-right: 0.5rem;
}

.header-slider input[type="range"] {
    height: 6px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.header-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    border: 1px solid transparent;
    /* Reserve space for border state */
    transition: all 0.2s ease;
}

.header-toggle:hover {
    color: var(--text-primary);
    background-color: var(--glass-border);
}

.header-toggle input {
    display: none;
    /* Hide default checkbox */
}

.header-toggle:has(input:checked) {
    color: var(--accent-primary);
    background-color: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.2);
}


.view-toggle {
    display: flex;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 4px;
    gap: 4px;
}

.view-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.view-btn:hover {
    color: var(--text-primary);
    background-color: var(--glass-border);
}

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

/* --- Grid View --- */
.hidden {
    display: none !important;
}

.grid-view-panel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(calc(var(--item-scale) * 45px), 1fr));
    gap: calc(0.2rem + (var(--item-scale) * 0.2rem));
    padding: 2rem;
    min-height: 50vh;
}

.grid-item {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: calc(var(--item-scale) * 0.15rem);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-size: calc(0.25rem * var(--item-scale));
}

.grid-view-panel.hide-labels .grid-item h3,
.grid-view-panel.hide-labels .grid-item p {
    display: none;
}

.grid-view-panel.hide-labels .grid-item {
    padding: calc(var(--item-scale) * 0.1rem);
}

.grid-view-panel.hide-labels .grid-item-image {
    margin-bottom: 0;
    width: 100%;
    height: 100%;
}

.grid-item:hover {
    transform: translateY(-4px);
    background-color: rgba(255, 255, 255, 0.05);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.grid-item-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    margin-bottom: 0.75rem;
    border-radius: 8px;
    transition: transform 0.2s ease;
}

.grid-item h3 {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.grid-item p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Checked State for Grid Item */
.grid-item.checked {
    border: 2px solid #22c55e;
    box-shadow: 0 0 0 1px #22c55e, 0 8px 24px rgba(34, 197, 94, 0.2);
    background: rgba(34, 197, 94, 0.05);
    /* Very subtle green tint */
}

.grid-item.checked .grid-item-image {
    filter: brightness(1.1);
}

.grid-item.checked::after {
    content: "✓";
    position: absolute;
    top: 10px;
    right: 10px;
    background: #22c55e;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}


/* --- Responsiveness --- */
@media (max-width: 900px) {
    .main-content-grid {
        grid-template-columns: 1fr;
    }

    .list-panel {
        height: 40vh;
    }

    .carousel-panel {
        height: auto;
        min-height: 50vh;
    }
}

@media (max-width: 600px) {
    body {
        padding: 1rem 0.5rem;
    }

    .app-container {
        gap: 1rem;
    }

    .glass-card {
        padding: 1rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    .footer-card {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .slider-group {
        max-width: 100%;
    }

    .carousel-panel {
        height: 60vh;
        max-height: 60vh;
    }

    #carousel-view {
        justify-content: flex-start;
        padding-top: 1rem;
    }

    .carousel-item-image {
        max-height: 30vh;
        margin-bottom: 1rem;
    }

    .carousel-item-title {
        font-size: 1.5rem;
    }

    .carousel-item-category {
        margin-bottom: 1rem;
    }

    /* Slim Mobile Header */
    .header-layout {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

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

    .header-controls {
        width: 100%;
        justify-content: space-between;
        gap: 0.75rem;
    }

    .header-slider {
        width: auto;
        flex-grow: 1;
        /* Fill available space */
        margin-right: 0;
        min-width: 0;
        /* Allow shrinking if needed */
    }
}