/* =========================================================
   CHATNEX — TEMPLATE SYSTEM

   File: css/templates.css

   Purpose:
   - Shared template-system styles
   - Website template UI
   - App template UI
   - Template cards
   - Template filters
   - Template previews
   - Template badges
   - Download / preview controls
   - Template detail components
   - Template states
   - Template-specific visual variants

   Architecture:
   - Global styles:
       /css/main.css
   - Responsive styles:
       /css/responsive.css
   - Shared template styles:
       /css/templates.css
   - Page-specific styles:
       /css/components/

   IMPORTANT:
   - No page-specific layout belongs here.
   - No responsive breakpoints belong here.
   - No template data or JavaScript belongs here.
========================================================= */


/* =========================================================
   01. TEMPLATE PAGE FOUNDATION
========================================================= */

.templates-page {
    position: relative;
    width: 100%;
    min-height: 100vh;
    overflow-x: hidden;
}

.templates-page-header {
    position: relative;
    max-width: 850px;
    margin: 0 auto 55px;
    text-align: center;
}

.templates-page-header .section-label {
    margin-bottom: 14px;
}

.templates-page-header .section-title {
    margin-bottom: 18px;
}

.templates-page-header .section-description {
    max-width: 720px;
    margin-inline: auto;
}


/* =========================================================
   02. TEMPLATE CATEGORY SWITCHER
========================================================= */

.template-category-switcher {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 auto 40px;
}

.template-category-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 46px;
    padding: 11px 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 650;
    cursor: pointer;
    transition:
        color var(--transition-normal),
        background var(--transition-normal),
        border-color var(--transition-normal),
        box-shadow var(--transition-normal),
        transform var(--transition-normal);
}

.template-category-btn:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

.template-category-btn:focus-visible {
    outline: 2px solid var(--brand-cyan);
    outline-offset: 3px;
}

.template-category-btn.active,
.template-category-btn[aria-pressed="true"] {
    color: var(--text-white);
    background: var(--gradient-brand);
    border-color: transparent;
    box-shadow: var(--shadow-blue);
}

.template-category-btn svg,
.template-category-btn i {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}


/* =========================================================
   03. TEMPLATE TOOLBAR
========================================================= */

.templates-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 30px;
}

.templates-toolbar-left,
.templates-toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.templates-toolbar-left {
    flex: 1;
}

.templates-toolbar-right {
    flex-shrink: 0;
}


/* =========================================================
   04. TEMPLATE SEARCH
========================================================= */

.template-search {
    position: relative;
    width: 100%;
    max-width: 430px;
}

.template-search-input {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px 12px 45px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition:
        border-color var(--transition-normal),
        box-shadow var(--transition-normal),
        background var(--transition-normal);
}

.template-search-input::placeholder {
    color: var(--text-muted);
}

.template-search-input:hover {
    border-color: var(--border-strong);
}

.template-search-input:focus,
.template-search-input:focus-visible {
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.template-search-icon {
    position: absolute;
    top: 50%;
    left: 15px;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
    transform: translateY(-50%);
}


/* =========================================================
   05. TEMPLATE SORT
========================================================= */

.template-sort {
    position: relative;
}

.template-sort-select {
    min-height: 48px;
    min-width: 175px;
    padding: 12px 38px 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    transition:
        border-color var(--transition-normal),
        background var(--transition-normal),
        box-shadow var(--transition-normal);
}

.template-sort-select:hover {
    border-color: var(--border-strong);
}

.template-sort-select:focus,
.template-sort-select:focus-visible {
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}


/* =========================================================
   06. TEMPLATE FILTERS
========================================================= */

.template-filters {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    margin-bottom: 38px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.template-filters::-webkit-scrollbar {
    display: none;
}

.template-filter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 40px;
    padding: 9px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 650;
    white-space: nowrap;
    cursor: pointer;
    transition:
        color var(--transition-normal),
        background var(--transition-normal),
        border-color var(--transition-normal),
        transform var(--transition-normal);
}

.template-filter:hover {
    color: var(--text-primary);
    background: var(--bg-card);
    border-color: var(--border-strong);
}

.template-filter.active,
.template-filter[data-active="true"] {
    color: var(--text-white);
    background: var(--brand-blue);
    border-color: var(--brand-blue);
    box-shadow: var(--shadow-blue);
}


/* =========================================================
   07. TEMPLATE RESULTS HEADER
========================================================= */

.template-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 24px;
}

