/**
 * =========================================================
 * Tutorial Studio
 * Template Panel
 *
 * 文件：css/main/sidebar/template_panel.css
 *
 * 左侧模板库：分类、搜索、模板卡片、缩略图、
 * 使用确认和空状态。
 * =========================================================
 */

.template-panel {
    position: relative;

    --ts-template-border: #e6ebf2;
    --ts-template-accent: #2563eb;
    --ts-template-muted: #94a3b8;
}

.template-panel-body {
    padding: 12px 14px 16px;
}

.template-panel .sidebar-search {
    margin-bottom: 12px;
}

.template-category-list {
    margin: 0 0 14px;
}

/* =========================================================
   01. 列表
========================================================= */

.template-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}


/* =========================================================
   02. 卡片
========================================================= */

.ts-template-card {
    display: flex;
    flex-direction: column;

    width: 100%;

    padding: 0;

    border: 1px solid var(--ts-template-border);
    border-radius: 11px;

    background: #ffffff;

    color: inherit;

    font: inherit;
    text-align: left;

    overflow: hidden;

    cursor: pointer;

    transition:
        border-color .16s ease,
        box-shadow .16s ease,
        transform .16s ease;
}

.ts-template-card:hover {
    border-color: #bcd0f7;

    box-shadow:
        0 8px 20px rgba(37, 99, 235, .1);

    transform: translateY(-1px);
}

.ts-template-card:active {
    transform: translateY(0);
}

.ts-template-card:focus-visible {
    outline: 2px solid var(--ts-template-accent);
    outline-offset: 2px;
}

/* ---------- 封面 ---------- */

.ts-template-cover {
    position: relative;

    display: block;

    width: 100%;

    aspect-ratio: 3 / 2;

    background:
        var(--ts-template-thumb-bg, #f2f5f9);

    overflow: hidden;

    contain: paint;
}

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

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    gap: 6px;

    padding: 10px;

    background:
        linear-gradient(135deg,
            rgba(255, 255, 255, .55),
            rgba(255, 255, 255, 0) 60%),
        var(--ts-template-thumb-bg, #f2f5f9);

    color: rgba(71, 85, 105, .58);

    font-size: 10px;

    text-align: center;

    pointer-events: none;

    transition: opacity .2s ease;
}

.ts-template-placeholder-mark {
    font-size: 18px;
    line-height: 1;
    opacity: .7;
}

.ts-template-placeholder-text {
    line-height: 1.4;
}

.ts-template-card.has-preview .ts-template-placeholder {
    opacity: 0;
}

.ts-template-card.has-preview-error .ts-template-placeholder-text {
    color: #b45309;
}

/* ---------- 缩略图 ---------- */

.ts-template-frame {
    display: block;

    border: 0;

    background: #ffffff;
}

.ts-template-image {
    position: absolute;
    inset: 0;

    display: block;

    width: 100%;
    height: 100%;

    object-fit: cover;

    background: #ffffff;
}

/* ---------- 角标 ---------- */

.ts-template-pages {
    position: absolute;
    top: 8px;
    right: 8px;

    z-index: 2;

    padding: 2px 7px;

    border-radius: 999px;

    background: rgba(15, 23, 42, .62);

    color: #ffffff;

    font-size: 9.5px;
    letter-spacing: .02em;

    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);

    pointer-events: none;
}

.ts-template-use {
    position: absolute;
    right: 8px;
    bottom: 8px;

    z-index: 2;

    padding: 4px 9px;

    border-radius: 999px;

    background: var(--ts-template-accent);

    color: #ffffff;

    font-size: 10px;
    font-weight: 600;

    opacity: 0;

    transform: translateY(4px);

    transition:
        opacity .16s ease,
        transform .16s ease;

    pointer-events: none;
}

.ts-template-card:hover .ts-template-use,
.ts-template-card:focus-visible .ts-template-use {
    opacity: 1;

    transform: none;
}

@media (hover: none) {
    .ts-template-use {
        opacity: .92;

        transform: none;
    }
}

/* ---------- 文本 ---------- */

.ts-template-info {
    display: flex;
    flex-direction: column;

    gap: 3px;

    min-width: 0;

    padding: 8px 10px 10px;
}

