:root {
    color-scheme: light;
    --bg: #f6f7f4;
    --surface: #ffffff;
    --surface-strong: #eef2ec;
    --text: #18201b;
    --muted: #667066;
    --border: #dfe5dc;
    --accent: #2f6f4e;
    --accent-strong: #24583d;
    --warning: #9a5b16;
    --danger: #a33a32;
    --shadow: 0 14px 40px rgba(33, 47, 38, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    width: min(1440px, calc(100vw - 40px));
    margin: 0 auto;
    padding: 28px 0 40px;
}

.topbar,
.filters,
.status-strip,
.pager,
.preview-bar {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar {
    justify-content: space-between;
    margin-bottom: 18px;
}

.topbar h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1.2;
    font-weight: 700;
}

.topbar p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn {
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.btn.primary {
    background: var(--accent);
    color: #fff;
}

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

.btn.secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.btn.secondary:hover {
    border-color: #b8c5b8;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.status-strip {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin: 14px 0 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
}

.status-strip div {
    padding: 14px 16px;
    border-right: 1px solid var(--border);
}

.status-strip div:last-child {
    border-right: 0;
}

.status-strip span {
    display: block;
    font-size: 22px;
    font-weight: 700;
}

.status-strip small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
}

.filters {
    align-items: flex-end;
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
}

.filters label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.filters select,
.filters input {
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 0 12px;
}

.filters select {
    min-width: 240px;
}

.filters input {
    width: min(520px, 48vw);
}

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

.template-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    min-width: 0;
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

.template-card.clickable {
    cursor: pointer;
}

.template-card.clickable:hover,
.template-card.clickable:focus-visible {
    border-color: #bdd0c0;
    box-shadow: 0 18px 46px rgba(33, 47, 38, 0.13);
    transform: translateY(-2px);
    outline: none;
}

.thumb-link,
.thumb-placeholder {
    display: block;
    aspect-ratio: 16 / 9;
    background: var(--surface-strong);
    color: var(--muted);
    text-decoration: none;
    overflow: hidden;
}

.thumb-link img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    /* 缩略图悬浮时轻微放大，增强客户浏览模板时的反馈感。 */
    transition: transform .24s ease, filter .24s ease;
    transform-origin: center;
}

.template-card.clickable:hover .thumb-link img,
.template-card.clickable:focus-visible .thumb-link img {
    transform: scale(1.045);
    filter: saturate(1.05);
}

.thumb-placeholder {
    display: grid;
    place-items: center;
    text-align: center;
    padding: 18px;
}

.thumb-placeholder strong {
    display: block;
    color: var(--text);
    margin-bottom: 6px;
}

.template-card-body {
    padding: 14px 14px 46px;
}

.template-card h2 {
    margin: 0;
    font-size: 16px;
    line-height: 1.4;
    font-weight: 650;
    /* 模板标题固定单行展示，长标题用省略号收起。 */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-meta {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
    /* 模板路径固定两行高度，避免卡片按钮区上下跳动。 */
    height: 39px;
    overflow: hidden;
    word-break: break-word;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

/* 客户反馈编号固定在卡片右下角，和标题、路径、状态区域保持独立。 */
.template-number {
    position: absolute;
    right: 14px;
    bottom: 14px;
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 6px;
    background: #eef2ec;
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 650;
    pointer-events: none;
}

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.card-actions .btn {
    flex: 1;
}

.empty-state {
    padding: 48px;
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 8px;
}

.pager {
    justify-content: center;
    margin-top: 22px;
}

#pageText {
    color: var(--muted);
    min-width: 120px;
    text-align: center;
}

.preview-body {
    height: 100vh;
    overflow: hidden;
    background: #f0f2ef;
}

.preview-bar {
    height: 58px;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.preview-title {
    min-width: 0;
    flex: 1;
    display: grid;
    gap: 2px;
}

.preview-title strong,
.preview-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-title span {
    color: var(--muted);
    font-size: 13px;
}

.preview-main {
    height: calc(100vh - 58px);
}

.preview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

.preview-unavailable {
    display: grid;
    place-content: center;
    height: calc(100vh - 58px);
    text-align: center;
    color: var(--muted);
}

.preview-unavailable h1 {
    margin: 0 0 8px;
    color: var(--text);
}

@media (max-width: 720px) {
    .app-shell {
        width: min(100vw - 24px, 720px);
        padding-top: 18px;
    }

    .topbar,
    .filters {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions {
        justify-content: stretch;
    }

    .topbar-actions .btn,
    .filters input,
    .filters select {
        width: 100%;
    }

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

    .status-strip div:nth-child(2n) {
        border-right: 0;
    }

    .template-grid {
        grid-template-columns: 1fr;
    }
}
