:root {
    --bg: #141414;
    --fg: #ffffff;
    --fg2: #e5e5e5;
    --red: #e50914;
    --red-dark: #b20710;
    --input-bg: #2b2b2b;
    --input-focus: #3a3a3a;
    --border: rgba(255,255,255,0.1);
    --card-bg: rgba(255,255,255,0.04);
    --ease: all 0.3s cubic-bezier(0.25,0.8,0.25,1);
}

html { scroll-behavior: smooth; box-sizing: border-box; }
*, *:before, *:after { box-sizing: inherit; margin: 0; padding: 0; }

body {
    background-color: #141414;
    color: #ffffff;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    overflow-x: hidden;
    min-height: 100vh;
}

h1, h2, h3, h4 { font-weight: 700; margin-bottom: 0.6rem; }
p { color: #e5e5e5; line-height: 1.6; }

/* ── Utilities ─────────────────────── */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Buttons ─────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.72rem 1.3rem;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.92rem;
    white-space: nowrap;
    transition: background 0.2s, transform 0.15s;
    text-decoration: none;
}
.btn-primary { background-color: #e50914; color: #fff; }
.btn-primary:hover { background-color: #b20710; transform: scale(1.04); }
.btn-secondary { background-color: rgba(109,109,110,0.72); color: #fff; }
.btn-secondary:hover { background-color: rgba(109,109,110,0.95); transform: scale(1.04); }

/* ── Auth ─────────────────────── */
.auth-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 24px 16px 60px;
    background:
        linear-gradient(to right, rgba(0,0,0,0.85), rgba(0,0,0,0.6)),
        url('https://images.unsplash.com/photo-1524995997946-a1c2e315a42f?q=80&w=1920&auto=format&fit=crop')
        no-repeat center center / cover;
    background-attachment: fixed;
}

#auth-brand {
    font-size: clamp(2.8rem,8vw,4.5rem);
    font-weight: 900;
    color: #e50914;
    letter-spacing: -2px;
    text-shadow: 0 0 40px rgba(229,9,20,0.5);
    margin-bottom: 20px;
    margin-top: 16px;
}

.auth-box {
    background: rgba(10,10,10,0.9);
    padding: 2rem 1.8rem 1.5rem;
    border-radius: 12px;
    width: 100%;
    max-width: 560px;
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(16px);
    box-shadow: 0 24px 60px rgba(0,0,0,0.7);
}

.auth-box h2 { font-size: 1.6rem; margin-bottom: 1.2rem; }

/* ── Form Sections ─────────────────── */
.form-section {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 10px;
    padding: 1.1rem 1.1rem 0.3rem;
    margin-bottom: 1rem;
}
.form-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #e50914;
    margin-bottom: 0.9rem;
}

.input-group { margin-bottom: 0.9rem; padding: 0 10px !important; box-sizing: border-box !important; }
.input-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.84rem;
    color: #ccc;
    font-weight: 500;
}
.tip { font-size: 0.72rem; color: #777; font-weight: 400; margin-left: 4px; }
.req { color: #e50914; }

.input-group input,
.input-group textarea,
.input-group select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.78rem 0.9rem;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.1);
    background: #2b2b2b;
    color: #fff;
    font-size: 0.92rem;
    outline: none;
    transition: border 0.2s, background 0.2s;
    font-family: inherit;
}
.input-group textarea {
    resize: vertical;
}
.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
    background: #3a3a3a;
    border-color: #e50914;
    box-shadow: 0 0 0 3px rgba(229,9,20,0.15);
}
.input-group select option { background: #222; }

/* ── TomSelect Overrides ─────────────────── */
.ts-wrapper.single .ts-control {
    display: flex !important;
    align-items: center !important;
    gap: 5px;
    padding: 0.5rem 0.9rem !important; /* Adjust if it feels too tall compared to native inputs */
}
.ts-wrapper.single .ts-control .item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90%;
    margin: 0 !important;
}
.ts-wrapper.single .ts-control input {
    height: auto !important;
    margin: 0 !important;
    flex-grow: 1 !important;
    width: 2px !important; /* shrink it to allow item to take space */
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }

/* ── Checkboxes ─────────────────── */
.checkbox-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    background: #2b2b2b;
    padding: 0.85rem;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.1);
}
.checkbox-group label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    color: #ddd;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background 0.15s;
    margin-bottom: 0 !important;
}
.checkbox-group label:hover { background: rgba(255,255,255,0.07); }
.checkbox-group input[type=checkbox] {
    width: 15px; height: 15px;
    accent-color: #e50914;
    flex-shrink: 0;
    padding: 0; margin: 0;
}

.auth-box form { display: flex; flex-direction: column; }
.auth-box .btn-primary { 
    align-self: flex-end; 
    width: auto; 
    min-width: 180px;
    margin-top: 1.5rem; 
    padding-left: 2rem;
    padding-right: 2rem;
}
.auth-links { text-align: center; margin-top: 1.5rem; }
.auth-links a { color: white; font-weight: 700; text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }


/* ── Navbar ─────────────────────── */
nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 4%;
    background: linear-gradient(180deg, rgba(0,0,0,0.92) 0%, transparent 100%);
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 100;
    transition: background-color 0.4s;
    gap: 20px;
}
.nav-left { flex-shrink: 1; }
.nav-right { flex-shrink: 0; }
nav.scrolled { background-color: #141414; }

.brand {
    font-size: clamp(1.4rem,4vw,2rem);
    font-weight: 900;
    color: #e50914;
    letter-spacing: -1px;
    flex-shrink: 0;
}
.nav-links {
    display: flex;
    align-items: center;
    gap: 15px;
}
#nav-profile-circle {
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}
#nav-profile-circle:hover {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(229,9,20,0.4);
}
#nav-profile-circle:hover::after {
    content: attr(data-title);
    position: absolute;
    bottom: -35px;
    right: 0;
    background: #333;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    font-weight: 500;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

/* ── Expanding Search Bar ─────────────────── */
.search-container {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #777;
    cursor: pointer;
    z-index: 2;
    transition: color 0.3s;
}

#main-search {
    background: transparent;
    border: 1px solid transparent;
    color: white;
    padding: 8px 12px 8px 35px;
    border-radius: 20px;
    width: 40px;
    font-size: 0.9rem;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s, border-color 0.3s;
    outline: none;
    cursor: pointer;
}

#main-search:focus,
#main-search:not(:placeholder-shown) {
    width: 250px;
    background: #141414;
    border-color: #333;
    cursor: text;
}

#main-search:focus + .search-icon,
#main-search:not(:placeholder-shown) + .search-icon {
    color: #fff;
}

.brand-subtext {
    transition: opacity 0.3s;
}

