.templates-page {
    max-width: 1300px;
    margin: 0 auto;
    padding: 40px 5% 80px;
}

.templates-header {
    text-align: center;
    margin-bottom: 40px;
}

.page-title {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 20px;
    background: linear-gradient(to right, #ffffff 30%, #5eead4 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
    /* Prevent flash before JS runs */
    opacity: 0;
    visibility: hidden;
}

.page-subtitle {
    font-size: 1.25rem;
    color: #94a3b8;
    max-width: 650px;
    margin: 0 auto;
    line-height: 1.6;
    letter-spacing: 0.2px;
    /* Prevent flash before JS runs */
    opacity: 0;
    visibility: hidden;
}

/* Filters & Search */
.filters-section {
    margin-bottom: 60px;
}

.filter-wrapper {
    display: flex;
    flex-direction: column;
    gap: 32px;
    align-items: center;
}

.search-box {
    position: relative;
    width: 100%;
    max-width: 500px;
}

.search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: #64748b;
    font-size: 1.2rem;
}

#templateSearch {
    width: 100%;
    padding: 16px 20px 16px 55px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    color: #f8fafc;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

#templateSearch:focus {
    outline: none;
    border-color: #14b8a6;
    background: rgba(15, 23, 42, 0.8);
    box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.15);
}

.filter-chips {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.filter-chip {
    padding: 10px 24px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 100px;
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.filter-chip:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.filter-chip.active {
    background: linear-gradient(135deg, #14b8a6 0%, #2dd4bf 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 10px 25px -5px rgba(20, 184, 166, 0.4);
}

/* Template Grid Premium Styles */
.template-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

.template-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    /* Animation Initial State */
    opacity: 0;
    transform: translateY(25px);
    transition: opacity 0.8s cubic-bezier(0.2, 0.8, 0.2, 1),
        transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1),
        border-color 0.4s ease,
        background 0.4s ease,
        box-shadow 0.4s ease;
}

.template-card.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.template-card:hover {
    transform: translateY(-10px);
    border-color: rgba(20, 184, 166, 0.4);
    background: rgba(30, 41, 59, 0.8);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    /* Faster hover transition */
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.4s ease,
        background 0.4s ease,
        box-shadow 0.4s ease;
}

.template-preview {
    height: 220px;
    position: relative;
    overflow: hidden;
    background: #0f172a;
    transform: translateZ(0);
    /* Force GPU layer for parent */
}

.template-preview img {
    width: 102%;
    /* Increased overlap */
    height: 102%;
    object-fit: cover;
    object-position: top;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    display: block;
    backface-visibility: hidden;
    will-change: transform;
    margin: -1%;
    /* Center the larger image */
}

.template-card:hover .template-preview img {
    transform: scale(1.08);
    /* Keep scale on image but ensure parent hides overflow */
}

/* Overlay on Hover */
.template-preview::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.9) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.template-card:hover .template-preview::after {
    opacity: 1;
}

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

.template-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: #f8fafc;
    margin-bottom: 4px;
}

.template-desc {
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.4;
    margin-bottom: 8px;
    height: 2.8em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
}

.template-tags {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.tag {
    font-size: 0.75rem;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 100px;
    color: #94a3b8;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.template-card[data-category="ats"] .tag {
    background: rgba(20, 184, 166, 0.1);
    border-color: rgba(20, 184, 166, 0.2);
    color: #2dd4bf;
}

.template-card[data-category="minimal"] .tag {
    background: rgba(20, 184, 166, 0.1);
    border-color: rgba(20, 184, 166, 0.2);
    color: #2dd4bf;
}

.template-card[data-category="academic"] .tag {
    background: rgba(244, 63, 94, 0.1);
    border-color: rgba(244, 63, 94, 0.2);
    color: #fca5a5;
}

.template-card[data-category="developer"] .tag {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.2);
    color: #fdba74;
}

.template-card[data-category="student"] .tag {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

/* Action Button */
.use-template-btn {
    margin-top: auto;
    width: 100%;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    border-radius: 10px;
    text-align: center;
    text-decoration: none;
    transition: all 0.3s ease;
}

.template-card:hover .use-template-btn {
    background: linear-gradient(135deg, #14b8a6 0%, #2dd4bf 100%);
    border-color: transparent;
    box-shadow: 0 4px 15px rgba(20, 184, 166, 0.4);
    transform: translateY(-2px);
}

.use-template-btn:active {
    transform: translateY(0);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 120px 0;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 32px;
    border: 2px dashed rgba(255, 255, 255, 0.05);
}

.empty-icon {
    font-size: 5rem;
    display: block;
    margin-bottom: 24px;
    filter: grayscale(1);
    opacity: 0.2;
}

.empty-state h3 {
    font-size: 1.75rem;
    color: #f8fafc;
    margin-bottom: 12px;
}

.empty-state p {
    color: #94a3b8;
    font-size: 1.1rem;
}

/* Responsive Grid */
@media (max-width: 1200px) {
    .template-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
}

@media (max-width: 992px) {
    .template-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .templates-page {
        padding: 60px 20px;
    }

    .page-title {
        font-size: 2.5rem;
    }

    .template-grid {
        grid-template-columns: 1fr;
        gap: 30px;
    }

    .template-preview {
        height: 320px;
    }

    .filter-chip {
        padding: 8px 18px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .page-title {
        font-size: 2rem;
    }

    .template-info {
        padding: 20px;
    }
}

/* Scroll Animations */
.scroll-animate {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: opacity, transform;
}

.scroll-animate.is-visible {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}

/* Word Reveal Animation */
.word {
    display: inline-block;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: opacity, transform;
    background: inherit;
    -webkit-background-clip: inherit;
    background-clip: inherit;
    -webkit-text-fill-color: inherit;
}

.word.visible {
    opacity: 1;
    transform: translateY(0);
}

.word:last-child {
    margin-right: 0;
}