.template-results-count,
.template-count,
.results-count {
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.template-results-count strong,
.template-count strong,
.results-count strong {
    color: var(--text-primary);
    font-weight: 750;
}

.template-view-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.template-view-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition:
        color var(--transition-normal),
        background var(--transition-normal),
        border-color var(--transition-normal);
}

.template-view-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--bg-card-hover);
}

.template-view-btn.active,
.template-view-btn[aria-pressed="true"] {
    color: var(--brand-blue);
    border-color: var(--border-strong);
    background: var(--bg-card-hover);
}

.template-view-btn:focus-visible {
    outline: 2px solid var(--brand-cyan);
    outline-offset: 3px;
}


/* =========================================================
   08. TEMPLATE GRID
========================================================= */

.templates-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 26px;
    width: 100%;
}


/* =========================================================
   09. TEMPLATE CARD
========================================================= */

.template-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--transition-normal),
        border-color var(--transition-normal),
        box-shadow var(--transition-normal),
        background var(--transition-normal);
}

.template-card:hover {
    transform: translateY(-7px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-lg);
}

.template-card.is-featured {
    border-color: rgba(59, 130, 246, 0.32);
}

.template-card.is-premium {
    border-color: rgba(139, 92, 246, 0.3);
}

.template-card.is-coming-soon {
    opacity: 0.96;
}


/* =========================================================
   10. TEMPLATE CARD PREVIEW
========================================================= */

.template-card-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: var(--bg-secondary);
}

.template-card-preview::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        linear-gradient(
            to bottom,
            transparent 55%,
            rgba(0, 0, 0, 0.2)
        );
}

.template-card-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition:
        transform var(--transition-slow),
        filter var(--transition-slow);
}

.template-card:hover .template-card-image {
    transform: scale(1.045);
}


/* =========================================================
   11. TEMPLATE IMAGE FALLBACK
========================================================= */

.template-card-image-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(
            circle at 30% 30%,
            rgba(59, 130, 246, 0.2),
            transparent 45%
        ),
        radial-gradient(
            circle at 70% 70%,
            rgba(34, 211, 238, 0.16),
            transparent 45%
        ),
        var(--bg-secondary);
}

.template-card-image-fallback-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}


/* =========================================================
   12. TEMPLATE CARD OVERLAY
========================================================= */

.template-card-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    background: rgba(5, 10, 18, 0.58);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    transition: opacity var(--transition-normal);
}

.template-card:hover .template-card-overlay,
.template-card:focus-within .template-card-overlay {
    opacity: 1;
}

.template-preview-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 11px 18px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-white);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 750;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition:
        background var(--transition-normal),
        border-color var(--transition-normal),
        transform var(--transition-normal);
}

.template-preview-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
    transform: translateY(-2px);
}


/* =========================================================
   13. TEMPLATE BADGES
========================================================= */

.template-badges {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 5;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
}

.template-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 27px;
    padding: 5px 10px;
    border-radius: var(--radius-pill);
    color: var(--text-white);
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.01em;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.template-badge.featured {
    background: rgba(59, 130, 246, 0.9);
}

.template-badge.free {
    background: rgba(34, 197, 94, 0.9);
}

.template-badge.premium {
    background: rgba(139, 92, 246, 0.92);
}

.template-badge.coming-soon {
    background: rgba(71, 85, 105, 0.92);
}

.template-badge.website {
    background: rgba(34, 211, 238, 0.88);
}

.template-badge.app {
    background: rgba(59, 130, 246, 0.88);
}


/* =========================================================
   14. TEMPLATE FAVORITE BUTTON
========================================================= */

.template-favorite {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 50%;
    background: rgba(5, 10, 18, 0.45);
    color: var(--text-white);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    transition:
        background var(--transition-normal),
        border-color var(--transition-normal),
        transform var(--transition-normal);
}

