/* 模板相关样式 */
.template-button {
    background: linear-gradient(145deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    margin: 2rem auto;
    transition: all 0.2s ease;
    display: block;
}

/* 模板选择动画 */
@keyframes templateSelectPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.5);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(102, 126, 234, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0);
    }
}

/* 内嵌模板容器样式 */
.template-container {
    width: 100%;
    padding: 20px 0;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin: 15px 0;
}

/* 添加搜索框容器样式 */
.template-search {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    gap: 10px;
}

.template-search input {
    width: 60%;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 30px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

.template-search input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.template-search button {
    padding: 10px 18px;
    background: linear-gradient(145deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.search-reset-btn {
    background: #f0f4ff !important;
    color: #667eea !important;
    border: 1px solid #dde2ff !important;
    margin-left: 5px;
}

.search-reset-btn:hover {
    background: #e0e7ff !important;
    border-color: #667eea !important;
}

.template-search button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* 添加模板选择提示样式 */
.template-selection-hint {
    text-align: center;
    color: #555;
    font-size: 15px;
    margin-bottom: 20px;
    padding: 10px 20px;
    background-color: #f7f9ff;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* 修改模板网格样式 - 更紧凑的布局 */
.template-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin: 0 auto 20px;
    max-width: 900px;
    height: 540px;
    overflow-y: auto;
    padding: 0 15px 5px;
    scrollbar-width: thin;
    scrollbar-color: #ddd #f5f5f5;
}

.template-grid::-webkit-scrollbar {
    width: 8px;
}

.template-grid::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 10px;
}

.template-grid::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 10px;
    border: 2px solid #f5f5f5;
}

/* 新的模板卡片样式 */
.template-card {
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    background: white;
    transition: box-shadow 0.3s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    height: 220px;
    border: 2px solid transparent;
    position: relative;
}

.template-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    border-color: #d1d5db;
}

.template-preview {
    width: 100%;
    height: 160px;
    overflow: hidden;
    position: relative;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
}

.template-preview img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    padding: 5px;
    transition: none;
}

/* 模板图标样式 */
.template-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #ccc;
    background-color: #f8f9fa;
}

.template-icon i {
    font-size: 48px;
    opacity: 0.6;
}

/* 图片占位符样式 */
.placeholder-img {
    padding: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

.template-card:hover .template-preview img {
    transform: none;
}

.template-info {
    padding: 12px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.template-info h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-card.selected {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

.template-card.selected::after {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: #667eea;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.template-card.selected .template-info h4 {
    color: #667eea;
}

/* 空状态样式 */
.empty-templates {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: #666;
    text-align: center;
    padding: 20px;
}

.empty-templates-icon {
    font-size: 48px;
    color: #ccd;
    margin-bottom: 15px;
}

.empty-templates-text {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-templates-subtext {
    font-size: 14px;
    color: #888;
}

/* 加载状态样式 */
.template-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: #667eea;
}

.template-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(102, 126, 234, 0.2);
    border-radius: 50%;
    border-top-color: #667eea;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 15px;
}

.template-loading-text {
    font-size: 16px;
    font-weight: 500;
}

.template-loading-subtext {
    font-size: 14px;
    color: #777;
    margin-top: 8px;
}

/* 加载更多指示器 */
.template-loading-more {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    grid-column: 1 / -1;
    color: #667eea;
    gap: 10px;
}

.template-loading-more .template-loading-spinner {
    width: 24px;
    height: 24px;
    margin: 0;
}

/* 模板数量计数 */
.template-count {
    text-align: center;
    color: #666;
    font-size: 14px;
    margin-bottom: 15px;
}

.count-highlight {
    color: #667eea;
    font-weight: 600;
}

.search-keyword {
    color: #f43f5e;
    font-weight: 600;
}

.template-count.no-results {
    color: #888;
    font-style: italic;
    padding: 10px 0;
}

.scroll-hint {
    display: inline-block;
    margin-left: 10px;
    color: #667eea;
    font-size: 13px;
    animation: bounceDown 1.5s infinite;
}

@keyframes bounceDown {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(3px);
    }
    60% {
        transform: translateY(2px);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-templates {
    text-align: center;
    padding: 25px;
    color: #667eea;
    font-size: 16px;
    font-weight: 500;
}

.no-templates, .error-message {
    text-align: center;
    padding: 25px;
    color: #666;
    font-size: 15px;
    background: #f9f9f9;
    border-radius: 10px;
    margin: 15px auto;
    max-width: 500px;
}

.error-message {
    color: #e74c3c;
    background: #fde8e7;
}

/* 分页控件样式 */
#pagination {
    display: flex;
    justify-content: center;
    margin: 15px 0 25px;
}

.pagination-container {
    display: flex;
    gap: 6px;
    align-items: center;
}

.pagination-container button {
    padding: 6px 12px;
    background: #f0f4ff;
    border: 1px solid #dde2ff;
    border-radius: 6px;
    color: #667eea;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.pagination-container button:hover:not(:disabled) {
    background: #dde2ff;
    border-color: #667eea;
}

.pagination-container button.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
    font-weight: bold;
}

.pagination-container button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 添加模板类型切换按钮样式 */
.template-type-switch {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    gap: 12px;
}

.template-type-btn {
    padding: 8px 20px;
    background: #fff;
    border: 2px solid #667eea;
    color: #667eea;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.template-type-btn.active {
    background: #667eea;
    color: #fff;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.template-type-btn:hover:not(.active) {
    background: #f0f4ff;
}

.template-type-btn:active {
    transform: scale(0.95);
}

.template-type-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    transition: all 0.3s ease;
}

