.designer-main [hidden],
.designer-main .tpl-panel[hidden] {
    display: none !important;
}

.designer-main {
    padding: 100px 0 60px;
    background: #f8fafc;
    min-height: 100vh;
}

.designer-header {
    margin-bottom: 1.5rem;
}

.designer-header h1 {
    font-size: 2rem;
    color: #2d3748;
    margin: 0 0 0.5rem;
}

.designer-lead {
    margin: 0;
    color: #4a5568;
    font-size: 1.05rem;
    line-height: 1.65;
}

.designer-faq {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid #e2e8f0;
}

.designer-faq h2 {
    font-size: 1.35rem;
    color: #2d3748;
    margin: 0 0 1.25rem;
}

.tpl-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
    margin: 1.5rem 0 1.25rem;
}

.tpl-tabs {
    display: inline-flex;
    padding: 4px;
    background: #e2e8f0;
    border-radius: 10px;
    gap: 4px;
}

.tpl-tab {
    appearance: none;
    border: 0;
    background: transparent;
    color: #4a5568;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.tpl-tab:hover {
    color: #1a202c;
}

.tpl-tab.is-active {
    background: #fff;
    color: #005AAC;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.tpl-tab-badge {
    min-width: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: #edf2f7;
    color: #4a5568;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.25rem;
    text-align: center;
}

.tpl-tab.is-active .tpl-tab-badge {
    background: #ebf4ff;
    color: #005AAC;
}

.tpl-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-left: auto;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.875rem;
    border-radius: 6px;
}

.btn-outline {
    background: #fff;
    color: #4a5568;
    border: 1px solid #cbd5e0;
}

.btn-outline:hover {
    border-color: #a0aec0;
    color: #1a202c;
    background: #fff;
    transform: none;
    box-shadow: none;
}

.tpl-meta {
    margin: 0 0 1rem;
    color: #718096;
    font-size: 0.9rem;
}

.std-layout {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}

.std-cat-aside {
    position: sticky;
    top: 88px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0.5rem;
}

.std-cat-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.std-cat-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: #4a5568;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    text-align: left;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 600;
}

.std-cat-btn:hover {
    background: #f7fafc;
    color: #1a202c;
}

.std-cat-btn.is-active {
    background: #ebf4ff;
    color: #005AAC;
}

.std-cat-count {
    min-width: 1.4rem;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: #718096;
    background: #edf2f7;
    border-radius: 999px;
    padding: 0.1rem 0.4rem;
}

.std-cat-btn.is-active .std-cat-count {
    background: #bee3f8;
    color: #005AAC;
}

.tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.tpl-card-meta {
    margin: 0;
    color: #718096;
    font-size: 0.8rem;
}

.tpl-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    min-height: 1.4rem;
}

.tpl-tag {
    font-size: 0.72rem;
    color: #4a5568;
    background: #edf2f7;
    border-radius: 999px;
    padding: 0.12rem 0.45rem;
}

.tpl-empty-inline {
    color: #718096;
    background: #fff;
    border: 1px dashed #cbd5e0;
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
}