.template-favorite:hover {
    background: rgba(5, 10, 18, 0.7);
    border-color: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.template-favorite.active,
.template-favorite[aria-pressed="true"] {
    color: #f472b6;
    border-color: rgba(244, 114, 182, 0.35);
    background: rgba(244, 114, 182, 0.12);
}


/* =========================================================
   15. TEMPLATE CARD BODY
========================================================= */

.template-card-body,
.template-card-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 21px;
}

.template-card-category {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    color: var(--brand-cyan);
    font-size: 0.72rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.template-card-title {
    margin: 0 0 9px;
    color: var(--text-primary);
    font-size: 1.12rem;
    font-weight: 800;
    line-height: 1.3;
}

.template-card-title a {
    color: inherit;
    text-decoration: none;
}

.template-card-title a:hover {
    color: var(--brand-cyan);
}

.template-card-description {
    margin: 0 0 18px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.65;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}


/* =========================================================
   16. TEMPLATE TAGS
========================================================= */

.template-tags {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 20px;
}

.template-tag {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 650;
}

.template-tag:hover {
    color: var(--text-secondary);
    border-color: var(--border-strong);
}


/* =========================================================
   17. TEMPLATE CARD FOOTER
========================================================= */

.template-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
    padding-top: 17px;
    border-top: 1px solid var(--border-color);
}

.template-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.template-card-actions .btn {
    min-height: 40px;
    padding: 9px 14px;
    font-size: 0.78rem;
}


/* =========================================================
   18. TEMPLATE STATUS
========================================================= */

.template-status,
.template-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 650;
}

.template-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
}

.template-status.free .template-status-dot,
.template-status-badge.free .template-status-dot {
    background: var(--brand-green);
}

.template-status.premium .template-status-dot,
.template-status-badge.premium .template-status-dot {
    background: var(--brand-purple);
}

.template-status.coming-soon .template-status-dot,
.template-status-badge.coming-soon .template-status-dot {
    background: #64748b;
}


/* =========================================================
   19. TEMPLATE PRICE
========================================================= */

.template-price {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 800;
}

.template-price.free {
    color: var(--brand-green);
}

.template-price.coming-soon {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.template-price-period {
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 500;
}


/* =========================================================
   20. COMING SOON TEMPLATE
========================================================= */

.template-card.coming-soon .template-card-preview {
    position: relative;
}

.template-card.coming-soon .template-card-preview::before {
    content: "Coming Soon";
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5, 10, 18, 0.48);
    color: var(--text-white);
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    backdrop-filter: blur(2px);
}

.template-card.coming-soon .template-card-image {
    filter: saturate(0.65);
}

.template-card.coming-soon .template-card-actions .btn {
    cursor: not-allowed;
    opacity: 0.6;
}


/* =========================================================
   21. FEATURED TEMPLATES
========================================================= */

.featured-templates {
    position: relative;
}

.featured-templates-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 30px;
}

.featured-templates-header-content {
    max-width: 700px;
}

.featured-templates-header .section-title {
    margin-bottom: 10px;
}

.featured-templates-header .section-description {
    margin: 0;
}

.featured-templates-link {
    flex-shrink: 0;
}


/* =========================================================
   22. TEMPLATE CATEGORY HERO
========================================================= */

.template-category-hero {
    position: relative;
    overflow: hidden;
    padding: 60px 45px;
    margin-bottom: 45px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    background:
        radial-gradient(
            circle at 10% 20%,
            rgba(59, 130, 246, 0.15),
            transparent 35%
        ),
        radial-gradient(
            circle at 90% 80%,
            rgba(34, 211, 238, 0.12),
            transparent 35%
        ),
        var(--bg-card);
}

.template-category-hero-content {
    position: relative;
    z-index: 2;
    max-width: 700px;
}

.template-category-hero-title {
    margin: 0 0 15px;
    color: var(--text-primary);
    font-size: clamp(2rem, 4vw, 3.1rem);
    line-height: 1.1;
    letter-spacing: -0.04em;
}

.template-category-hero-description {
    max-width: 650px;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.98rem;
    line-height: 1.75;
}


/* =========================================================
   23. TEMPLATE DETAIL PAGE
========================================================= */

