/**
 * Template library (/templates). Loaded inside the dashboard shell (x-app-layout).
 */

.tpl-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Filters bar ── */
/* ── Plan tabs (All / Base / Pro) ──
   A bare <nav> picks up global.css's site-header `nav {}` rule, hence the reset. */
nav.tpl-plan-tabs {
    display: inline-flex;
    align-items: stretch;
    justify-content: flex-start;
    gap: 4px;
    position: static;
    z-index: auto;
    height: auto;
    margin: 0 0 16px;
    padding: 4px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    max-width: 100%;
    overflow-x: auto;
}

.tpl-plan-tab {
    display: inline-flex;
    align-items: center;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-mid);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.tpl-plan-tab:hover {
    background: var(--gray-light);
    color: var(--text-dark);
}

.tpl-plan-tab.is-active {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    color: var(--accent);
}

.tpl-plan-tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.tpl-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 28px;
}

.tpl-search {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 240px;
    min-width: 200px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
}

.tpl-search input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-dark);
    font-size: 15px;
    outline: none;
}

.tpl-search input::placeholder {
    color: var(--gray-mid);
}

.tpl-search i {
    color: var(--gray-mid);
}

.tpl-category-label {
    position: relative;
    flex: 0 0 220px;
    max-width: 100%;
}

/* Match the search box beside it. */
.tpl-category-label .cs-trigger {
    padding: 10px 14px;
    font-size: 15px;
    border: 1px solid var(--line);
}

/* The plain <select>, shown only if custom-select.js hasn't enhanced it. */
.tpl-category-label select:not(.cs-native) {
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--text-dark);
    padding: 10px 14px;
    font-size: 15px;
}

/* ── Card grid ── */
.tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 24px;
}

.tpl-btn-small {
    padding: 8px 14px;
    font-size: 13px;
}

.tpl-card {
    border-radius: var(--radius);
    border: 1px solid var(--line, #e0e0e8);
    overflow: hidden;
    background: var(--white, #fff);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
}

.tpl-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12);
}

/* Library cards: only the thumbnail is a card; name and action sit on the page. */
.tpl-card.tpl-gallery-card {
    border: none;
    border-radius: 0;
    overflow: visible;
    background: transparent;
    box-shadow: none;
    transition: none;
}

.tpl-card.tpl-gallery-card:hover {
    transform: none;
    box-shadow: none;
}

.tpl-gallery-card .tpl-gallery-thumb {
    flex-shrink: 0;
    border-radius: var(--radius);
    border: 1px solid var(--line, #e0e0e8);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.tpl-gallery-card:hover .tpl-gallery-thumb {
    transform: translateY(-4px);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12);
}

.tpl-gallery-body {
    padding: 14px 2px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

.tpl-gallery-title {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    color: var(--navy, #1a2a4a);
    line-height: 1.25;
}

.tpl-gallery-actions {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tpl-gallery-lock-hint {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--gray-mid, #64748b);
}

.tpl-gallery-tier-actions {
    width: 100%;
    justify-content: stretch;
}

.tpl-gallery-tier-actions .tpl-btn-small {
    flex: 1;
    justify-content: center;
}

.tpl-card-visual {
    position: relative;
    display: block;
    aspect-ratio: 4 / 5;
    background: linear-gradient(145deg, #eef2ff 0%, #fce7f3 100%);
    overflow: hidden;
}

.tpl-card-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tpl-card-placeholder {
    position: relative;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    background: linear-gradient(160deg, var(--tpl-bg, #eef2ff) 0%, color-mix(in srgb, var(--tpl-accent, #1e47bb) 28%, var(--tpl-bg, #eef2ff)) 60%, color-mix(in srgb, var(--tpl-primary, #1a2a4a) 18%, var(--tpl-bg, #eef2ff)) 100%);
}

.tpl-card-preview-chip {
    position: absolute;
    bottom: 14px;
    right: 14px;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: rgba(15, 23, 42, 0.82);
    color: var(--white, #fff);
    border: 1px solid rgba(255, 255, 255, 0.18);
    pointer-events: none;
}

.tpl-card-body {
    padding: 18px 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.tpl-card-body h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    color: var(--navy, #1a2a4a);
}

.tpl-card-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.tpl-tier-badge {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--line, #e0e0e8);
    background: var(--white, #fff);
    color: var(--gray-mid, #64748b);
}

.tpl-tier-badge.tpl-tier-base {
    border-color: rgba(100, 116, 139, 0.38);
    background: rgba(100, 116, 139, 0.09);
    color: var(--gray-mid, #64748b);
}

.tpl-tier-badge.tpl-tier-pro {
    border-color: rgba(14, 165, 233, 0.35);
    background: rgba(14, 165, 233, 0.08);
    color: var(--cyan, #0ea5e9);
}

.tpl-tier-badge.tpl-tier-pro-plus {
    border-color: rgba(217, 70, 239, 0.35);
    background: rgba(217, 70, 239, 0.08);
    color: #a21caf;
}

/* Badge pinned over the card thumbnail — solid so the tier tint stays readable on any photo. */
.tpl-card-visual .tpl-tier-badge.tpl-thumb-tier {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 1;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.14);
}

.tpl-tier-lock-msg {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--gray-mid, #64748b);
}

.tpl-tier-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.tpl-card-body > p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-mid, #64748b);
    flex: 1;
}

.tpl-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tpl-tag {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent, #1e47bb) 12%, transparent);
    color: var(--accent, #1e47bb);
    border: 1px solid color-mix(in srgb, var(--accent, #1e47bb) 22%, transparent);
}

.tpl-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--gray-mid, #64748b);
    font-size: 16px;
}

.tpl-card.tpl-card--suggested {
    border-color: rgba(14, 165, 233, 0.55);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.22), var(--card-shadow);
}

.evt-tpl-suggested-note {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--cyan, #0ea5e9);
}

.evt-tpl-select-form {
    margin-top: auto;
}

@media (max-width: 640px) {
    .tpl-filters {
        flex-direction: column;
        align-items: stretch;
    }

    /* The row layout's `flex: 1 1 240px` sizes the main axis, which is the
       height once this stack turns into a column — reset it to content height. */
    .tpl-search {
        flex: 0 0 auto;
        min-width: 0;
    }

    .tpl-category-label {
        flex: 0 0 auto;
    }
}

/* ── Preview page bar ── */
.tpl-preview-bar {
    position: sticky;
    top: 0; /* the preview page hides the site nav, so this is the top bar */
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 20px;
    height: 52px;
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.tpl-preview-bar-back {
    display: flex;
    align-items: center;
    gap: 7px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.18s;
    flex-shrink: 0;
}

.tpl-preview-bar-back:hover {
    color: #fff;
}

.tpl-preview-bar-name {
    flex: 1;
    text-align: center;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 8px;
}

.tpl-preview-bar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.tpl-preview-bar-lock {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
}

.tpl-preview-bar-upgrade {
    display: inline-flex;
    align-items: center;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: border-color 0.18s, background 0.18s;
}

.tpl-preview-bar-upgrade:hover {
    border-color: rgba(255, 255, 255, 0.65);
    background: rgba(255, 255, 255, 0.08);
}

@media (max-width: 540px) {
    .tpl-preview-bar-name {
        display: none;
    }

    .tpl-preview-bar-lock {
        display: none;
    }
}
