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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #f59e0b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* Main Content */
.main-content {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
}

/* Search Section */
.search-section {
    margin-bottom: 1.5rem;
}

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

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    padding: 0.75rem 1.25rem;
    box-shadow: var(--shadow-lg);
    border: 2px solid transparent;
    transition: border-color var(--transition-fast);
}

.search-box:focus-within {
    border-color: var(--primary-color);
}

.search-icon {
    width: 24px;
    height: 24px;
    color: var(--text-light);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1rem;
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-primary);
}

.search-box input::placeholder {
    color: var(--text-light);
}

.clear-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    transition: all var(--transition-fast);
}

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

.clear-btn svg {
    width: 18px;
    height: 18px;
}

/* Filters Section */
.filters-section {
    margin-bottom: 1.5rem;
}

.filters-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    align-items: center;
    background: var(--bg-primary);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.filter-group select {
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-primary);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    transition: border-color var(--transition-fast);
}

.filter-group select:hover {
    border-color: var(--primary-color);
}

.filter-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.favorites-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.favorites-btn:hover {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.favorites-btn.active {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: white;
}

.favorites-btn svg {
    width: 18px;
    height: 18px;
}

.badge {
    background: var(--primary-color);
    color: white;
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-weight: 600;
}

.favorites-btn.active .badge {
    background: white;
    color: var(--danger-color);
}

/* Results Info */
.results-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
    color: white;
    font-size: 0.875rem;
}

.clear-filters-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.clear-filters-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Templates Grid */
.templates-section {
    min-height: 400px;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* Template Card */
.template-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-normal);
    cursor: pointer;
    position: relative;
}

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

.template-image {
    position: relative;
    padding-top: 66.67%;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.template-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-normal);
}

.template-card:hover .template-image img {
    transform: scale(1.05);
}

.template-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, transparent 50%, rgba(0, 0, 0, 0.6));
    opacity: 0;
    transition: opacity var(--transition-fast);
    display: flex;
    align-items: flex-end;
    padding: 1rem;
}

.template-card:hover .template-overlay {
    opacity: 1;
}

.preview-btn {
    background: white;
    color: var(--text-primary);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.favorite-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
    z-index: 10;
}

.favorite-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-light);
    transition: all var(--transition-fast);
}

.favorite-btn:hover svg {
    color: var(--danger-color);
}

.favorite-btn.active svg {
    color: var(--danger-color);
    fill: var(--danger-color);
}

.template-content {
    padding: 1rem;
}

.template-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.template-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.template-category {
    background: var(--primary-light);
    color: var(--primary-color);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.template-source {
    color: var(--text-light);
}

.template-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.template-tag {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

/* No Results */
.no-results {
    text-align: center;
    padding: 4rem 2rem;
    color: white;
}

.no-results svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.no-results h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.no-results p {
    opacity: 0.8;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    padding: 1rem;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    position: relative;
    transform: scale(0.9);
    transition: transform var(--transition-normal);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 10;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
}

.modal-close svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.modal-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    max-height: 90vh;
}

.preview-image-container {
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    max-height: 90vh;
    overflow: hidden;
}

.preview-image-container img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.preview-details {
    padding: 2rem;
    overflow-y: auto;
    max-height: 90vh;
}

.preview-details h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.preview-details > p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.preview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.meta-item svg {
    width: 18px;
    height: 18px;
    color: var(--primary-color);
}

.preview-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.preview-tags .template-tag {
    font-size: 0.875rem;
    padding: 0.25rem 0.75rem;
}

.preview-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.action-btn svg {
    width: 20px;
    height: 20px;
}

.favorite-action {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.favorite-action:hover {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.favorite-action.active {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: white;
}

.favorite-action.active svg {
    fill: white;
}

.primary-action {
    background: var(--primary-color);
    border: none;
    color: white;
}

.primary-action:hover {
    background: var(--primary-hover);
}

/* Footer */
.footer {
    background: rgba(0, 0, 0, 0.2);
    padding: 1.5rem 2rem;
    margin-top: auto;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
}

.footer p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.875rem;
}

.footer a {
    color: white;
    text-decoration: none;
    font-weight: 600;
    transition: opacity var(--transition-fast);
}

.footer a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Responsive Styles */
@media (max-width: 900px) {
    .modal-body {
        grid-template-columns: 1fr;
    }

    .preview-image-container {
        max-height: 40vh;
        padding: 1rem;
    }

    .preview-image-container img {
        max-height: 35vh;
    }

    .preview-details {
        max-height: 50vh;
        padding: 1.5rem;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .tagline {
        font-size: 0.875rem;
    }

    .main-content {
        padding: 1rem;
    }

    .search-box {
        padding: 0.5rem 1rem;
    }

    .search-box input {
        font-size: 0.875rem;
    }

    .filters-container {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filter-group {
        width: 100%;
        justify-content: space-between;
    }

    .filter-group select {
        flex: 1;
        max-width: 200px;
    }

    .favorites-btn {
        width: 100%;
        justify-content: center;
    }

    .templates-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 1rem;
    }

    .results-info {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .modal-content {
        max-height: 95vh;
    }

    .preview-details h2 {
        font-size: 1.25rem;
    }

    .preview-actions {
        position: sticky;
        bottom: 0;
        background: var(--bg-primary);
        padding-top: 1rem;
        margin: 0 -1.5rem -1.5rem;
        padding: 1rem 1.5rem 1.5rem;
        box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1);
    }
}

@media (max-width: 480px) {
    .templates-grid {
        grid-template-columns: 1fr;
    }

    .logo {
        flex-direction: column;
        gap: 0.5rem;
    }

    .logo-img {
        width: 32px;
        height: 32px;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.template-card {
    animation: fadeIn 0.3s ease forwards;
}

.template-card:nth-child(1) { animation-delay: 0.05s; }
.template-card:nth-child(2) { animation-delay: 0.1s; }
.template-card:nth-child(3) { animation-delay: 0.15s; }
.template-card:nth-child(4) { animation-delay: 0.2s; }
.template-card:nth-child(5) { animation-delay: 0.25s; }
.template-card:nth-child(6) { animation-delay: 0.3s; }
.template-card:nth-child(7) { animation-delay: 0.35s; }
.template-card:nth-child(8) { animation-delay: 0.4s; }

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