.template-detail-page {
    position: relative;
}

.template-detail-layout {
    display: grid;
    grid-template-columns:
        minmax(0, 1.45fr)
        minmax(300px, 0.75fr);
    gap: 35px;
    align-items: start;
}


/* =========================================================
   24. TEMPLATE DETAIL PREVIEW
========================================================= */

.template-detail-preview {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
}

.template-detail-preview-image {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
}

.template-detail-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    min-height: 58px;
    padding: 10px 14px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.template-detail-preview-controls {
    display: flex;
    align-items: center;
    gap: 7px;
}

.template-preview-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition:
        color var(--transition-normal),
        border-color var(--transition-normal),
        background var(--transition-normal);
}

.template-preview-control:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--bg-card-hover);
}


/* =========================================================
   25. TEMPLATE DETAIL INFORMATION
========================================================= */

.template-detail-info {
    position: sticky;
    top: calc(var(--header-height) + 22px);
    padding: 28px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow-md);
}

.template-detail-badges {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 17px;
}

.template-detail-title {
    margin: 0 0 13px;
    color: var(--text-primary);
    font-size: clamp(1.7rem, 3vw, 2.35rem);
    line-height: 1.15;
    letter-spacing: -0.035em;
}

.template-detail-description {
    margin: 0 0 25px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.75;
}


/* =========================================================
   26. TEMPLATE DETAIL ACTIONS
========================================================= */

.template-detail-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 25px;
}

.template-detail-actions .btn {
    width: 100%;
    min-height: 48px;
}


/* =========================================================
   27. TEMPLATE INFORMATION LIST
========================================================= */

.template-info-list {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--border-color);
}

.template-info-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
}

.template-info-label {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.template-info-value {
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 650;
    text-align: right;
}


/* =========================================================
   28. TEMPLATE TECHNOLOGIES
========================================================= */

.template-technologies {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 20px;
}

.template-technology {
    display: inline-flex;
    align-items: center;
    min-height: 29px;
    padding: 5px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 650;
}


/* =========================================================
   29. TEMPLATE PREVIEW MODAL
========================================================= */

.template-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    background: rgba(2, 6, 12, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    opacity: 0;
    visibility: hidden;
    transition:
        opacity var(--transition-normal),
        visibility var(--transition-normal);
}

.template-preview-modal.active {
    opacity: 1;
    visibility: visible;
}

.template-preview-modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(1200px, 100%);
    height: min(850px, 90vh);
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(15px) scale(0.98);
    transition: transform var(--transition-normal);
}

.template-preview-modal.active .template-preview-modal-content {
    transform: translateY(0) scale(1);
}

.template-preview-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    min-height: 58px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.template-preview-modal-title,
.template-preview-title {
    margin: 0;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 750;
}

.template-preview-modal-close,
.template-preview-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition:
        color var(--transition-normal),
        background var(--transition-normal),
        border-color var(--transition-normal);
}

.template-preview-modal-close:hover,
.template-preview-close:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
}

.template-preview-frame {
    flex: 1;
    width: 100%;
    height: 100%;
    border: 0;
    background: #ffffff;
    color-scheme: light;
}

.template-preview-frame[hidden] {
    display: none;
}


/* =========================================================
   30. EMPTY TEMPLATE STATE
========================================================= */

.templates-empty-state,
.templates-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 320px;
    padding: 45px 25px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    text-align: center;
}

.templates-empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    margin-bottom: 18px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text-muted);
}

.templates-empty-title {
    margin: 0 0 9px;
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 750;
}

.templates-empty-description {
    max-width: 450px;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.7;
}


/* =========================================================
   31. TEMPLATE LOADING STATE
========================================================= */

.template-loading,
.templates-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 250px;
}

.template-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--brand-blue);
    border-radius: 50%;
    animation: templateSpinner 0.8s linear infinite;
}

@keyframes templateSpinner {
    to {
        transform: rotate(360deg);
    }
}


/* =========================================================
   32. TEMPLATE PAGINATION
========================================================= */

.template-pagination,
.templates-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 45px;
}

