/* ============================================
   Templates library page
   ============================================ */

.tpl-hero {
    text-align: center;
    margin-bottom: 34px;
}
.tpl-kicker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    margin-bottom: 18px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-primary);
    background: rgba(255, 152, 0, 0.1);
    border: 1px solid rgba(255, 152, 0, 0.22);
    border-radius: 999px;
}
.tpl-kicker::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(255, 152, 0, 0.14);
}
.tpl-hero h1 {
    font-family: var(--font-display);
    font-size: clamp(32px, 4.6vw, 48px);
    font-weight: 800;
    line-height: 1.08;
    letter-spacing: -0.03em;
    max-width: 820px;
    margin: 0 auto 16px;
}
.tpl-hero p {
    max-width: 660px;
    margin: 0 auto;
    font-size: 17px;
    line-height: 1.7;
    color: var(--text-secondary);
}
.tpl-hero-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 26px;
}
.tpl-hero-actions .btn svg {
    flex-shrink: 0;
}

/* ---- Toolbar: search + count ---- */
.tpl-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin: 32px 0 16px;
}
.tpl-search {
    flex: 1 1 340px;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 48px;
    padding: 0 18px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.tpl-search:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(255, 152, 0, 0.12);
}
.tpl-search > svg {
    flex-shrink: 0;
    color: var(--text-tertiary);
}
.tpl-search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: 14px;
}
.tpl-search input::placeholder {
    color: var(--text-muted);
}
.tpl-search input::-webkit-search-cancel-button {
    display: none;
}
.tpl-search-clear {
    display: none;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border: 0;
    border-radius: 50%;
    background: var(--glass-bg);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: var(--transition-fast);
}
.tpl-search-clear:hover {
    background: var(--glass-border-hover);
    color: var(--text-primary);
}
.tpl-count {
    font-size: 13px;
    color: var(--text-tertiary);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ---- Category chips ---- */
.tpl-cats {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 10px;
    margin-bottom: 22px;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
    -webkit-overflow-scrolling: touch;
}
.tpl-cats::-webkit-scrollbar {
    height: 6px;
}
.tpl-cats::-webkit-scrollbar-track {
    background: transparent;
}
.tpl-cats::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 99px;
}
.tpl-cats:hover::-webkit-scrollbar-thumb {
    background: var(--glass-border-hover);
}
.tpl-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex-shrink: 0;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.tpl-chip:hover {
    color: var(--text-primary);
    border-color: var(--glass-border-hover);
}
.tpl-chip.active {
    color: #fff;
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    box-shadow: 0 4px 14px -6px rgba(255, 152, 0, 0.9);
}
.tpl-chip-count {
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 999px;
    color: var(--text-tertiary);
    background: var(--glass-bg);
    font-variant-numeric: tabular-nums;
}
.tpl-chip.active .tpl-chip-count {
    color: #fff;
    background: rgba(255, 255, 255, 0.24);
}

/* ---- Card grid ---- */
#tplGrid {
    scroll-margin-top: calc(var(--nav-height) + 24px);
}
.tpl-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 20px;
    min-height: 120px;
}
.tpl-card {
    display: flex;
    flex-direction: column;
    gap: 9px;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}
.tpl-card:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}
.tpl-thumb {
    position: relative;
    aspect-ratio: 4 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
}
.tpl-card:hover .tpl-thumb {
    transform: translateY(-3px);
    border-color: rgba(255, 152, 0, 0.4);
    box-shadow: var(--shadow-md);
}
.tpl-thumb img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 6px 16px -10px rgba(0, 0, 0, 0.45);
    transition: transform var(--transition-base);
}
.tpl-card:hover .tpl-thumb img {
    transform: scale(1.04);
}
.tpl-thumb-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 70%;
    aspect-ratio: 3 / 4;
    color: var(--text-tertiary);
    background: var(--bg-card);
    border: 1px dashed var(--glass-border);
    border-radius: 4px;
}
.tpl-pages {
    margin-inline-start: auto;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-tertiary);
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}
.tpl-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 14px;
    background: linear-gradient(180deg, transparent 45%, rgba(15, 23, 42, 0.6));
    opacity: 0;
    transition: opacity var(--transition-base);
    pointer-events: none;
}
.tpl-card:hover .tpl-overlay,
.tpl-card:focus-visible .tpl-overlay {
    opacity: 1;
}
.tpl-use {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #09090b;
    background: #fff;
    border-radius: 999px;
    box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.5);
    transform: translateY(6px);
    transition: transform var(--transition-base);
}
.tpl-card:hover .tpl-use,
.tpl-card:focus-visible .tpl-use {
    transform: translateY(0);
}
.tpl-card-body {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
}
.tpl-card-title {
    flex: 0 0 100%;
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.7em;
    transition: color var(--transition-fast);
}
.tpl-card:hover .tpl-card-title {
    color: var(--text-primary);
}
.tpl-card-cat {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-tertiary);
}