.template-type-btn:active::after {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    transition: 0s;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .template-container {
        padding: 15px 0;
    }
    
    .template-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        height: 460px;
        padding: 0 10px 5px;
    }
    
    .template-card {
        height: 200px;
    }
    
    .template-preview {
        height: 140px;
    }
    
    .template-search input {
        width: 65%;
    }
}

@media (max-width: 480px) {
    .template-container {
        padding: 8px 0;
    }
    .template-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
        height: auto;
        min-height: 200px;
        padding: 0 4px 5px;
        max-width: 100vw;
    }
    .template-card {
        height: 120px;
        min-height: 110px;
        border-radius: 10px;
    }
    .template-preview {
        height: 60px;
        min-height: 50px;
        padding: 2px;
    }
    .template-preview img {
        max-height: 56px;
        width: auto;
        object-fit: contain;
        margin: 0 auto;
        display: block;
    }
    .template-info {
        padding: 4px 2px 2px 2px;
    }
    .template-info h4 {
        font-size: 12px;
        line-height: 1.2;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .template-type-btn {
        padding: 5px 10px;
        font-size: 12px;
        border-radius: 20px;
        min-width: 60px;
    }
    .template-search {
        flex-direction: row;
        align-items: center;
        gap: 6px;
        margin-bottom: 10px;
        width: 95%;
        max-width: 100vw;
    }
    .template-search input {
        width: 0;
        flex: 1 1 0%;
        min-width: 0;
        max-width: 100%;
        padding: 7px 10px;
        font-size: 13px;
        border-radius: 18px;
    }
    .template-search button {
        width: auto;
        min-width: 60px;
        max-width: 100px;
        padding: 7px 10px;
        font-size: 13px;
        border-radius: 18px;
        margin: 0;
        flex-shrink: 0;
    }
    .search-reset-btn {
        min-width: 60px;
        max-width: 100px;
        padding: 7px 10px;
        font-size: 13px;
        border-radius: 18px;
        margin: 0 0 0 4px;
    }
}

/* 超小屏幕优化 */
@media (max-width: 320px) {
    .template-grid {
        grid-template-columns: repeat(1, 1fr);
        height: 360px;
    }

    .template-card {
        height: 200px;
    }
    
    .template-preview {
        height: 140px;
    }
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 24px;
    font-weight: bold;
    color: #aaa;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.3s;
}

.close-modal:hover {
    color: #333;
}

/* 添加模板卡片点击效果 */
.template-card.clicking {
    transform: scale(0.98);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

/* 添加点击波纹效果 */
@keyframes template-click-ripple {
    0% {
        opacity: 1;
        transform: scale(0.3);
    }
    100% {
        opacity: 0;
        transform: scale(1);
    }
}

.template-card.clicking::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(99, 102, 241, 0.1);
    border-radius: 12px;
    animation: template-click-ripple 0.4s ease-out forwards;
    pointer-events: none;
    z-index: 1;
} 