.template-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 11px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 650;
    cursor: pointer;
    transition:
        color var(--transition-normal),
        background var(--transition-normal),
        border-color var(--transition-normal),
        transform var(--transition-normal);
}

.template-page-btn:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.template-page-btn.active {
    color: var(--text-white);
    background: var(--brand-blue);
    border-color: var(--brand-blue);
}

.template-page-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}


/* =========================================================
   33. TEMPLATE NOTICE
========================================================= */

.template-notice {
    display: flex;
    align-items: flex-start;
    gap: 13px;
    padding: 17px 18px;
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
}

.template-notice-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    color: var(--brand-blue);
}

.template-notice-content {
    flex: 1;
}

.template-notice-title {
    margin: 0 0 5px;
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 750;
}

.template-notice-text {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.76rem;
    line-height: 1.65;
}


/* =========================================================
   34. TEMPLATE DOWNLOAD STATES
========================================================= */

.template-download-btn {
    position: relative;
}

.template-download-btn.loading {
    pointer-events: none;
}

.template-download-btn.loading .btn-text {
    opacity: 0;
}

.template-download-btn.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: templateSpinner 0.7s linear infinite;
}

.template-download-btn.disabled,
.template-download-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* =========================================================
   35. TEMPLATE QUICK META
========================================================= */

.template-quick-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 13px;
    margin-bottom: 15px;
}

.template-quick-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 550;
}

.template-quick-meta-item svg,
.template-quick-meta-item i {
    width: 14px;
    height: 14px;
}


/* =========================================================
   36. TEMPLATE LIST VIEW
========================================================= */

.templates-grid.list-view {
    grid-template-columns: 1fr;
}

.templates-grid.list-view .template-card {
    display: grid;
    grid-template-columns:
        280px
        minmax(0, 1fr);
    min-height: 220px;
}

.templates-grid.list-view .template-card-preview {
    height: 100%;
    aspect-ratio: auto;
}

.templates-grid.list-view .template-card-body,
.templates-grid.list-view .template-card-content {
    padding: 24px;
}


/* =========================================================
   37. TEMPLATE GRID VIEW
========================================================= */

.templates-grid.grid-view {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}


/* =========================================================
   38. WEBSITE TEMPLATE VARIANT
========================================================= */

.website-template-card .template-card-category {
    color: var(--brand-cyan);
}

.website-template-card .template-card-preview {
    background:
        linear-gradient(
            135deg,
            rgba(34, 211, 238, 0.08),
            transparent
        ),
        var(--bg-secondary);
}

.template-category-website {
    color: var(--brand-cyan);
}


/* =========================================================
   39. APP TEMPLATE VARIANT
========================================================= */

.app-template-card .template-card-category {
    color: var(--brand-blue-light);
}

.app-template-card .template-card-preview {
    background:
        linear-gradient(
            135deg,
            rgba(59, 130, 246, 0.08),
            transparent
        ),
        var(--bg-secondary);
}

.template-category-app {
    color: var(--brand-blue-light);
}


/* =========================================================
   40. PREMIUM TEMPLATE OVERLAY
========================================================= */

.template-card.premium-only .template-card-overlay {
    background: rgba(5, 10, 18, 0.66);
}

.template-premium-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-white);
    text-align: center;
}

.template-premium-message-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(139, 92, 246, 0.4);
    border-radius: 50%;
    background: rgba(139, 92, 246, 0.2);
    color: var(--text-white);
}

.template-premium-message-title {
    font-size: 0.88rem;
    font-weight: 800;
}

.template-premium-message-text {
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.72rem;
}


/* =========================================================
   41. TEMPLATE ACCESSIBILITY
========================================================= */

.template-card:focus-within {
    border-color: var(--brand-blue);
    box-shadow:
        0 0 0 3px rgba(59, 130, 246, 0.1),
        var(--shadow-md);
}

.template-filter:focus-visible,
.template-category-btn:focus-visible,
.template-preview-btn:focus-visible,
.template-favorite:focus-visible,
.template-page-btn:focus-visible,
.template-view-btn:focus-visible,
.template-preview-control:focus-visible,
.template-preview-modal-close:focus-visible,
.template-preview-close:focus-visible,
.template-description-toggle:focus-visible {
    outline: 2px solid var(--brand-cyan);
    outline-offset: 3px;
}