@media (max-width: 900px) {
    .std-layout {
        grid-template-columns: 1fr;
    }

    .std-cat-aside {
        position: static;
    }

    .std-cat-nav {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .std-cat-btn {
        width: auto;
    }
}

.tpl-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100%;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tpl-card:hover {
    border-color: #90cdf4;
    box-shadow: 0 8px 24px rgba(0, 90, 172, 0.08);
}

.tpl-card-preview {
    position: relative;
    height: 200px;
    background:
        linear-gradient(45deg, #edf2f7 25%, transparent 25%),
        linear-gradient(-45deg, #edf2f7 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #edf2f7 75%),
        linear-gradient(-45deg, transparent 75%, #edf2f7 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-color: #f7fafc;
    border-bottom: 1px solid #e2e8f0;
    overflow: hidden;
}

.tpl-card-frame {
    position: absolute;
    top: 0;
    left: 0;
    border: 0;
    pointer-events: none;
    background: #fff;
    overflow: hidden;
    /* 宽高与缩放由 gallery.js 按模板尺寸等比填满预览区 */
}

.tpl-card-body {
    padding: 0.9rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 0.35rem;
}

.tpl-card-title {
    margin: 0;
    font-size: 1rem;
    color: #1a202c;
    line-height: 1.35;
}

.tpl-card-desc {
    margin: 0;
    color: #718096;
    font-size: 0.85rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.5em;
}

.tpl-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: auto;
    padding-top: 0.75rem;
}

.tpl-card-actions .btn {
    flex: 1 1 auto;
    text-align: center;
    min-width: 0;
}

.tpl-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    background: #fff;
    border: 1px dashed #cbd5e0;
    border-radius: 12px;
    color: #4a5568;
}

.tpl-empty h2 {
    margin: 0 0 0.5rem;
    font-size: 1.2rem;
    color: #2d3748;
    border: 0;
    padding: 0;
}

.tpl-empty p {
    margin: 0 0 1.25rem;
    color: #718096;
}

.tpl-empty-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.tpl-error {
    color: #c53030;
    background: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 8px;
    padding: 0.85rem 1rem;
}

/* —— 可视化设计器 —— */
/* 整页锁在视口内，左右栏各自滚动，不跟页面一起滚 */
html:has(body.editor-shell),
body.editor-shell {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.editor-shell {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: #dfe6ef;
    overflow: hidden;
    color: #1e293b;
}

.editor-shell .btn-ghost {
    background: transparent;
    color: #475569;
    border: 1px solid transparent;
    box-shadow: none;
    transform: none;
}

.editor-shell .btn-ghost:hover:not(:disabled) {
    background: #f1f5f9;
    color: #0f172a;
    border-color: transparent;
    box-shadow: none;
    transform: none;
}

.editor-shell .btn-ghost:disabled {
    opacity: 0.38;
}

.editor-topbar {
    position: relative;
    z-index: 30;
    flex: 0 0 auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.65rem 0.85rem;
    padding: 0.55rem 0.9rem;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
    overflow-x: auto;
}

.topbar-left {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    flex: 0 0 auto;
}

.topbar-divider {
    width: 1px;
    height: 1.35rem;
    background: #e2e8f0;
    flex: 0 0 auto;
}

.editor-name-inline {
    flex: 0 1 220px;
    min-width: 120px;
    max-width: 260px;
    padding: 0.4rem 0.7rem;
    border: 1px solid transparent;
    border-radius: 8px;
    background: #f8fafc;
    font-size: 0.92rem;
    font-weight: 650;
    color: #0f172a;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.editor-name-inline:hover {
    background: #f1f5f9;
}

.editor-name-inline:focus {
    outline: none;
    background: #fff;
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(0, 90, 172, 0.12);
}

.editor-zoom {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    padding: 0.1rem;
    border-radius: 8px;
    background: #f1f5f9;
    color: #475569;
    font-size: 0.78rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.editor-zoom #zoom-label {
    min-width: 2.6rem;
    text-align: center;
}

.editor-topbar-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.45rem 0.65rem;
    margin-left: auto;
    flex-shrink: 0;
}

.topbar-group {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    padding: 0.15rem;
    border-radius: 10px;
    background: #f8fafc;
}

.topbar-group-save {
    gap: 0.35rem;
    background: transparent;
    padding: 0;
}

.export-split {
    position: relative;
    display: inline-flex;
    align-items: stretch;
    vertical-align: middle;
}

.export-split-main {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    border-right-width: 0;
}

.export-split-caret {
    width: 1.65rem;
    min-width: 1.65rem;
    padding-left: 0;
    padding-right: 0;
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    justify-content: center;
}

.export-split-caret .fa-caret-down {
    font-size: 0.75rem;
    line-height: 1;
}

.export-split.is-open .export-split-main,
.export-split.is-open .export-split-caret {
    border-color: #316efe;
    color: #316efe;
}

/* fixed：顶栏 overflow-x:auto 会把 absolute 菜单裁进滚动条里 */
.export-split-menu {
    position: fixed;
    z-index: 13000;
    min-width: 10.5rem;
    padding: 0.3rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

.export-split-menu[hidden] {
    display: none !important;
}

.export-split-item {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0.45rem 0.65rem;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #1a202c;
    font: inherit;
    font-size: 0.8125rem;
    text-align: left;
    cursor: pointer;
}

.export-split-item:hover,
.export-split-item:focus-visible {
    background: #eff4ff;
    color: #1d4ed8;
    outline: none;
}

.topbar-group-icon .btn-icon {
    width: 2rem;
    min-width: 2rem;
    padding-left: 0;
    padding-right: 0;
    justify-content: center;
}

.topbar-group-print .btn,
.topbar-group-save .btn {
    white-space: nowrap;
}

.topbar-left #btn-back {
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    white-space: nowrap;
    font-weight: 600;
}

.designer-workspace {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 300px;
    min-height: 0;
    overflow: hidden;
}

.designer-center {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.designer-center > .designer-canvas-frame {
    flex: 1 1 auto;
    min-height: 0;
}

/* 画布下方操作说明：快捷键芯片 + 简短文案 */
.canvas-hints {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0.9rem;
    background: #f7f8fa;
    border-top: 1px solid #e8eaed;
    color: #64748b;
    font-size: 0.76rem;
    line-height: 1.35;
}

.canvas-hints[hidden] {
    display: none !important;
}

.canvas-hints-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.85rem;
    margin: 0;
    padding: 0;
    list-style: none;
    min-width: 0;
}

.canvas-hint {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.canvas-hint-keys {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.canvas-hint kbd,
.canvas-hint-plain {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.35rem;
    padding: 0 0.4rem;
    border-radius: 4px;
    border: 1px solid #b8c4d4;
    background: #fff;
    box-shadow: 0 1px 0 #c5d0de;
    color: #334155;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.canvas-hint-join {
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.7rem;
}

.canvas-hint-label {
    color: #64748b;
}

.canvas-hints-dismiss {
    flex: 0 0 auto;
    appearance: none;
    border: 0;
    background: transparent;
    color: #64748b;
    font: inherit;
    font-size: 0.75rem;
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    cursor: pointer;
}

.canvas-hints-dismiss:hover {
    background: rgba(15, 23, 42, 0.06);
    color: #334155;
}

.designer-palette,
.designer-props {
    background: #fbfcfe;
    border-right: 1px solid #e2e8f0;
    padding: 0.75rem 0.9rem 1.1rem;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.designer-props {
    border-right: 0;
    border-left: 1px solid #e2e8f0;
    background: #fff;
}

.designer-palette h2,
.designer-props h2,
.props-header h2 {
    margin: 0 0 0.35rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
    border: 0;
    padding: 0;
}

.palette-block {
    margin-bottom: 0.35rem;
}

.palette-fold {
    margin-top: 0.55rem;
    border: 1px solid #e8eef5;
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}

.palette-fold > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: #334155;
    background: #fff;
}

.palette-fold > summary::-webkit-details-marker {
    display: none;
}

.palette-fold > summary::after {
    content: '';
    width: 0.45rem;
    height: 0.45rem;
    border-right: 1.5px solid #94a3b8;
    border-bottom: 1.5px solid #94a3b8;
    transform: rotate(45deg);
    transition: transform 0.15s ease;
    flex: 0 0 auto;
}

.palette-fold[open] > summary::after {
    transform: rotate(-135deg);
    margin-top: 0.2rem;
}

.palette-fold > summary:hover {
    background: #f8fafc;
}

.palette-fold-body {
    padding: 0.45rem 0.85rem 0.75rem;
    border-top: 1px solid #f1f5f9;
}

/* 纸张等表单项：行距紧凑，不加分隔线 */
.palette-fold-body > .prop-field + .prop-field {
    margin-top: 0.35rem;
}

.palette-fold-body > .prop-field {
    gap: 0.12rem;
}

.palette-fold-body > .prop-field > span:first-child {
    font-size: 0.72rem;
    line-height: 1.2;
}

.palette-fold-body > .designer-palette-hint {
    margin-top: 0.35rem;
    margin-bottom: 0;
}

/* 页面脚本：CSS / JS 两大块之间再拉开并加分隔 */
.palette-fold-body.is-stacked > .prop-field + .prop-field {
    margin-top: 0.85rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f1f5f9;
}

.designer-palette-hint {
    margin: 0 0 0.55rem;
    color: #94a3b8;
    font-size: 0.75rem;
    line-height: 1.4;
}

.prop-field > .designer-palette-hint {
    margin: 0 0 0.35rem;
    font-size: 0.72rem;
}

.palette-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin-bottom: 0.15rem;
}

.palette-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    appearance: none;
    border: 1px solid #e8eef5;
    background: #fff;
    color: #334155;
    border-radius: 10px;
    padding: 0.6rem 0.35rem 0.5rem;
    margin: 0;
    cursor: grab;
    font-size: 0.78rem;
    font-weight: 650;
    text-align: center;
    line-height: 1.2;
    user-select: none;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.palette-item i {
    font-size: 1.05rem;
    color: #005AAC;
    opacity: 0.88;
}

.palette-item:hover {
    border-color: #bfdbfe;
    background: #f0f7ff;
    color: #005AAC;
    box-shadow: 0 4px 12px rgba(0, 90, 172, 0.08);
}

.palette-item:active,
.palette-item.is-dragging {
    cursor: grabbing;
    opacity: 0.75;
}

.designer-sheet.is-palette-dragover {
    outline: 2px dashed #316EFE;
    outline-offset: -2px;
}

.designer-canvas-frame {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-rows: 26px minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    background: #f3f5f8;
}

.ruler-corner {
    grid-column: 1;
    grid-row: 1;
    background: #f7f8fa;
    border-right: 1px solid #e8eaed;
    border-bottom: 1px solid #e8eaed;
    z-index: 3;
}

.ruler-h,
.ruler-v {
    display: block;
    background: #f7f8fa;
    z-index: 2;
}

.ruler-h {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    height: 26px;
    border-bottom: 1px solid #e8eaed;
}

.ruler-v {
    grid-column: 1;
    grid-row: 2;
    width: 40px;
    height: 100%;
    border-right: 1px solid #e8eaed;
}

.designer-canvas-wrap {
    grid-column: 2;
    grid-row: 2;
    overflow: auto;
    padding: 28px;
    /* 浅中性底 + 极淡网格，让白纸更突出，避免脏灰感 */
    background-color: #eef1f5;
    background-image:
        linear-gradient(rgba(148, 163, 184, 0.09) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.09) 1px, transparent 1px);
    background-size: 24px 24px;
    position: relative;
}

.designer-canvas-scaler {
    transform-origin: 0 0;
    width: max-content;
}

.designer-sheet {
    position: relative;
    background: #fff;
    box-shadow:
        0 0 0 1px rgba(15, 23, 42, 0.04),
        0 8px 24px rgba(15, 23, 42, 0.08);
    border-radius: 2px;
    outline: none;
    /* 编辑态允许手柄露出纸边；导出 HTML 仍带 overflow:hidden */
    overflow: visible;
}

.ds-guides {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 40;
    overflow: visible;
}

.ds-guide-x,
.ds-guide-y {
    position: absolute;
    background: #f43f5e;
    pointer-events: none;
}

.ds-guide-x {
    top: 0;
    bottom: 0;
    width: 1px;
    box-shadow: 0 0 0 0.5px rgba(244, 63, 94, 0.35);
}

.ds-guide-y {
    left: 0;
    right: 0;
    height: 1px;
    box-shadow: 0 0 0 0.5px rgba(244, 63, 94, 0.35);
}

.ruler-cursor-h,
.ruler-cursor-v {
    position: absolute;
    background: #316EFE;
    pointer-events: none;
    z-index: 4;
}

.ruler-cursor-h {
    top: 0;
    width: 1px;
    height: 20px;
}

.ruler-cursor-v {
    left: 0;
    width: 40px;
    height: 1px;
}

.ds-el {
    position: absolute;
    box-sizing: border-box;
    cursor: move;
    user-select: none;
    overflow: hidden;
}

/* 文本：中文正常连排；仅超长英文词超出框宽时再断开 */
.ds-el[data-kind="text"] {
    overflow-wrap: break-word;
    word-break: normal;
    min-width: 0;
}

.ds-el-face {
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    pointer-events: none;
}

.ds-el-face-circle {
    border-radius: 50%;
    overflow: hidden;
}

.ds-el img,
.ds-el svg {
    display: block;
    pointer-events: none;
    flex-shrink: 0;
}

/* 条码/二维码禁止 CSS 拉伸，否则改尺寸后模块比例失真扫不出 */
.ds-el svg {
    max-width: none;
    height: auto;
}

.ds-el img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ds-el table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    pointer-events: none;
}

.ds-el table th,
.ds-el table td {
    word-break: break-word;
}

.ds-el.is-selected {
    overflow: visible;
    z-index: 3;
}

/* 多选非主项：元素自身必须有选中环（!important 防止全局 CSS 盖掉） */
.ds-el.is-selected:not(.is-primary-selected) {
    outline: 2px solid #316EFE !important;
    outline-offset: 0 !important;
    box-shadow: 0 0 0 2px #316EFE !important;
}

.ds-selection {
    position: absolute;
    box-sizing: border-box;
    /* 用 box-shadow 画框，避免 outline 在 transform/缩放层下偶发不绘制 */
    box-shadow: 0 0 0 2px #316EFE;
    pointer-events: none;
    z-index: 50;
}

/* 多选副框：与主选中同色；无缩放/旋转手柄 */
.ds-selection-secondary {
    z-index: 49;
}

.ds-selection .ds-handle {
    pointer-events: auto;
}

.ds-el.is-selected.is-overflow {
    box-shadow: 0 0 0 2px #e53e3e;
}

/* 细线/极小元素：扩大可点选，但不常显描边（面单分割线很多时会像满屏虚框） */
.ds-el-tiny {
    z-index: 2;
    overflow: visible;
}

.ds-el-tiny:hover:not(.is-selected) {
    outline: 1px dotted rgba(49, 110, 254, 0.55);
    outline-offset: 2px;
}

.ds-hit-pad {
    position: absolute;
    left: -8px;
    top: -8px;
    right: -8px;
    bottom: -8px;
    pointer-events: auto;
}

.props-form [hidden],
.designer-props [hidden] {
    display: none !important;
}

.ds-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    box-sizing: border-box;
    background: #fff;
    border: 2px solid #316EFE;
    border-radius: 2px;
    z-index: 6;
    /* 画布缩小时由 JS 反缩放，保持屏幕上约 12px 可点 */
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9);
}