/* ── Category Navigation ─────────────────── */
.nav-categories {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-cat-link {
    color: #e5e5e5;
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s, transform 0.15s;
    position: relative;
    white-space: nowrap;
}

.nav-cat-link:hover {
    color: #fff;
    transform: translateY(-1px);
}

/* Tooltip for navigation items (placed ON TOP) */
[data-title] {
    position: relative;
}
[data-title]:hover::before {
    content: attr(data-title);
    position: absolute;
    top: calc(100% + 15px); /* Positioned below to avoid top-of-screen clipping */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(18, 18, 18, 0.98);
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 999;
    pointer-events: none;
    animation: fadeInDown 0.2s ease forwards;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translate(-50%, -10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.nav-cat-link::after {
    content: "";
    position: absolute;
    bottom: -6px;
    left: 0;
    width: 0;
    height: 2px;
    background: #e50914;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-cat-link:hover::after {
    width: 100%;
}

/* ── Hero ─────────────────────── */
.hero {
    min-height: 80vh;
    display: flex;
    align-items: flex-end;
    padding: 130px 4% 60px; /* Increased top padding to clear nav and brand */
    position: relative;
    background:
        linear-gradient(90deg, #141414 0%, rgba(20,20,20,0.5) 60%, transparent 100%),
        url('https://images.unsplash.com/photo-1507842217343-583bb7270b66?q=80&w=1920&auto=format&fit=crop')
        no-repeat center center / cover;
}
.hero-content { 
    max-width: 620px; 
    z-index: 2; 
    position: relative; 
    transition: transform 0.4s ease-out;
}
.hero-content h1 { 
    font-size: clamp(2rem,6vw,3.8rem); 
    font-weight: 800;
    line-height: 1.1; 
    text-shadow: 2px 2px 8px rgba(0,0,0,0.9); 
    margin-bottom: 1rem;
}
.hero-buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 1.5rem; }

/* ── Row Sliders ─────────────────── */
.row { padding: 1.5rem 0; width: 100%; position: relative; }
.row-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem; }
.row-header h2 { font-size: 1.25rem; }
.row-posters {
    display: flex;
    overflow-y: hidden;
    overflow-x: scroll;
    padding: 0.8rem 0;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
.row-posters::-webkit-scrollbar { display: none; }
.poster {
    object-fit: cover;
    width: 170px;
    height: 240px;
    margin-right: 10px;
    border-radius: 6px;
    transition: transform 0.3s;
    cursor: pointer;
    flex-shrink: 0;
    background: #222;
}
.poster:hover { transform: scale(1.08); }

/* --- Poster Title Hover Expansion --- */
.poster-card-label {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(20, 20, 20, 0.9);
    padding: 10px 8px;
    font-size: 0.75rem;
    color: #eee;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    z-index: 5;
    max-height: 40px; /* Initial truncated height */
}

.poster-card:hover .poster-card-label {
    max-height: 100%;
    white-space: normal;
    background: rgba(0, 0, 0, 0.95);
    padding-top: 15px;
    padding-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.poster-sm { width: 130px; height: 185px; }
.poster-sm:hover { transform: scale(1.05); }

/* ── Category Full View ─────────────────── */
.category-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.cat-filter-select {
    background: rgba(43, 43, 43, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #eee;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 140px;
}

.cat-filter-select:hover {
    background: rgba(60, 60, 60, 0.8);
    border-color: rgba(255, 255, 255, 0.2);
}

.cat-filter-select:focus {
    border-color: var(--red);
    box-shadow: 0 0 0 2px rgba(229, 9, 20, 0.2);
}

/* ── Modal ─────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal-overlay.active { display: flex; animation: fadeIn 0.3s ease forwards; }

.modal-content {
    background: #141414;
    width: 90%;
    max-width: 850px;
    max-height: 90vh;
    border-radius: 12px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
}
.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    z-index: 100;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    width: 38px; height: 38px;
    font-size: 1.1rem;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.modal-close:hover { background: white; color: black; }

/* ── Admin ─────────────────────── */
.admin-container { padding: 20px 3%; }
.admin-tabs { padding-bottom: 8px; }
.admin-card {
    background: #1e1e1e;
    padding: 1.8rem;
    border-radius: 10px;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(255,255,255,0.08);
}
.data-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.data-table th, .data-table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    font-size: 0.88rem;
}
.data-table th { color: #999; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.03); }

/* ── Related ─────────────────────── */
.related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px,1fr));
    gap: 1rem;
    margin-top: 1rem;
}

/* ── Stat Cards ─────────────────── */
.stat-card {
    background: #1a1a2e;
    border-radius: 8px;
    padding: 1.2rem;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.08);
}
.stat-card .stat-num { font-size: 2rem; font-weight: 800; margin-bottom: 4px; }
.stat-card .stat-label { color: #aaa; font-size: 0.85rem; }

/* ── Responsive ─────────────────── */
@media (max-width: 992px) {
    .brand-subtext { display: none; }
    #main-search:focus,
    #main-search:not(:placeholder-shown) {
        width: 180px;
    }
}

@media (max-width: 768px) {
    .auth-box { padding: 1.4rem 1.1rem 1rem; }
    .form-row { grid-template-columns: 1fr; }
    .checkbox-group { grid-template-columns: 1fr; }

    nav { padding: 0.7rem 4%; }
    .nav-links .btn { padding: 0.5rem 0.75rem; font-size: 0.8rem; }
    .nav-links #welcome-user { display: none; } /* Hide welcome text on mobile to save space */
    .brand { font-size: 1.4rem; }
    .brand-subtext { display: none; }
    
    .nav-categories { gap: 10px; }
    .nav-cat-link { font-size: 0.72rem; }
    .nav-left { gap: 15px !important; }

    #main-search:focus,
    #main-search:not(:placeholder-shown) {
        width: 150px;
    }

    .hero { min-height: 60vh; padding: 80px 4% 30px; }
    .hero-content h1 { font-size: 1.7rem; }

    .row { padding: 1rem 3%; }
    .poster { width: 130px; height: 185px; }

    .modal-content { width: 97%; border-radius: 8px; }
    .admin-card { padding: 1rem; }
    .data-table th, .data-table td { padding: 0.55rem 0.5rem; font-size: 0.78rem; }
}