/* =========================================================
   42. LIGHT MODE COMPATIBILITY
========================================================= */

body.light-mode .template-card-overlay {
    background: rgba(15, 23, 42, 0.5);
}

body.light-mode .template-preview-modal {
    background: rgba(15, 23, 42, 0.6);
}

body.light-mode .template-card.coming-soon .template-card-preview::before {
    background: rgba(15, 23, 42, 0.42);
}

body.light-mode .template-category-hero {
    background:
        radial-gradient(
            circle at 10% 20%,
            rgba(59, 130, 246, 0.09),
            transparent 35%
        ),
        radial-gradient(
            circle at 90% 80%,
            rgba(34, 211, 238, 0.08),
            transparent 35%
        ),
        var(--bg-card);
}

body.light-mode .template-card-image-fallback {
    background:
        radial-gradient(
            circle at 30% 30%,
            rgba(59, 130, 246, 0.1),
            transparent 45%
        ),
        radial-gradient(
            circle at 70% 70%,
            rgba(34, 211, 238, 0.08),
            transparent 45%
        ),
        var(--bg-secondary);
}

body.light-mode .template-category-stat {
    background: rgba(15, 23, 42, 0.025);
}


/* =========================================================
   43. TEMPLATE HORIZONTAL SCROLL WRAPPER
========================================================= */

.template-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.template-scroll-wrapper::-webkit-scrollbar {
    display: none;
}


/* =========================================================
   44. TEMPLATE CATEGORY STATS
========================================================= */

.template-category-stats {
    display: grid;
    grid-template-columns:
        repeat(2, minmax(0, 1fr));
    gap: 12px;
    max-width: 450px;
    margin-top: 28px;
}

.template-category-stat {
    padding: 15px 17px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.025);
}

.template-category-stat-value {
    display: block;
    margin-bottom: 4px;
    color: var(--text-primary);
    font-size: 1.15rem;
    font-weight: 800;
}

.template-category-stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.7rem;
}


/* =========================================================
   45. TEMPLATE RESULT ANIMATION
========================================================= */

.template-card.template-hidden {
    display: none;
}

.template-card.template-visible {
    animation: templateCardAppear 0.35s ease both;
}

@keyframes templateCardAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* =========================================================
   46. TEMPLATE NO RESULTS
========================================================= */

.template-no-results {
    display: none;
}

.template-no-results.active {
    display: flex;
}


/* =========================================================
   47. TEMPLATE SECTION DIVIDER
========================================================= */

.template-section-divider {
    width: 100%;
    height: 1px;
    margin: 55px 0;
    background: var(--border-color);
}


/* =========================================================
   48. TEMPLATE IMAGE LOADING
========================================================= */

.template-card-image.is-loading {
    opacity: 0.35;
    filter: blur(4px);
}

.template-card-image.is-loaded {
    opacity: 1;
    filter: none;
}


/* =========================================================
   49. TEMPLATE FILTER ACTIVE INDICATOR
========================================================= */

.template-filter[data-active="true"] {
    color: var(--text-white);
    background: var(--brand-blue);
    border-color: var(--brand-blue);
}


/* =========================================================
   50. TEMPLATE CARD ACTION STATES
========================================================= */

.template-card-actions .btn-preview {
    border-color: var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.template-card-actions .btn-preview:hover {
    border-color: var(--border-strong);
    background: var(--bg-card-hover);
}

.template-card-actions .btn-download {
    background: var(--gradient-brand);
    color: var(--text-white);
}


/* =========================================================
   51. TEMPLATE PREMIUM LOCK
========================================================= */

.template-premium-lock {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: var(--radius-sm);
    background: rgba(139, 92, 246, 0.08);
    color: var(--brand-purple-light);
}

.template-card.premium-only .template-download-btn {
    background: var(--bg-elevated);
    color: var(--text-muted);
    border-color: var(--border-color);
    cursor: not-allowed;
}


/* =========================================================
   52. TEMPLATE FEATURED INDICATOR
========================================================= */

.template-card.is-featured::before {
    content: "";
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 2px;
    z-index: 6;
    border-radius:
        0 0 var(--radius-pill) var(--radius-pill);
    background: var(--gradient-brand);
    opacity: 0.9;
}


/* =========================================================
   53. TEMPLATE CONTENT WIDTH
========================================================= */

.template-content {
    width: 100%;
}

.template-content-narrow {
    width: min(100%, 900px);
    margin-inline: auto;
}


/* =========================================================
   54. TEMPLATE CARD META ROW
========================================================= */

.template-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 13px;
}