.ts-template-title {
    display: -webkit-box;

    overflow: hidden;

    color: #1f2937;

    font-size: 12px;
    font-weight: 600;
    line-height: 1.45;

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

.ts-template-meta {
    overflow: hidden;

    color: var(--ts-template-muted);

    font-size: 10px;

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


/* =========================================================
   03. 骨架
========================================================= */

.ts-template-card--skeleton {
    pointer-events: none;
}

.ts-template-skeleton-cover {
    position: absolute;
    inset: 0;

    background:
        linear-gradient(90deg,
            #eef2f7 25%,
            #f8fafc 37%,
            #eef2f7 63%);

    background-size: 400% 100%;

    animation:
        ts-template-shimmer 1.3s ease infinite;
}

.ts-template-skeleton-line {
    height: 9px;

    border-radius: 4px;

    background:
        linear-gradient(90deg,
            #eef2f7 25%,
            #f8fafc 37%,
            #eef2f7 63%);

    background-size: 400% 100%;

    animation:
        ts-template-shimmer 1.3s ease infinite;
}

.ts-template-skeleton-line.is-short {
    width: 52%;
}

@keyframes ts-template-shimmer {

    from {
        background-position: 100% 50%;
    }

    to {
        background-position: 0 50%;
    }
}


/* =========================================================
   04. 空状态 / 错误状态
========================================================= */

.ts-template-state {
    display: flex;
    flex-direction: column;
    align-items: center;

    gap: 6px;

    padding: 30px 12px;

    text-align: center;

    color: var(--ts-template-muted);
}

.ts-template-state-mark {
    display: grid;
    place-items: center;

    width: 36px;
    height: 36px;

    border-radius: 50%;

    background: #f1f5f9;

    color: #94a3b8;

    font-size: 17px;
}

.ts-template-state-title {
    color: #475569;

    font-size: 12.5px;
    font-weight: 600;
}

.ts-template-state-text {
    font-size: 11px;
    line-height: 1.6;

    word-break: break-word;
}

.ts-template-state-button {
    margin-top: 6px;

    padding: 6px 13px;

    border:
        1px solid #cfe0ff;

    border-radius: 999px;

    background: #eff6ff;

    color: var(--ts-template-accent);

    font-size: 11px;

    cursor: pointer;
}

.ts-template-state-button:hover {
    background: #dbeafe;
}


/* =========================================================
   05. 使用确认
========================================================= */

.template-confirm {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;

    z-index: 6;

    padding: 11px 12px;

    border-radius: 12px;

    background: #0f172a;

    color: #e2e8f0;

    box-shadow:
        0 16px 40px rgba(15, 23, 42, .35);

    opacity: 0;

    transform: translateY(8px);

    transition:
        opacity .16s ease,
        transform .16s ease;
}

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

.template-confirm.is-visible {
    opacity: 1;

    transform: none;
}

.template-confirm-text {
    display: flex;
    flex-direction: column;

    gap: 3px;

    margin: 0 0 9px;
}

.template-confirm-text strong {
    overflow: hidden;

    font-size: 12px;
    font-weight: 600;

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

.template-confirm-text span {
    color: #94a3b8;

    font-size: 10.5px;
    line-height: 1.5;
}

.template-confirm-actions {
    display: flex;
    justify-content: flex-end;

    gap: 6px;
}

.template-confirm-actions button {
    padding: 6px 11px;

    border: 1px solid transparent;
    border-radius: 8px;

    font-size: 11px;

    cursor: pointer;
}

.template-confirm-cancel {
    border-color: #334155;

    background: transparent;

    color: #cbd5e1;
}

.template-confirm-cancel:hover {
    background: rgba(255, 255, 255, .06);
}

.template-confirm-apply {
    background: var(--ts-template-accent);

    color: #ffffff;
}

.template-confirm-apply:hover {
    background: #1d4ed8;
}

.template-confirm-actions button:disabled {
    opacity: .6;

    cursor: default;
}

/* 确认栏打开时，给列表底部留出空间。 */

.template-panel.has-template-confirm .template-panel-body {
    padding-bottom: 118px;
}


/* =========================================================
   06. 响应式
========================================================= */

@media (max-width: 768px) {
    .template-panel-body {
        padding: 12px 12px 16px;
    }

    .ts-template-cover {
        aspect-ratio: 16 / 10;
    }
}


/* =========================================================
   07. 降低动态效果
========================================================= */

@media (prefers-reduced-motion: reduce) {
    .ts-template-card,
    .ts-template-use,
    .ts-template-placeholder,
    .template-confirm,
    .ts-template-skeleton-cover,
    .ts-template-skeleton-line {
        animation: none !important;
        transition: none !important;
    }
}