@media (max-width: 640px) {
    .nav-categories { display: none; } /* Hide categories on very small screens, maybe use a burger later */
}

@media (max-width: 580px) {
    .nav-links #admin-btn { display: none !important; } /* Hide admin btn on very small screens, use hub instead if needed or menu */
    #logout-btn span { display: none; } /* Hide "Logout" text on mobile */
    #logout-btn { padding: 8px 12px; }
}
@media (max-width: 480px) {
    #auth-brand { font-size: 2.8rem; }
    .auth-box { padding: 1.1rem 0.9rem; }
    .btn { padding: 0.63rem 0.95rem; font-size: 0.86rem; }
    .poster { width: 110px; height: 158px; }
}

/* ── Search Results Grid ─────────────────── */
.search-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px 10px;
    padding: 0 4% 50px 4%;
    justify-items: start;
    justify-content: flex-start;
}

/* ── Animated Icons ─────────────────── */
.flipping-book {
    display: inline-block;
    position: relative;
    width: 1.2em;
    height: 1.2em;
    perspective: 300px;
    margin-right: 8px;
    vertical-align: middle;
}

.flipping-book i {
    animation: openCloseBook 2.5s infinite ease-in-out;
    transform-origin: center;
}

@keyframes openCloseBook {
    0%, 100% { transform: rotateY(0deg) scale(1); }
    50% { transform: rotateY(-30deg) scale(1.1); }
}

.animated-eye {
    display: inline-block;
    animation: blinkEye 3s infinite;
}

@keyframes blinkEye {
    0%, 90%, 100% { transform: scaleY(1); opacity: 1; }
    95% { transform: scaleY(0.1); opacity: 0.5; }
}

.animated-download {
    display: inline-block;
    animation: bounceDownload 2s infinite;
}

@keyframes bounceDownload {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(4px); }
}

.animated-like {
    display: inline-block;
    animation: pulseLike 1.5s infinite;
}

@keyframes pulseLike {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

@media (max-width: 768px) {
    .search-results-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 15px 10px;
    }
}

.pdf-nav-btn:hover { opacity: 1 !important; }

/* ── Package Download ─────────────────── */
/* Card highlighted when selected in select-mode */
.pkg-selected {
    outline: 3px solid #e50914 !important;
    outline-offset: -2px;
    box-shadow: 0 0 0 3px rgba(229,9,20,0.35), 0 4px 20px rgba(0,0,0,0.6) !important;
    transform: scale(1.04) !important;
}
/* Checkmark overlay shown on selected cards */
.pkg-check-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    background: #e50914;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10;
    pointer-events: none;
}
.pkg-selected .pkg-check-overlay {
    opacity: 1;
    transform: scale(1);
}
/* Spinner keyframe for bundling modal */
@keyframes pkgSpin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* Toast slide animations */
@keyframes pkgToastIn {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes pkgToastOut {
    from { opacity: 1; transform: translate(-50%, 0); }
    to   { opacity: 0; transform: translate(-50%, 20px); }
}