/* ===== 灵感模板模块 / 模板详情弹窗 ===== */
/* ========== 灵感模板模块 ========== */
#tplView {
    height: 100%;
    padding: 18px 22px 40px;
    overflow-y: auto;
}

.tpl-header {
    margin-bottom: 4px;
}

.tpl-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-heading);
}

.tpl-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.tpl-filter {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 16px 0 18px;
}

.tpl-chip {
    padding: 6px 15px;
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-btn);
    background: #fff;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.tpl-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.tpl-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.tpl-loading {
    grid-column: 1 / -1;
    padding: 60px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.tpl-card {
    background: var(--card-bg);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-card);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 8px rgba(61, 52, 40, 0.05);
    transition: var(--transition);
}

.tpl-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 12px 26px rgba(61, 52, 40, 0.14);
}

.tpl-cover {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: var(--ds-surface-muted);
    cursor: pointer;
}

/* contain：示例图完整展示不裁切；非 4:3 的图会留白，用底色填充 */
.tpl-cover img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    transition: transform 0.3s ease;
}

.tpl-card:hover .tpl-cover img {
    transform: scale(1.02);
}

.tpl-cover .tpl-refbadge {
    position: absolute;
    left: 10px;
    top: 10px;
    background: rgba(255, 204, 0, 0.92);
    color: #6b4b00;
    font-size: 11px;
    font-weight: 800;
    padding: 3px 10px;
    border-radius: 20px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.tpl-cover .tpl-count {
    position: absolute;
    right: 10px;
    bottom: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 20px;
}

.tpl-cover .tpl-noimg {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    color: var(--text-muted);
}

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

.tpl-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-heading);
}

.tpl-prompt {
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

.tpl-tag {
    font-size: 11px;
    padding: 2px 9px;
    border-radius: 20px;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
}

.tpl-actions {
    margin-top: auto;
    display: flex;
    gap: 8px;
}

.tpl-btn {
    flex: 1;
    padding: 8px 10px;
    border-radius: var(--radius-btn);
    border: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}

.tpl-btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 0 0 var(--primary-3d);
}

.tpl-btn-primary:hover {
    background: var(--primary-hover);
}

.tpl-btn-primary:active {
    transform: translateY(1px);
    box-shadow: none;
}

.tpl-btn-ghost {
    flex: 0 0 auto;
    background: #fff;
    border: 1.5px solid var(--border-light);
    color: var(--text-secondary);
    padding: 8px 14px;
}

.tpl-btn-ghost:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.tpl-state {
    text-align: center;
    padding: 70px 20px;
    color: var(--text-muted);
}

.tpl-state .icon {
    font-size: 46px;
    margin-bottom: 10px;
}

/* ========== 历史详情弹窗：复用模板详情的「左图右信息」布局 ========== */
#detailModal .modal-dialog {
    max-width: 980px;
    background: var(--ds-surface);
    border: 1px solid var(--ds-line-strong);
}

#detailModal .modal-header {
    background: var(--ds-surface);
    border-bottom-color: var(--ds-line);
}

/* 无结果（失败 / 排队中）时左栏占位，避免整栏塌陷 */
.detail-empty-media {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 220px;
    padding: 20px;
    text-align: center;
    background: var(--ds-surface-muted);
    border: 1.5px dashed var(--ds-line-strong);
    border-radius: 12px;
    color: var(--ds-muted);
    font-size: 13px;
    line-height: 1.8;
    word-break: break-word;
}

.detail-media-extra {
    margin-top: 14px;
    min-width: 0;
}

/* 参考图较多时（最多 16 张）限制高度，避免把左栏拉得过长 */
.detail-media-extra .modal-images {
    max-height: 200px;
    overflow-y: auto;
}

.detail-media-extra .modal-image-item {
    width: 64px;
    height: 64px;
}

.detail-meta {
    font-size: 12px;
    color: var(--ds-muted);
    line-height: 1.7;
}

/* 用量信息：有最大高度，超出在框内滚动 */
.detail-usage {
    margin: 0;
    background: var(--ds-surface-muted);
    border: 1px solid var(--ds-line-strong);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--ds-ink-soft);
    max-height: 140px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ========== 模板详情弹窗：左侧示例图 + 右侧信息 ========== */
#tplDetailModal .modal-dialog {
    max-width: 980px;
    background: var(--ds-surface);
    border: 1px solid var(--ds-line-strong);
}

#tplDetailModal .modal-header {
    background: var(--ds-surface);
    border-bottom-color: var(--ds-line);
}