/* ---- Loading / empty / load more ---- */
.tpl-skeleton {
    border-radius: var(--border-radius-md);
}
.tpl-skeleton::before {
    content: '';
    display: block;
    aspect-ratio: 4 / 3;
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
    background: linear-gradient(100deg, var(--bg-secondary) 30%, var(--glass-bg) 45%, var(--bg-secondary) 60%);
    background-size: 220% 100%;
    animation: tplShimmer 1.3s linear infinite;
}
.tpl-skeleton::after {
    content: '';
    display: block;
    width: 70%;
    height: 12px;
    margin: 9px 2px 0;
    border-radius: 4px;
    background: var(--bg-secondary);
}
@keyframes tplShimmer {
    from { background-position: 120% 0; }
    to { background-position: -120% 0; }
}
.tpl-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 64px 24px;
    text-align: center;
    background: var(--bg-card);
    border: 1px dashed var(--glass-border);
    border-radius: var(--border-radius-lg);
}
.tpl-empty-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-bottom: 4px;
    border-radius: 50%;
    color: var(--text-tertiary);
    background: var(--glass-bg);
}
.tpl-empty strong {
    font-family: var(--font-display);
    font-size: 17px;
}
.tpl-empty span {
    font-size: 13px;
    color: var(--text-tertiary);
}
.tpl-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-top: 28px;
    text-align: center;
}
.tpl-more {
    min-width: 220px;
}

/* ---- Why / FAQ / CTA ---- */
.tpl-content {
    max-width: 1040px;
    margin: 12px auto 0;
}
.tpl-faq {
    margin-top: 24px;
    padding: 32px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    backdrop-filter: blur(12px);
}
.tpl-faq h2 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 26px;
    text-align: center;
}
.tpl-faq-item + .tpl-faq-item {
    padding-top: 20px;
    margin-top: 20px;
    border-top: 1px solid var(--glass-border);
}
.tpl-faq-item h3 {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 6px;
}
.tpl-faq-item p {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}
.tpl-cta {
    position: relative;
    margin-top: 24px;
    padding: 52px 28px;
    text-align: center;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 50% -20%, rgba(255, 152, 0, 0.18), transparent 60%),
        var(--bg-card);
    border: 1px solid rgba(255, 152, 0, 0.25);
    border-radius: var(--border-radius-xl);
}
.tpl-cta h2 {
    font-family: var(--font-display);
    font-size: clamp(24px, 3vw, 32px);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 10px;
}
.tpl-cta p {
    max-width: 520px;
    margin: 0 auto 24px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-secondary);
}