.ds-handle-nw { left: -6px; top: -6px; cursor: nwse-resize; transform-origin: 0 0; }
.ds-handle-ne { right: -6px; top: -6px; cursor: nesw-resize; transform-origin: 100% 0; }
.ds-handle-sw { left: -6px; bottom: -6px; cursor: nesw-resize; transform-origin: 0 100%; }
.ds-handle-se { right: -6px; bottom: -6px; cursor: nwse-resize; transform-origin: 100% 100%; }

/* 统一在选中框右上角外侧，避开 NE 缩放手柄 */
.ds-handle-rotate {
    left: auto;
    right: -5px;
    top: -18px;
    width: 9px;
    height: 9px;
    margin: 0;
    border-radius: 50%;
    cursor: grab;
    transform-origin: 100% 100%;
    background: #316EFE;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1px #316EFE;
    z-index: 7;
}

/* 短连接：旋转钮 → 右上角 */
.ds-handle-rotate::before {
    content: '';
    position: absolute;
    right: 2.5px;
    top: 100%;
    width: 1px;
    height: 6px;
    background: #316EFE;
    pointer-events: none;
}

/* 简易旋转箭头示意 */
.ds-handle-rotate::after {
    content: '';
    position: absolute;
    inset: 1px;
    border: 1px solid #fff;
    border-radius: 50%;
    border-right-color: transparent;
    pointer-events: none;
}

