/* =========================================================
   模板作品区域
   ========================================================= */

.category-templates {
    margin-top: 48px;
    padding-top: 36px;
    border-top: 1px solid #e8ebf0;
}

.category-templates[hidden],
.template-empty[hidden] {
    display: none !important;
}


/* 标题区域 */

.template-section-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.template-section-eyebrow {
    display: block;
    margin-bottom: 10px;
    color: #6375a0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 2px;
}

.template-section-header h2 {
    margin: 0 0 10px;
    color: #1e293b;
    font-size: 27px;
    font-weight: 700;
    letter-spacing: -.6px;
}

.template-section-header p {
    margin: 0;
    color: #64748b;
    font-size: 14px;
    line-height: 1.7;
}

.template-result-count {
    flex-shrink: 0;
    padding: 8px 13px;
    border-radius: 999px;
    background: #eef2ff;
    color: #4f46e5;
    font-size: 12px;
    font-weight: 600;
}


/* =========================================================
   模板网格
   ========================================================= */

.template-grid {
    display: grid;
    grid-template-columns: repeat(3,
            minmax(0, 1fr));
    gap: 24px;
}


/* =========================================================
   模板卡片
   ========================================================= */

.template-card {
    min-width: 0;
    overflow: hidden;
    border: 1px solid #e7eaf0;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 3px 12px rgba(15, 23, 42, .025);
    transition:
        transform .22s ease,
        box-shadow .22s ease,
        border-color .22s ease;
}

.template-card:hover {
    transform: translateY(-5px);
    border-color: #cbd5e1;
    box-shadow: 0 14px 34px rgba(15, 23, 42, .09);
}


/* 封面 */

.template-card-cover {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 250px;
    overflow: hidden;
    background: #f3f4f6;
}

.template-card-cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform .35s ease;
}

.template-card:hover .template-card-cover img {
    transform: scale(1.035);
}


/* 暂无封面 */

.template-cover-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 24px;
    background:
        radial-gradient(circle at 80% 20%,
            rgba(255, 255, 255, .8),
            transparent 45%),
        linear-gradient(135deg,
            #f5f0e6,
            #e9dfcd);
}

.template-cover-symbol {
    margin-bottom: 18px;
    color: #a18b68;
    font-size: 28px;
}

.template-cover-title {
    color: #292820;
    font-family: "Songti SC", "SimSun", serif;
    font-size: 29px;
    font-weight: 500;
    letter-spacing: 4px;
}

.template-cover-subtitle {
    margin-top: 12px;
    color: #81796b;
    font-size: 12px;
    letter-spacing: 2px;
}


/* 信息 */

.template-card-content {
    padding: 20px;
}

.template-card-title {
    margin: 0 0 10px;
    color: #1e293b;
    font-size: 17px;
    font-weight: 700;
}

.template-card-description {
    display: -webkit-box;
    min-height: 44px;
    margin: 0;
    overflow: hidden;
    color: #64748b;
    font-size: 13px;
    line-height: 1.7;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}


/* 标签 */

.template-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 16px;
}

.template-tag {
    padding: 5px 9px;
    border-radius: 6px;
    background: #f1f5f9;
    color: #64748b;
    font-size: 11px;
}


/* 底部 */

.template-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #f1f5f9;
}

.template-card-size {
    color: #94a3b8;
    font-size: 12px;
}

.template-use-button {
    padding: 9px 14px;
    border: 0;
    border-radius: 9px;
    background: #eef2ff;
    color: #4338ca;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition:
        background .2s ease,
        color .2s ease;
}

.template-use-button:hover {
    background: #4f46e5;
    color: white;
}


/* 空状态 */

.template-empty {
    padding: 70px 20px;
    border: 1px dashed #d9e0eb;
    border-radius: 16px;
    background: #fafbfe;
    text-align: center;
}

.template-empty-icon {
    margin-bottom: 15px;
    color: #94a3b8;
    font-size: 35px;
}

.template-empty h3 {
    margin: 0 0 10px;
    color: #334155;
    font-size: 17px;
}

.template-empty p {
    margin: 0;
    color: #94a3b8;
    font-size: 13px;
}


/* =========================================================
   响应式
   ========================================================= */

@media (max-width: 1100px) {

    .template-grid {
        grid-template-columns: repeat(2,
                minmax(0, 1fr));
    }

}

@media (max-width: 640px) {

    .category-templates {
        margin-top: 32px;
        padding-top: 26px;
    }

    .template-section-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
    }

    .template-section-header h2 {
        font-size: 23px;
    }

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

    .template-card-cover {
        height: 230px;
    }

}

/* =========================================================
   模板操作按钮
   ========================================================= */

.template-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.template-preview-button {
    padding: 9px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 9px;
    background: #fff;
    color: #475569;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.template-preview-button:hover {
    border-color: #94a3b8;
    background: #f8fafc;
}

.template-use-button:disabled {
    opacity: .5;
    cursor: not-allowed;
}


/* =========================================================
   预览弹窗
   ========================================================= */