/* ---- Preview modal (Canva-style) ---- */
.tpl-modal {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
}
.tpl-modal[hidden] { display: none; }
.tpl-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(9, 9, 11, 0.62);
    backdrop-filter: blur(5px);
}
.tpl-modal-dialog {
    position: relative;
    display: flex;
    width: min(980px, 100%);
    max-height: min(86vh, 800px);
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: tplModalIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
@keyframes tplModalIn {
    from { opacity: 0; transform: translateY(14px) scale(0.97); }
    to { opacity: 1; transform: none; }
}
.tpl-modal-media {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    background:
        radial-gradient(circle at 50% 40%, rgba(255, 152, 0, 0.05), transparent 70%),
        var(--bg-secondary);
    overflow: hidden;
}
.tpl-modal-media img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 18px 44px -18px rgba(0, 0, 0, 0.5);
}
/* Low-res thumbnail stretched to the final frame while the preview decodes. */
.tpl-modal-media img.is-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: blur(3px);
}
.tpl-modal-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60%;
    aspect-ratio: 3 / 4;
    color: var(--text-tertiary);
    background: var(--bg-card);
    border: 1px dashed var(--glass-border);
    border-radius: 6px;
}
.tpl-modal-fallback[hidden] { display: none; }
.tpl-modal-thumb-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 70%;
    aspect-ratio: 3 / 4;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    border: 1px dashed var(--glass-border);
    border-radius: 4px;
    font-weight: 700;
}
.tpl-modal-side {
    flex: 0 0 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 26px 24px;
    overflow-y: auto;
    border-inline-start: 1px solid var(--glass-border);
}
.tpl-modal-close {
    position: absolute;
    top: 12px;
    inset-inline-end: 12px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}
.tpl-modal-close:hover {
    color: var(--text-primary);
    border-color: var(--glass-border-hover);
    transform: rotate(90deg);
}
.tpl-modal-close:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}
.tpl-modal-cat {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent-primary);
}
.tpl-modal-title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    line-height: 1.25;
    margin: 0;
}
.tpl-modal-pages {
    font-size: 13px;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}
.tpl-modal-use {
    justify-content: center;
    width: 100%;
    margin-top: 6px;
}
.tpl-modal-more {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.tpl-modal-more[hidden] { display: none; }
.tpl-modal-more-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}
.tpl-modal-thumbs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}
.tpl-modal-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    padding: 8px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    cursor: pointer;
    overflow: hidden;
    transition: border-color var(--transition-fast), transform var(--transition-fast);
}
.tpl-modal-thumb img {
    max-width: 100%;
    max-height: 100%;
    background: #fff;
    border-radius: 2px;
}
.tpl-modal-thumb:hover {
    border-color: rgba(255, 152, 0, 0.4);
    transform: translateY(-2px);
}
.tpl-modal-thumb:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}
.tpl-modal-thumb.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.25);
}
body.tpl-modal-lock { overflow: hidden; }

/* ---- Responsive ---- */
@media (max-width: 1100px) {
    .tpl-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .tpl-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .tpl-hero p { font-size: 16px; }
}
@media (max-width: 680px) {
    .tpl-toolbar { margin-top: 26px; }
    .tpl-search { flex-basis: 100%; }
    .tpl-count { width: 100%; text-align: center; }
    .tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
    .tpl-thumb { padding: 8px; }
    .tpl-card-title { font-size: 12.5px; }
    .tpl-faq { padding: 24px 20px; }
    .tpl-cta { padding: 40px 20px; }
}
@media (max-width: 400px) {
    .tpl-hero h1 { font-size: 29px; }
    .tpl-grid { gap: 10px; }
    .tpl-thumb { padding: 6px; }
}
@media (max-width: 900px) {
    .tpl-modal { padding: 12px; align-items: stretch; }
    .tpl-modal-dialog {
        flex-direction: column;
        max-height: 92vh;
        overflow-y: auto;
    }
    .tpl-modal-media {
        flex: none;
        min-height: 42vh;
        padding: 20px 16px;
    }
    .tpl-modal-side {
        flex: 1 1 auto;
        border-inline-start: 0;
        border-top: 1px solid var(--glass-border);
        overflow: visible;
    }
    .tpl-modal-thumbs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
    .tpl-modal-side { padding: 18px 16px; gap: 10px; }
    .tpl-modal-title { font-size: 19px; }
    .tpl-modal-thumbs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
    .tpl-card,
    .tpl-thumb img,
    .tpl-use,
    .tpl-overlay {
        transition: none;
    }
    .tpl-skeleton::before { animation: none; }
    .tpl-modal-dialog { animation: none; }
    .tpl-modal-close,
    .tpl-modal-thumb { transition: none; }
}