.tpl-detail {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.tpl-detail-media,
.tpl-detail-info {
    min-width: 0;
}

.tpl-detail-info {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tpl-detail-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

/* 多张示例图：方形格子内完整展示（不裁切）；max-width 兜底，
   保证任何情况下图片都不会横向溢出到右侧信息栏 */
.tpl-detail-gallery img {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    background: var(--ds-surface-muted);
    border: 1px solid var(--ds-line-strong);
    border-radius: 12px;
    cursor: zoom-in;
    transition: border-color var(--ds-ease), transform var(--ds-ease), box-shadow var(--ds-ease);
}

/* 只有一张示例图：铺满整列、按原图比例完整展示，
   仅限制最大高度，避免竖版长图把弹窗撑得过高 */
.tpl-detail-gallery img:only-child {
    grid-column: 1 / -1;
    justify-self: center;
    width: auto;
    height: auto;
    aspect-ratio: auto;
    max-height: min(64vh, 560px);
}

.tpl-detail-gallery img:hover {
    border-color: var(--ds-primary);
    box-shadow: var(--ds-shadow-sm);
    transform: translateY(-2px);
}

.tpl-detail-label {
    display: block;
    font-size: 12px;
    font-weight: 800;
    color: var(--ds-muted);
    margin-bottom: 8px;
}

.tpl-detail-prompt {
    background: var(--ds-surface-muted);
    border: 1px solid var(--ds-line-strong);
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.8;
    color: var(--ds-ink-soft);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 220px;
    overflow-y: auto;
}

.tpl-detail-params {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tpl-detail-actions {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.tpl-detail-actions .tpl-detail-apply {
    flex: 1;
}

.tpl-detail-actions .tpl-btn:not(.tpl-btn-primary) {
    flex-shrink: 0;
    padding: 12px 14px;
    white-space: nowrap;
}

.tpl-detail-apply {
    padding: 12px;
}

.tpl-ref-notice {
    background: var(--warning-bg);
    border: 1.5px dashed var(--warning);
    color: #8a6100;
    font-size: 12.5px;
    line-height: 1.6;
    padding: 10px 12px;
    border-radius: 12px;
}

.tpl-param-pill {
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 20px;
    background: var(--ds-surface-muted);
    border: 1px solid var(--ds-line-strong);
    color: var(--ds-ink-soft);
    font-weight: 600;
}

/* 模板视图下隐藏移动端底部操作栏 */
body.tpl-mode .mobile-bottom-bar {
    display: none !important;
}

/* 套用模板后高亮参数面板 */
.left-panel.tpl-applied .card,
.left-panel.tpl-applied .btn-generate {
    animation: tplPulse 1.6s ease;
}

@keyframes tplPulse {
    0%   { box-shadow: 0 0 0 0 rgba(25, 200, 185, 0.55); }
    70%  { box-shadow: 0 0 0 10px rgba(25, 200, 185, 0); }
    100% { box-shadow: 0 0 0 0 rgba(25, 200, 185, 0); }
}

/* 中小屏：侧栏随之收窄，为结果区留出空间 */
@media (max-width: 1060px) {
    .app-sidebar {
        width: 212px;
    }
}

@media (max-width: 768px) {
    /* 移动端：侧栏简化为顶栏下方的横向菜单，历史继续走原有抽屉 */
    .header-model {
        display: none;
    }

    .empty-steps {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .opt-btn {
        min-width: 50px;
        padding: 6px 9px;
        font-size: 12px;
    }

    .app-body {
        flex-direction: column;
    }

    .app-sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        flex-shrink: 0;
        border-right: none;
        border-bottom: 2px solid var(--border-light);
        padding: 6px 10px;
    }

    .sidebar-menu {
        flex-direction: row;
        gap: 6px;
        width: 100%;
        padding: 0;
        overflow-x: auto;
    }

    .sidebar-menu-item {
        width: auto;
        padding: 7px 14px;
        font-size: 13px;
        border-radius: var(--radius-btn);
        white-space: nowrap;
    }

    .app-sidebar .history-sidebar {
        display: none;
    }

    .app-main {
        flex: 1;
        min-height: 0;
    }

    .app-main .main-container {
        height: 100%;
        padding: 0;
    }

    #tplView {
        height: 100%;
        padding: 14px 14px 90px;
    }

    .tpl-title {
        font-size: 17px;
    }

    .tpl-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }

    /* 模板详情：窄屏改为上图下信息 */
    .tpl-detail {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }
}