.ds-handle-rotate:active {
    cursor: grabbing;
}

.prop-field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    margin-bottom: 0.35rem;
    min-height: 1.75rem;
}

.prop-field-head > span:first-child {
    min-width: 0;
    padding-right: 0.25rem;
    font-weight: 650;
    color: #334155;
}

.prop-field-head .btn {
    flex-shrink: 0;
    margin-right: 0;
    padding: 0.25rem 0.55rem;
    font-size: 0.72rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
}

.prop-field-head .btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
}

#page-global-css,
#page-global-js {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
    line-height: 1.4;
    min-height: 10rem;
    max-height: 20rem;
    resize: vertical;
}

.code-editor-modal {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

.code-editor-modal[hidden] {
    display: none !important;
}

.code-editor-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.code-editor-panel {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: min(1100px, 100%);
    height: min(92vh, 900px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
    overflow: hidden;
}

.code-editor-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.code-editor-header h2 {
    margin: 0;
    font-size: 1rem;
    color: #1a202c;
    border: 0;
    padding: 0;
}

.code-editor-tabs {
    display: flex;
    gap: 0.35rem;
    margin-right: auto;
}

.code-editor-tabs .btn.is-active {
    background: #316EFE;
    border-color: #316EFE;
    color: #fff;
}

.code-editor-actions {
    display: flex;
    gap: 0.4rem;
}

.code-editor-body {
    flex: 1;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 1rem 1.1rem;
    border: 0;
    resize: none;
    box-sizing: border-box;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #0f172a;
    background: #fff;
}

.code-editor-body:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px rgba(49, 110, 254, 0.35);
}

.code-editor-foot {
    margin: 0;
    padding: 0.55rem 1rem;
    font-size: 0.78rem;
    color: #64748b;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

.table-editor {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.55rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
}

.table-editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.table-editor-toolbar .table-section-title {
    margin: 0;
}

.table-editor-modal {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

.table-editor-modal[hidden] {
    display: none !important;
}

.table-editor-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.table-editor-modal-panel {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: min(1200px, 100%);
    height: min(92vh, 900px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
    overflow: hidden;
}

.table-editor-modal-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.table-editor-modal-header h2 {
    margin: 0;
    margin-right: auto;
    font-size: 1rem;
    color: #1a202c;
    border: 0;
    padding: 0;
}

.table-editor-modal-actions {
    display: flex;
    gap: 0.4rem;
}

.table-editor-modal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
    overflow-x: hidden;
    overflow-y: auto; /* 下方属性过多时整块可滚 */
}

.table-editor-modal-body .table-editor {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    flex: 1 0 auto;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 0;
}

.table-editor-modal-body .table-editor-toolbar,
.table-editor-modal-body .table-sel-status,
.table-editor-modal-body .table-editor-hint,
.table-editor-modal-body .table-selection-props,
.table-editor-modal-body .table-opts-details {
    flex: 0 0 auto;
}

.table-editor-modal-body .table-editor-toolbar #btn-expand-table {
    display: none;
}

/* 固定可视高度，避免被下方属性区挤没；格子多时在此区域内滚动 */
.table-editor-modal-body .table-editor-scroll {
    flex: 0 0 auto;
    height: min(52vh, 480px);
    min-height: 240px;
    max-height: none !important;
    overflow: auto !important;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    background: #fff;
    -webkit-overflow-scrolling: touch;
}

.table-editor-modal-body .table-editor-grid {
    font-size: 0.9rem;
}

.table-editor-modal-body .table-editor-grid input {
    font-size: 0.9rem;
    padding: 0.5rem 0.55rem;
}

.table-editor-modal-foot {
    margin: 0;
    padding: 0.55rem 1rem 0.75rem;
    border-top: 1px solid #e2e8f0;
    font-size: 0.78rem;
    color: #64748b;
    background: #f8fafc;
}

.table-section-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 0.1rem;
}

.table-section-sub {
    grid-column: 1 / -1;
    font-size: 0.72rem;
    font-weight: 600;
    color: #475569;
    margin: 0.1rem 0 0;
}

.table-sel-status {
    margin: 0;
    padding: 0.35rem 0.45rem;
    border-radius: 6px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 0.72rem;
    line-height: 1.35;
}

.table-ctx-menu {
    position: fixed;
    z-index: 13000;
    min-width: 11.5rem;
    padding: 0.3rem;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

.table-ctx-item {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 0.42rem 0.55rem;
    border-radius: 7px;
    font-size: 0.8rem;
    color: #0f172a;
    cursor: pointer;
}

.table-ctx-item:hover:not(:disabled) {
    background: #eff6ff;
    color: #1d4ed8;
}

.table-ctx-item:disabled {
    color: #94a3b8;
    cursor: not-allowed;
}

.table-ctx-sep {
    height: 1px;
    margin: 0.25rem 0.35rem;
    background: #e2e8f0;
}

.table-opts,
.table-col-props,
.table-cell-props {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    padding: 0.45rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
}

.table-selection-props {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.table-col-props.is-disabled,
.table-cell-props.is-disabled,
#wrap-table-zebra-color.is-disabled {
    opacity: 0.55;
}

.table-opts-details {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    padding: 0.25rem 0.45rem 0.45rem;
}

.table-opts-details > summary {
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 700;
    color: #334155;
    padding: 0.35rem 0.1rem;
    list-style: none;
}

.table-opts-details > summary::-webkit-details-marker {
    display: none;
}

.table-opts-details > summary::before {
    content: '▸ ';
    color: #64748b;
}

.table-opts-details[open] > summary::before {
    content: '▾ ';
}

.table-opts-details .table-opts {
    margin-top: 0.35rem;
    border: 0;
    padding: 0;
}

.table-opts .prop-full,
.table-cell-props .prop-check {
    grid-column: 1 / -1;
}

.table-editor-scroll {
    max-height: 240px;
    overflow: auto;
    overflow-x: auto;
    overflow-y: auto;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    background: #fff;
    -webkit-overflow-scrolling: touch;
}

.table-editor-grid {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.78rem;
}

.table-editor-grid th,
.table-editor-grid td {
    border: 1px solid #e2e8f0;
    padding: 0;
    vertical-align: middle;
    min-width: 48px;
}

.table-editor-grid th {
    background: #f1f5f9;
    position: sticky;
    top: 0;
    z-index: 1;
}

.table-editor-grid th.is-header {
    position: sticky;
    top: 0;
    padding-right: 6px;
}

.table-editor-grid th.is-header input {
    padding-left: 14px;
    padding-right: 8px;
}

.table-editor-grid .table-col-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 4;
    touch-action: none;
}

.table-editor-grid .table-col-resizer:hover,
.table-editor-grid .table-col-resizer:active {
    background: rgba(49, 110, 254, 0.35);
}

.table-editor-grid .table-col-drag {
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 14px;
    border-radius: 2px;
    cursor: grab;
    background: repeating-linear-gradient(
        to bottom,
        #94a3b8 0 2px,
        transparent 2px 4px
    );
    opacity: 0.55;
    z-index: 3;
}

.table-editor-grid .table-col-drag:hover {
    opacity: 1;
}

body.is-table-col-resizing,
body.is-table-col-resizing * {
    cursor: col-resize !important;
    user-select: none !important;
}

.ds-el[data-kind="table"] th,
.ds-el[data-kind="table"] td {
    position: relative;
}

.ds-el[data-kind="table"] th.is-col-active {
    outline: 2px solid #316EFE;
    outline-offset: -2px;
}

.table-editor-grid .table-corner,
.table-editor-grid .table-row-head {
    min-width: 28px;
    width: 28px;
    text-align: center;
    font-size: 0.68rem;
    color: #64748b;
    background: #f1f5f9;
    cursor: pointer;
    user-select: none;
    position: sticky;
    left: 0;
    z-index: 2;
}

.table-editor-grid .table-corner {
    z-index: 3;
    cursor: default;
}

.table-editor-grid .table-row-head.is-row-active,
.table-editor-grid tr.is-row-active .table-row-head {
    background: #dbeafe;
    color: #1d4ed8;
}

.table-editor-grid input {
    width: 100%;
    box-sizing: border-box;
    border: 0;
    margin: 0;
    padding: 0.35rem 0.4rem;
    font-size: 0.78rem;
    background: transparent;
    color: #1a202c;
    border-radius: 0;
    min-width: 0;
}

.table-editor-grid input:focus {
    outline: 2px solid #316EFE;
    outline-offset: -2px;
    background: #eff6ff;
}

.table-editor-grid .is-header input {
    font-weight: 600;
}

.table-editor-grid th.is-col-active,
.table-editor-grid td.is-cell-active,
.table-editor-grid th.is-cell-active,
.table-editor-grid td.is-range,
.table-editor-grid th.is-range {
    outline: 2px solid #316EFE;
    outline-offset: -2px;
    /* 用内阴影标选中，不覆盖单元格自定义底色 */
    box-shadow: inset 0 0 0 999px rgba(49, 110, 254, 0.14);
}

/* 多选时选中态画在格子上，避免只有焦点格看起来被选中 */
.table-editor-grid td.is-range input:focus,
.table-editor-grid td.is-cell-active input:focus,
.table-editor-grid th.is-cell-active input:focus {
    outline: none;
    background: transparent;
}

/* 合并格靠 rowspan/colspan 跨格即可识别，不再加斜纹底色（易被当成脏背景） */

.table-editor-grid th.is-dragging {
    opacity: 0.55;
}

.table-editor-hint {
    margin: 0;
    font-size: 0.72rem;
    color: #718096;
    line-height: 1.35;
}

.ds-el[data-kind="table"] th.is-cell-active,
.ds-el[data-kind="table"] td.is-cell-active,
.ds-el[data-kind="table"] th.is-range,
.ds-el[data-kind="table"] td.is-range {
    outline: 2px solid #316EFE;
    outline-offset: -2px;
    background-color: rgba(49, 110, 254, 0.18) !important;
}

.ds-el[data-kind="table"] .is-canvas-editing {
    outline: 2px solid #316EFE;
    outline-offset: -2px;
    background: #fff !important;
    cursor: text;
    min-height: 1em;
}

.props-header {
    margin-bottom: 0.65rem;
}

.props-header h2 {
    margin-bottom: 0.25rem;
}

.props-empty,
.props-empty-card {
    margin: 0;
    color: #94a3b8;
    font-size: 0.82rem;
    line-height: 1.45;
}

.props-empty-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    text-align: center;
    padding: 1.75rem 0.85rem;
    border: 1px dashed #dbe3ee;
    border-radius: 12px;
    background: #f8fafc;
    min-height: 7.5rem;
}