.template-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.template-preview-modal[hidden] {
    display: none !important;
}

.template-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(8px);
}

.template-preview-dialog {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: min(1100px, 100%);
    max-height: 92vh;
    overflow: hidden;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 30px 90px rgba(0, 0, 0, .2);
}

.template-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 24px;
    border-bottom: 1px solid #e2e8f0;
}

.template-preview-heading {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.template-preview-heading strong {
    color: #0f172a;
    font-size: 18px;
}

.template-preview-heading span {
    color: #64748b;
    font-size: 12px;
}

.template-preview-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.template-preview-stage {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

@media (max-width: 640px) {

    .template-preview-modal {
        padding: 10px;
    }

    .template-preview-dialog {
        max-height: 96vh;
        border-radius: 14px;
    }

    .template-preview-toolbar {
        flex-wrap: wrap;
        padding: 14px;
    }

    .template-preview-actions {
        width: 100%;
    }

    .template-preview-actions button {
        flex: 1;
    }

}

#templatePreviewStage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: auto;
    box-sizing: border-box;
    padding: 24px;
    background: #f1f5f9;
}

.template-preview-wrapper {
    position: relative;
    flex: 0 0 auto;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 8px 32px rgb(15 23 42 / 12%);
}

/* ================================
   模板卡片
================================ */

.template-card {
    min-width: 0;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

.template-card:hover {
    border-color: #c7d2fe;
    box-shadow: 0 8px 24px rgb(15 23 42 / 8%);
    transform: translateY(-2px);
}

/* ================================
   模板预览裁剪区域
================================ */

.template-card-cover {
    position: relative;

    width: 100%;

    /*
     * 统一卡片预览高度。
     * 可以根据你原来的卡片设计调整比例。
     */
    aspect-ratio: 5 / 4;

    overflow: hidden;

    isolation: isolate;

    background: #f3f5f8;

    border-bottom: 1px solid #edf0f4;
}

/*
 * iframe 保持模板的真实设计尺寸。
 *
 * 不设置 transform: scale()。
 * 不使用 object-fit。
 * 不改变模板的宽高比例。
 *
 * 超出卡片的部分由 cover 的 overflow:hidden 裁剪。
 */
.template-card-live-frame {
    position: absolute;

    top: 0;
    left: 0;

    display: block;

    margin: 0;
    padding: 0;

    border: 0;

    max-width: none;
    max-height: none;

    transform-origin: top left;

    pointer-events: none;

    background: #fff;
}

/* ================================
   加载占位
================================ */

.template-card-placeholder {
    position: absolute;
    inset: 0;

    z-index: 1;

    display: flex;
    flex-direction: column;

    align-items: center;
    justify-content: center;

    gap: 10px;

    padding: 16px;

    text-align: center;

    background:
        linear-gradient(
            135deg,
            #f8fafc,
            #eef2ff
        );

    color: #64748b;
}

.template-card-placeholder-icon {
    font-size: 28px;
    line-height: 1;
    color: #6366f1;
}

.template-card-placeholder-title {
    max-width: 100%;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 14px;
    font-weight: 600;
    color: #334155;
}

.template-card-placeholder-subtitle {
    font-size: 12px;
    color: #94a3b8;
}

/* ================================
   卡片内容
================================ */

.template-card-content {
    min-width: 0;
    padding: 14px;
}

.template-card-title {
    margin: 0 0 8px;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 15px;
    font-weight: 600;
    line-height: 1.5;
    color: #1e293b;
}

.template-card-description {
    display: -webkit-box;

    margin: 0 0 12px;

    overflow: hidden;

    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;

    font-size: 13px;
    line-height: 1.6;
    color: #64748b;
}

.template-card-tags {
    display: flex;
    flex-wrap: wrap;

    gap: 6px;

    margin-bottom: 12px;
}

.template-card-tag {
    padding: 3px 8px;

    border-radius: 5px;

    background: #f1f5f9;

    font-size: 11px;
    color: #475569;
}

.template-card-meta {
    display: flex;

    align-items: center;
    justify-content: space-between;

    gap: 8px;

    margin-bottom: 14px;

    font-size: 12px;
    color: #94a3b8;
}

.template-card-author {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-card-size {
    flex-shrink: 0;
}

/* ================================
   操作按钮
================================ */

.template-card-actions {
    display: flex;

    align-items: center;

    gap: 10px;
}

.template-card-preview-btn,
.template-card-use-btn {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    min-height: 36px;

    padding: 0 12px;

    border-radius: 7px;

    font-size: 13px;
    font-weight: 500;

    cursor: pointer;

    transition:
        background 0.2s ease,
        border-color 0.2s ease;
}

.template-card-preview-btn {
    flex: 1;

    border: 1px solid #e2e8f0;

    background: #fff;

    color: #334155;
}

.template-card-preview-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.template-card-use-btn {
    flex: 1;

    border: 1px solid #4f46e5;

    background: #4f46e5;

    color: #fff;
}

.template-card-use-btn:hover {
    background: #4338ca;
    border-color: #4338ca;
}