.template-card-meta-left,
.template-card-meta-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.template-card-meta-right {
    margin-left: auto;
}


/* =========================================================
   55. TEMPLATE DESCRIPTION STATES
========================================================= */

.template-card-description.is-expanded {
    display: block;
    -webkit-line-clamp: unset;
}

.template-description-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 15px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--brand-cyan);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

.template-description-toggle:hover {
    color: var(--brand-blue-light);
}


/* =========================================================
   56. TEMPLATE ERROR STATE
========================================================= */

.template-error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 250px;
    padding: 35px 25px;
    border: 1px solid rgba(239, 68, 68, 0.18);
    border-radius: var(--radius-lg);
    background: rgba(239, 68, 68, 0.04);
    text-align: center;
}

.template-error-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    margin-bottom: 14px;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 50%;
    color: #f87171;
}

.template-error-title {
    margin: 0 0 7px;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 750;
}

.template-error-description {
    max-width: 460px;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.65;
}


/* =========================================================
   57. TEMPLATE UTILITY STATES
========================================================= */

.template-card[hidden],
.template-no-results[hidden],
.templates-empty-state[hidden],
.templates-empty[hidden],
.template-loading[hidden],
.templates-loading[hidden],
.template-error-state[hidden] {
    display: none !important;
}


/* =========================================================
   58. TEMPLATE SYSTEM MOTION CONTROL
========================================================= */

@media (prefers-reduced-motion: reduce) {
    .template-card,
    .template-card-image,
    .template-category-btn,
    .template-filter,
    .template-preview-btn,
    .template-favorite,
    .template-view-btn,
    .template-page-btn,
    .template-preview-control,
    .template-preview-modal,
    .template-preview-modal-content {
        transition: none;
    }

    .template-card.template-visible {
        animation: none;
    }

    .template-loading-spinner,
    .template-download-btn.loading::after {
        animation: none;
    }
}


/* =========================================================
   59. JAVASCRIPT / HTML COMPATIBILITY LAYER

   These aliases keep the shared stylesheet compatible with
   the selectors currently used by templates.js and the
   dynamically generated template cards.
========================================================= */

/* Result containers */
.template-results {
    position: relative;
    width: 100%;
}

.template-results-count {
    min-height: 20px;
}

/* Dynamic card content aliases */
.template-card-content {
    min-width: 0;
}

/* Dynamic preview fallback */
.template-placeholder-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}

/* Dynamic type/status badge aliases */
.template-type-badge,
.template-status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Dynamic card image placeholder aliases */
.template-card-image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
}

.template-card-image-fallback-icon,
.template-placeholder-icon {
    flex-shrink: 0;
}

/* Dynamic card footer aliases */
.template-card-footer {
    min-width: 0;
}

/* Search / sort accessibility */
.template-search-input:focus-visible,
.template-sort-select:focus-visible {
    outline: 2px solid var(--brand-cyan);
    outline-offset: 2px;
}

/* Dynamic preview buttons */
.template-card-actions .btn-preview,
.template-card-actions .btn-download {
    white-space: nowrap;
}

/* Dynamic favorite button */
.template-favorite[aria-label] {
    line-height: 1;
}

/* Dynamic loading state */
.templates-loading {
    width: 100%;
}

/* Dynamic empty state */
.templates-empty {
    width: 100%;
}

/* Dynamic pagination */
.templates-pagination {
    width: 100%;
}

/* Dynamic modal title / close aliases */
.template-preview-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-preview-close {
    flex-shrink: 0;
}


/* =========================================================
   END OF CHATNEX TEMPLATE SYSTEM
========================================================= */