.props-empty-card i {
    font-size: 1.25rem;
    color: #94a3b8;
}

.props-empty-card p {
    margin: 0;
    max-width: 12rem;
}

.props-multi {
    margin-bottom: 0.75rem;
}

.props-multi-count {
    margin: 0 0 0.55rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: #0f172a;
}

.align-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    margin: 0;
}

.align-toolbar .btn {
    width: 100%;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
    font-size: 0.75rem;
    border-radius: 8px;
}

.ds-marquee {
    position: absolute;
    box-sizing: border-box;
    border: 1px dashed #316EFE;
    background: rgba(49, 110, 254, 0.12);
    pointer-events: none;
    z-index: 40;
}


.props-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.45rem 0.5rem;
    align-items: end;
}

.prop-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin: 0;
    min-width: 0;
    font-size: 0.75rem;
    color: #4a5568;
}

.prop-field > span:first-child {
    line-height: 1.2;
    color: #64748b;
}

.prop-field input,
.prop-field select,
.prop-field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 0.38rem 0.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.84rem;
    color: #0f172a;
    background: #fff;
    min-width: 0;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.prop-field input:focus,
.prop-field select:focus,
.prop-field textarea:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(0, 90, 172, 0.12);
}

.prop-field input[type="color"] {
    padding: 0.12rem;
    height: 32px;
    cursor: pointer;
}

