:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-soft: #f8faff;
    --ink: #111b34;
    --muted: #68738c;
    --line: #e5eaf3;
    --primary: #dc5896;
    --primary-dark: #c54280;
    --cyan: #72c9ca;
    --navy: #252730;
    --danger: #d14343;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05), 0 5px 16px rgba(16, 24, 40, .05);
    --shadow-lg: 0 18px 45px rgba(30, 43, 80, .12);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --shell: 1440px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    background:
        radial-gradient(circle at 8% 0, rgba(156, 234, 230, .2), transparent 27rem),
        radial-gradient(circle at 88% 4%, rgba(223, 186, 230, .18), transparent 24rem),
        var(--bg);
    color: var(--ink);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.shell { width: min(calc(100% - 48px), var(--shell)); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 1000; transform: translateY(-150%); padding: 10px 14px; border-radius: 8px; background: var(--navy); color: white; }
.skip-link:focus { transform: translateY(0); }
:focus-visible { outline: 3px solid rgba(91, 92, 240, .34); outline-offset: 3px; }

.site-header {
    position: sticky; top: 0; z-index: 50;
    background: rgba(255, 255, 255, .88);
    border-bottom: 1px solid rgba(229, 234, 243, .9);
    backdrop-filter: blur(18px);
}
.header-inner { min-height: 76px; display: grid; grid-template-columns: auto minmax(280px, 500px); align-items: center; justify-content: space-between; gap: 36px; }
.brand, .preview-brand { display: inline-flex; align-items: center; gap: 11px; font-size: 20px; font-weight: 800; letter-spacing: -.03em; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: white; background: linear-gradient(135deg, #e878aa, #cf4f8d 58%, #7acccc); box-shadow: 0 8px 18px rgba(220,88,150,.22); }
.brand-mark svg { width: 23px; height: 23px; }
.top-nav { display: flex; align-items: center; gap: 24px; color: #566179; font-weight: 600; }
.top-nav a { min-height: 44px; display: inline-flex; align-items: center; position: relative; }
.top-nav a:hover, .top-nav a.active { color: var(--primary); }
.top-nav a.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 1px; height: 3px; border-radius: 3px; background: var(--primary); }
.header-search { height: 46px; display: flex; align-items: center; gap: 10px; padding: 4px 5px 4px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); transition: .2s ease; }
.header-search:focus-within { background: white; border-color: rgba(220,88,150,.55); box-shadow: 0 0 0 4px rgba(220,88,150,.09); }
.header-search svg { width: 19px; color: #8993a8; }
.header-search input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--ink); background: transparent; }
.header-search input::placeholder { color: #9aa3b5; }
.header-search button, .button { min-height: 36px; padding: 0 17px; border: 0; border-radius: 10px; background: var(--primary); color: white; font-weight: 700; transition: .2s ease; }
.header-search button:hover, .button:hover { background: var(--primary-dark); }

.page-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; padding-block: 34px 64px; align-items: start; }
.filter-toggle { display: none; }
.filter-panel { position: sticky; top: 108px; max-height: calc(100vh - 132px); overflow: auto; padding: 20px 16px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); scrollbar-width: thin; }
.filter-heading { display: flex; align-items: end; justify-content: space-between; padding: 4px 6px 16px; border-bottom: 1px solid var(--line); }
.eyebrow { display: block; color: var(--primary); font-size: 11px; line-height: 1.2; font-weight: 800; letter-spacing: .12em; }
.filter-heading h2 { margin: 4px 0 0; font-size: 19px; line-height: 1.3; }
.clear-filter { color: var(--muted); font-size: 13px; }
.clear-filter:hover { color: var(--primary); }
.category-tree { margin-top: 5px; }
.category-group { padding-block: 4px; border-bottom: 1px solid #f0f2f7; }
.category-group:last-child { border: 0; }
.category-link { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 10px; color: #59647b; transition: .16s ease; }
.category-link span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.category-link strong { min-width: 28px; padding: 1px 6px; border-radius: 999px; background: #f0f2f8; color: #9099aa; font-size: 11px; text-align: center; font-variant-numeric: tabular-nums; }
.category-link.parent { color: var(--ink); font-weight: 700; }
.category-children .category-link { min-height: 38px; padding-left: 18px; font-size: 13px; }
.category-link:hover { color: var(--primary); background: #fff4f9; }
.category-link.selected { color: #fff; background: linear-gradient(110deg, var(--primary), #ec7bac); box-shadow: 0 7px 16px rgba(220,88,150,.2); }
.category-link.selected strong { background: rgba(255,255,255,.17); color: white; }

.results { min-width: 0; }
.results-head { min-height: 100px; display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 22px; padding: 6px 2px; }
.results-head h1 { margin: 5px 0 0; font-size: clamp(27px, 3vw, 38px); line-height: 1.15; letter-spacing: -.035em; }
.results-head p { margin: 8px 0 0; color: var(--muted); }
.results-head p strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.quick-filters { display: flex; gap: 10px; }
.quick-filters label { position: relative; }
.quick-filters label > span { position: absolute; top: -8px; left: 11px; z-index: 1; padding: 0 4px; background: var(--bg); color: #8992a4; font-size: 10px; font-weight: 700; }
.quick-filters select { min-width: 132px; height: 44px; padding: 0 34px 0 13px; border: 1px solid var(--line); border-radius: 11px; background: white; color: #3e4960; font-weight: 600; }

.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.template-card { min-width: 0; overflow: hidden; background: var(--surface); border: 1px solid rgba(224,229,239,.95); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease; }
.template-card:hover { transform: translateY(-4px); border-color: rgba(220,88,150,.28); box-shadow: var(--shadow-lg); }
.template-shot { position: relative; display: block; overflow: hidden; aspect-ratio: 16 / 10; background: linear-gradient(135deg, #eef1f8, #e4e9f4); }
.template-shot::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(11,18,42,.42), transparent 56%); opacity: 0; transition: opacity .22s ease; }
.template-shot img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: top; transition: transform .65s ease; }
.template-shot img.scroll-preview { position: absolute; inset: 0 auto auto 0; height: auto; min-height: 100%; object-fit: unset; }
.template-card:hover .template-shot img.scroll-preview { transform: translateY(var(--preview-scroll, 0)); transition-duration: var(--preview-duration, 4s); transition-timing-function: linear; }
.template-card:hover .template-shot::after { opacity: 1; }
.image-placeholder { height: 100%; display: grid; place-items: center; color: #8c96aa; font-weight: 600; }
.preview-action { position: absolute; left: 50%; top: 54%; z-index: 2; transform: translate(-50%, -42%); opacity: 0; display: flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 999px; background: white; color: var(--ink); font-size: 13px; font-weight: 800; box-shadow: 0 12px 30px rgba(9,15,38,.2); transition: .2s ease; }
.preview-action svg { width: 16px; fill: currentColor; stroke: none; }
.template-card:hover .preview-action { top: 50%; opacity: 1; }
.card-body { padding: 16px 17px 17px; }
.card-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: #8992a4; font-size: 11px; }
.category-pill { max-width: 68%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 3px 8px; border-radius: 999px; background: #fff0f7; color: #c74682; font-weight: 700; }
.card-body h2 { min-height: 48px; margin: 11px 0 13px; font-size: 16px; line-height: 1.5; letter-spacing: -.01em; }
.card-body h2 a { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-body h2 a:hover { color: var(--primary); }
.card-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid #edf0f5; }
.framework { color: var(--muted); font-size: 12px; font-weight: 600; }
.arrow-link { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: #f3f5fa; color: #69758d; }
.arrow-link svg { width: 17px; }
.arrow-link:hover { color: white; background: var(--primary); }

.pagination { margin-top: 30px; }
.pagination ul { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin: 0; padding: 0; list-style: none; }
.pagination li, .pagination a, .pagination span { min-width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; }
.pagination a, .pagination span { padding: 0 10px; border: 1px solid var(--line); background: white; color: #58637a; }
.pagination a:hover, .pagination .active span { border-color: var(--primary); background: var(--primary); color: white; }
.pagination .disabled span { opacity: .5; }
.empty-state { min-height: 460px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px; border: 1px dashed #ccd3e2; border-radius: var(--radius-lg); background: rgba(255,255,255,.6); text-align: center; }
.empty-state svg { width: 52px; height: 52px; color: #a2acc0; }
.empty-state h2 { margin: 17px 0 2px; }
.empty-state p { margin: 0 0 20px; color: var(--muted); }
.button { display: inline-flex; align-items: center; justify-content: center; }
.site-footer { padding: 26px 0; border-top: 1px solid var(--line); color: var(--muted); background: white; text-align: center; font-size: 13px; }

/* Preview */
.preview-page { height: 100dvh; overflow: hidden; background: #dce1ec; }
.preview-bar { height: 64px; display: grid; grid-template-columns: 220px minmax(0, 1fr) auto auto; align-items: center; gap: 22px; padding: 0 18px; background: var(--navy); color: white; box-shadow: 0 4px 20px rgba(4,9,25,.2); }
.preview-brand { font-size: 17px; }
.preview-brand .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
.preview-title { min-width: 0; text-align: center; }
.preview-title strong, .preview-title span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.preview-title strong { font-size: 14px; }
.preview-title span { color: #9da8c3; font-size: 10px; }
.device-switch { display: flex; gap: 4px; padding: 4px; border: 1px solid rgba(255,255,255,.12); border-radius: 10px; background: rgba(255,255,255,.06); }
.device-switch button { width: 36px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: #93a0bd; }
.device-switch button:hover, .device-switch button.active { background: var(--primary); color: white; }
.device-switch svg { width: 18px; }
.preview-links { display: flex; align-items: center; gap: 12px; color: #c7cee0; font-size: 12px; }
.preview-close { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: rgba(255,255,255,.09); }
.preview-close:hover { background: rgba(255,255,255,.16); }
.preview-close svg { width: 18px; }
.preview-stage { position: relative; height: calc(100dvh - 64px); display: flex; justify-content: center; overflow: auto; background: #dfe4ed; }
.preview-stage iframe { position: relative; z-index: 2; width: 100%; height: 100%; flex: 0 0 auto; border: 0; background: white; box-shadow: 0 0 0 1px rgba(15,23,42,.07), 0 18px 50px rgba(15,23,42,.16); transition: width .28s ease; }
.preview-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; color: #657087; font-weight: 600; }
.preview-loading span { width: 20px; height: 20px; border: 2px solid #bdc5d5; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
.preview-loading.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Admin */
.admin-page { min-height: 100dvh; background: #f4f6fa; }
.admin-shell { width: min(calc(100% - 40px), 1180px); margin-inline: auto; }
.admin-header { background: var(--navy); color: white; }
.admin-header .admin-shell { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.admin-actions { display: flex; align-items: center; gap: 10px; }
.admin-main { padding-block: 30px 60px; }
.panel { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-md); background: white; box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.panel-head h1 { margin: 0; font-size: 24px; }
.admin-search { display: flex; gap: 8px; }
.admin-search input, .form-control { width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid #dce1eb; border-radius: 10px; background: white; color: var(--ink); }
.admin-search input:focus, .form-control:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(220,88,150,.09); }
.btn { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 0 15px; border: 0; border-radius: 9px; background: #edf0f6; color: #43506a; font-weight: 700; }
.btn-primary { background: var(--primary); color: white; }
.btn-danger { color: var(--danger); background: #fff0f0; }
.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 10px; border-bottom: 1px solid #edf0f5; text-align: left; vertical-align: middle; }
.data-table th { color: #748098; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.data-table td { font-size: 13px; }
.data-table .thumb { width: 74px; height: 47px; object-fit: cover; border-radius: 7px; background: #edf0f5; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; }
.status-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #aab2c1; }
.status-dot.on::before { background: var(--cyan); }
.row-actions { display: flex; gap: 6px; }
.row-actions form { margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-group { display: flex; flex-direction: column; gap: 7px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { color: #46526a; font-size: 13px; font-weight: 700; }
.form-help { color: #8a94a8; font-size: 11px; }
.checkbox-row { display: flex; flex-wrap: wrap; gap: 24px; }
.checkbox-row label { min-height: 44px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; }
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, rgba(122,204,204,.24), transparent 28rem), radial-gradient(circle at top right, rgba(220,88,150,.26), transparent 30rem), var(--navy); }
.login-card { width: min(100%, 420px); padding: 32px; border-radius: 20px; background: white; box-shadow: 0 30px 80px rgba(0,0,0,.24); }
.login-card .brand { margin-bottom: 24px; }
.login-card h1 { margin: 0 0 5px; font-size: 26px; }
.login-card > p { margin: 0 0 22px; color: var(--muted); }
.login-card .form-group { margin-bottom: 15px; }
.login-card .btn { width: 100%; min-height: 46px; margin-top: 8px; }
.alert { margin-bottom: 18px; padding: 11px 13px; border-radius: 9px; background: #fff0f0; color: #a42e2e; font-size: 13px; }

@media (max-width: 1180px) {
    .header-inner { grid-template-columns: auto minmax(260px, 420px); gap: 22px; }
    .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .shell { width: min(calc(100% - 28px), var(--shell)); }
    .header-inner { grid-template-columns: auto 1fr; min-height: 68px; }
    .top-nav { justify-content: flex-end; }
    .top-nav a:last-child { display: none; }
    .header-search { grid-column: 1 / -1; margin-bottom: 12px; }
    .site-header { position: relative; }
    .page-layout { display: block; padding-top: 20px; }
    .filter-toggle { width: 100%; min-height: 46px; display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 12px; background: white; color: #46526a; font-weight: 700; }
    .filter-toggle svg { width: 19px; }
    .filter-panel { position: fixed; inset: auto 12px 12px; z-index: 100; top: 12px; max-height: none; transform: translateY(110%); visibility: hidden; transition: .25s ease; box-shadow: 0 26px 80px rgba(8,16,40,.3); }
    .filter-panel.open { transform: translateY(0); visibility: visible; }
    .results-head { align-items: flex-start; }
    .preview-bar { grid-template-columns: auto minmax(0, 1fr) auto; }
    .preview-brand > span:last-child { display: none; }
    .preview-links { gap: 0; }
}
@media (max-width: 620px) {
    body { font-size: 14px; }
    .top-nav { display: none; }
    .header-inner { display: flex; flex-wrap: wrap; gap: 12px; padding-top: 12px; }
    .header-search { width: 100%; order: 2; }
    .results-head { display: block; }
    .quick-filters { margin-top: 22px; }
    .quick-filters label { flex: 1; }
    .quick-filters select { width: 100%; min-width: 0; }
    .template-grid { grid-template-columns: 1fr; }
    .template-shot { aspect-ratio: 16 / 9.6; }
    .preview-bar { grid-template-columns: auto minmax(0, 1fr) auto; height: 58px; padding-inline: 10px; gap: 9px; }
    .preview-stage { height: calc(100dvh - 58px); }
    .device-switch { display: none; }
    .preview-title { text-align: left; }
    .preview-close { width: 36px; height: 36px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-group.full { grid-column: auto; }
    .panel { padding: 18px; }
    .panel-head { align-items: flex-start; flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