.prop-field input[type="number"] {
    font-variant-numeric: tabular-nums;
}

.prop-check {
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    min-height: 32px;
    padding-bottom: 0.15rem;
}

.prop-check input {
    width: auto;
    margin: 0;
}

.prop-full,
.props-actions {
    grid-column: 1 / -1;
}

.props-actions {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    margin-top: 0.35rem;
    padding-top: 0.75rem;
    border-top: 1px solid #e2e8f0;
}

.props-actions > .btn {
    width: 100%;
}

.props-layer-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
}

.props-layer-row .btn {
    width: 100%;
    padding-left: 0.4rem;
    padding-right: 0.4rem;
}

.editor-status {
    font-size: 0.78rem;
    color: #64748b;
    min-height: 1.15em;
    margin: 0;
}

.designer-toast {
    position: fixed;
    left: 50%;
    top: 18px;
    transform: translateX(-50%) translateY(-12px);
    z-index: 10000;
    max-width: min(92vw, 420px);
    padding: 0.7rem 1.1rem;
    border-radius: 10px;
    background: #166534;
    color: #fff;
    font-size: 0.92rem;
    line-height: 1.4;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.designer-toast[data-tone='err'] {
    background: #991b1b;
}

.designer-toast.is-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 1100px) {
    .designer-workspace {
        grid-template-columns: 180px minmax(0, 1fr) 260px;
    }
}

@media (max-width: 900px) {
    .designer-workspace {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(120px, 22vh) minmax(0, 1fr) minmax(140px, 26vh);
        grid-template-areas:
            "palette"
            "center"
            "props";
        overflow: hidden;
    }

    .designer-palette { grid-area: palette; }
    .designer-center { grid-area: center; min-height: 0; }
    .designer-props { grid-area: props; }

    .designer-palette,
    .designer-props {
        border: 0;
        border-bottom: 1px solid #e2e8f0;
        max-height: none;
        min-height: 0;
    }

    .designer-props {
        border-bottom: 0;
        border-top: 1px solid #e2e8f0;
    }

    .designer-canvas-wrap {
        min-height: 0;
        padding: 16px;
    }

    .topbar-left #btn-back span {
        display: none;
    }

    .canvas-hints {
        padding: 0.35rem 0.65rem;
    }

    .canvas-hints-list {
        gap: 0.3rem 0.55rem;
    }

    .tpl-toolbar-actions {
        margin-left: 0;
        width: 100%;
    }
}
