@font-face {
    font-family: "LXGWWenKai";
    src: url("./fonts/LXGWWenKai-Regular.ttf") format("truetype");
    font-display: swap;
}

@font-face {
    font-family: "LiSuLocal";
    src: url("./fonts/LiSu.ttf") format("truetype");
    font-display: swap;
}

@font-face {
    font-family: "XinDiXiaoWanZi";
    src: url("./fonts/新蒂小丸子小学版.ttf") format("truetype");
    font-display: swap;
}

@font-face {
    font-family: "HongLeiBanShu";
    src: url("./fonts/鸿雷板书简体.ttf") format("truetype");
    font-display: swap;
}

:root {
    --ink: #24231f;
    --muted: #716a5e;
    --paper: #f7f1e7;
    --panel: #fffaf0;
    --line: #ded1bd;
    --red: #b91f31;
    --red-deep: #861525;
    --gold: #c99a32;
    --jade: #2d6a4f;
    --blue: #2d5f85;
    --shadow: 0 18px 45px rgba(43, 30, 18, 0.13);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-width: 320px;
    color: var(--ink);
    font-family: "LXGWWenKai", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
    background:
        linear-gradient(90deg, rgba(36, 35, 31, 0.035) 1px, transparent 1px),
        linear-gradient(0deg, rgba(36, 35, 31, 0.035) 1px, transparent 1px),
        var(--paper);
    background-size: 22px 22px;
}

body.designer-page {
    height: 100%;
    overflow: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

button {
    border: 0;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body.designer-page .app-shell {
    height: 100dvh;
    min-height: 0;
}

.topbar {
    min-height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 22px;
    border-bottom: 1px solid rgba(36, 35, 31, 0.14);
    background: rgba(255, 250, 240, 0.9);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
}

.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: #fffaf0;
    background: var(--red);
    border: 2px solid var(--red-deep);
    border-radius: 8px;
    font-family: "LiSuLocal", "LXGWWenKai", serif;
    font-size: 30px;
    line-height: 1;
    box-shadow: 5px 5px 0 rgba(201, 154, 50, 0.35);
}

.brand h1 {
    margin: 0;
    font-family: "LiSuLocal", "LXGWWenKai", serif;
    font-size: clamp(28px, 3vw, 40px);
    font-weight: 500;
    line-height: 1;
}

.active-label {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.canvas-info {
    min-width: 112px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--blue);
    background: #fffdfa;
    text-align: center;
    font-weight: 700;
}

.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(330px, 410px) minmax(0, 1fr);
    overflow: hidden;
    gap: 18px;
    padding: 18px;
    min-height: 0;
}

.use-workspace {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 18px;
    padding: 18px;
    min-height: 0;
}

.use-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: calc(100vh - 110px);
    overflow: auto;
    padding-right: 2px;
}

.ghost-link {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid rgba(45, 95, 133, 0.2);
    border-radius: 7px;
    color: var(--blue);
    background: #fffdfa;
    text-decoration: none;
}

.ghost-link:hover {
    color: #fffaf0;
    background: var(--blue);
    border-color: var(--blue);
}

.muted-note {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

.field-panel {
    display: grid;
    gap: 10px;
    min-height: 52px;
}

.user-field {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdfa;
}

.use-field-label {
    display: block;
    margin-bottom: 5px;
    color: var(--ink);
    font-size: 12px;
}

.data-preview {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.preview-row {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 1px solid rgba(45, 95, 133, 0.16);
    border-radius: 8px;
    background: #f8fbfd;
    color: var(--ink);
    font-size: 12px;
    line-height: 1.6;
}

.preview-row span {
    word-break: break-word;
}

.control-panel {
    height: 100%;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    max-height: none;
    min-height: 0;
    overflow: hidden;
}

.control-panel-tabs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
}

.control-panel-tab {
    min-height: 34px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    background: #fffdfa;
    font-size: 12px;
    cursor: pointer;
}

.control-panel-tab.is-active {
    border-color: var(--red);
    color: #fffaf0;
    background: var(--red);
}

.control-panel-view-select {
    display: none;
}

.control-panel-views {
    min-height: 0;
    overflow: auto;
    padding-right: 2px;
}

.control-panel-view {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.control-panel-view[hidden] {
    display: none;
}

.panel-section {
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 250, 240, 0.94);
    box-shadow: 0 8px 20px rgba(43, 30, 18, 0.06);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.section-title h2 {
    margin: 0;
    color: var(--red-deep);
    font-size: 18px;
    font-weight: 800;
}

.inline-title {
    align-items: center;
}

.resolution-grid {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 8px;
    align-items: end;
}

label span,
.field-label {
    display: block;
    margin-bottom: 5px;
    color: var(--ink);
    font-size: 12px;
}

.file-button span,
.mini-file-button span {
    color: #fffaf0;
}

.publish-help {
    margin: -4px 0 12px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.55;
}

input[type="number"],
input[type="text"],
select,
textarea {
    width: 100%;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 7px 9px;
    color: var(--ink);
    background: #fffdfa;
    outline: none;
}

textarea {
    resize: vertical;
    min-height: 68px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 154, 50, 0.18);
}

input[type="color"] {
    width: 44px;
    height: 36px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fffdfa;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--red);
}

.tool-button,
.ghost-button,
.primary-button,
.wide-button,
.file-button,
.mini-file-button {
    min-height: 36px;
    border-radius: 7px;
    padding: 8px 12px;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.tool-button,
.wide-button,
.file-button,
.mini-file-button {
    color: #fffaf0;
    background: var(--ink);
}

.tool-button:hover,
.wide-button:hover,
.file-button:hover,
.mini-file-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 15px rgba(36, 35, 31, 0.18);
}

.primary-button {
    min-width: 118px;
    color: #fffaf0;
    background: var(--red);
    box-shadow: 0 8px 20px rgba(185, 31, 49, 0.22);
}

.primary-button:hover {
    transform: translateY(-1px);
    background: var(--red-deep);
}

.ghost-button {
    color: var(--red-deep);
    background: #fff5ef;
    border: 1px solid rgba(185, 31, 49, 0.25);
}

.wide-button {
    width: 100%;
    margin-top: 9px;
    background: var(--jade);
}

.preset-tools,
.field-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-top: 9px;
    align-items: end;
}

.preset-tools:has(.ghost-button) {
    grid-template-columns: minmax(0, 1fr) auto auto;
}

.field-row {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
}

.file-button,
.mini-file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.file-button {
    width: 100%;
    margin-top: 10px;
    background: var(--blue);
}

.compact-file-button {
    margin-top: 0;
}

.template-publish-tools {
    display: flex;
    justify-content: flex-end;
    margin-top: 9px;
}

.publish-fields-panel {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.publish-field-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
    gap: 7px;
    align-items: end;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdfa;
}

.publish-field-row .toggle-label {
    min-height: 36px;
    align-items: center;
}

.publish-field-row input[type="text"] {
    min-height: 32px;
}

.publish-toggle {
    margin-top: 10px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdfa;
}

.xlsx-config-panel {
    display: grid;
    gap: 9px;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid rgba(45, 95, 133, 0.22);
    border-radius: 8px;
    background: #f8fbfd;
}

.xlsx-config-panel[hidden] {
    display: none;
}

.xlsx-config-panel .field-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    margin-top: 0;
}

.xlsx-config-panel textarea {
    min-height: 118px;
    font-family: Consolas, "Microsoft YaHei", monospace;
    font-size: 12px;
}

.storage-line {
    margin-top: 10px;
    padding-top: 9px;
    border-top: 1px dashed var(--line);
    color: var(--muted);
    font-size: 12px;
}

.mini-file-button {
    min-height: 32px;
    padding: 6px 10px;
    background: var(--jade);
}

.file-button input,
.mini-file-button input {
    display: none;
}

.resource-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 9px;
}

.asset-tools {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.resource-tile {
    position: relative;
    display: grid;
    grid-template-rows: 82px auto;
    gap: 7px;
    align-items: center;
    width: 100%;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fffdfa;
    cursor: pointer;
    text-align: center;
}

.resource-tile:hover {
    border-color: var(--gold);
    box-shadow: 0 8px 18px rgba(43, 30, 18, 0.1);
}

.resource-tile img {
    width: 100%;
    height: 82px;
    object-fit: contain;
}

.resource-tile span {
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.asset-delete-button {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    color: #fffaf0;
    background: var(--red);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.16s ease;
}

.resource-tile:hover .asset-delete-button {
    opacity: 1;
}

.text-section {
    padding-bottom: 10px;
}

.text-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.text-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #fffdfa;
}

.text-card.is-active {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 154, 50, 0.16);
}

.text-card-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.text-card-title {
    font-weight: 800;
    color: var(--red-deep);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--muted);
    font-size: 12px;
}

.icon-button {
    width: 31px;
    height: 31px;
    border-radius: 7px;
    color: var(--red-deep);
    background: #fff5ef;
    border: 1px solid rgba(185, 31, 49, 0.25);
    cursor: pointer;
}

.text-control-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) 76px 48px;
    gap: 8px;
    align-items: end;
    margin-top: 8px;
}

.text-curve-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    gap: 8px;
    align-items: end;
    min-width: 0;
    margin-top: 8px;
}

.text-curve-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
}

.text-curve-copy small {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}

.text-curve-inputs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 8px;
    align-items: center;
    min-width: 0;
}

.text-curve-inputs input {
    min-width: 0;
}

.fill-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    margin-top: 8px;
}

.fill-controls .full-row {
    grid-column: 1 / -1;
}

.text-card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

.text-card-actions .ghost-button,
.text-card-actions .tool-button {
    min-height: 31px;
    padding: 7px 10px;
    font-size: 12px;
}

.is-hidden {
    display: none !important;
}

.layer-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 52px;
}

.layer-row {
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr) auto auto;
    gap: 7px;
    align-items: center;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdfa;
}

.layer-row[draggable="true"] {
    cursor: grab;
}

.layer-row.is-active {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 154, 50, 0.14);
}

.layer-row.is-drag-over {
    border-color: var(--jade);
}

.layer-row.layer-hidden .layer-name {
    color: var(--muted);
    text-decoration: line-through;
}

.layer-row.layer-hidden .layer-grip {
    opacity: 0.45;
}

.layer-row.layer-locked {
    background: #fff7ed;
}

.layer-row.layer-locked .layer-grip {
    color: var(--red);
}

.layer-grip {
    color: var(--muted);
    font-weight: 800;
    text-align: center;
}

.layer-name {
    min-width: 0;
    height: 32px;
    min-height: 32px;
}

.layer-button {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    color: var(--ink);
    background: #fff5ef;
    border: 1px solid rgba(36, 35, 31, 0.12);
    cursor: pointer;
}

.layer-button.is-active {
    color: #fffaf0;
    background: var(--red);
}

.empty-panel-note {
    padding: 10px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--muted);
    text-align: center;
}

.stage-panel {
    min-width: 0;
    min-height: calc(100vh - 110px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    border: 1px solid rgba(36, 35, 31, 0.15);
    border-radius: var(--radius);
    background: #f4efe7;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.designer-workspace .stage-panel {
    height: 100%;
    min-height: 0;
}

.stage-toolbar {
    display: grid;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid rgba(36, 35, 31, 0.13);
    background: rgba(255, 250, 240, 0.92);
}

.stage-actions,
.align-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.icon-text-button,
.align-tools button {
    min-height: 30px;
    border-radius: 7px;
    padding: 6px 9px;
    color: var(--ink);
    background: #fffdfa;
    border: 1px solid var(--line);
    cursor: pointer;
}

.icon-text-button:disabled {
    opacity: 0.46;
    cursor: not-allowed;
}

.icon-text-button.is-active,
.align-tools button:hover,
.icon-text-button:hover:not(:disabled) {
    color: #fffaf0;
    background: var(--jade);
    border-color: var(--jade);
}

.zoom-label {
    min-width: 56px;
    padding: 6px 8px;
    border-radius: 7px;
    color: var(--blue);
    background: #fffdfa;
    border: 1px solid var(--line);
    text-align: center;
    font-weight: 800;
}

.canvas-viewport {
    width: 100%;
    height: 100%;
    min-height: calc(100vh - 112px);
    display: grid;
    place-items: center;
    padding: 14px;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
    background:
        linear-gradient(45deg, rgba(45, 106, 79, 0.06) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(45, 106, 79, 0.06) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(45, 106, 79, 0.06) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(45, 106, 79, 0.06) 75%),
        #ecf1ee;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    background-size: 20px 20px;
}

.designer-workspace .canvas-viewport {
    height: 100%;
    min-height: 0;
}

.canvas-viewport.is-panning {
    cursor: grabbing;
}

.canvas-container {
    position: relative;
    box-shadow: 0 22px 60px rgba(36, 35, 31, 0.28);
    background: #fff;
    border-radius: 6px;
    outline: 1px solid rgba(36, 35, 31, 0.18);
    transform-origin: center center;
    will-change: transform;
}

.canvas-container .lower-canvas {
    z-index: 0;
}

.canvas-container .upper-canvas {
    z-index: 5;
}

.canvas-container.is-fabric-object-transforming .upper-canvas {
    z-index: 10;
}

.html-table-layer {
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
    overflow: visible;
}

.html-table-interaction-layer {
    position: absolute;
    inset: 0;
    z-index: 8;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

.html-table-hit-area {
    position: absolute;
    z-index: 8;
    background: transparent;
    cursor: move;
    pointer-events: auto;
}

.html-table-hit-area.is-locked {
    cursor: default;
}

.html-table-component {
    position: absolute;
    z-index: 4;
    box-sizing: border-box;
    color: var(--table-body-text);
    font-family: var(--table-font-family);
    font-size: var(--table-font-size);
    line-height: 1.25;
}

.html-table-object-overlay,
.html-table-export-object-layer {
    position: absolute;
    inset: 0;
    z-index: 3;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.html-table-container {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    background: transparent;
    padding: var(--table-container-padding-top) var(--table-container-padding-right) var(--table-container-padding-bottom) var(--table-container-padding-left);
    border: var(--table-container-border-width) solid var(--table-container-border-color);
}

.html-table-container-background {
    position: absolute;
    inset: var(--table-frame-background-inset);
    z-index: 0;
    pointer-events: none;
    background: var(--table-container-background);
}

.html-table-frame-decoration {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.html-table-frame-layer {
    position: absolute;
    box-sizing: border-box;
    pointer-events: none;
}

.html-table-frame-layer-1 {
    inset: var(--table-frame-layer-1-inset);
    border: var(--table-frame-layer-1-width) solid var(--table-frame-layer-1-color);
}

.html-table-frame-layer-2 {
    inset: var(--table-frame-layer-2-inset);
    border: var(--table-frame-layer-2-width) solid var(--table-frame-layer-2-color);
}

.html-table-frame-layer-3 {
    inset: var(--table-frame-layer-3-inset);
    border: var(--table-frame-layer-3-width) solid var(--table-frame-layer-3-color);
}

.html-table-core {
    position: relative;
    z-index: 2;
    background: var(--table-container-background);
    overflow: hidden;
    clip-path: inset(0);
    border: var(--table-border-width) solid var(--table-border-color);
}

.html-table-header {
    height: var(--table-header-height);
    min-height: var(--table-header-height);
    color: var(--table-header-text);
    background: var(--table-header-fill);
    font-size: var(--table-header-font-size);
    font-weight: 800;
}

.html-table-body {
    position: relative;
    z-index: 1;
    overflow: hidden;
}

.html-table-row {
    position: relative;
    display: grid;
    grid-template-columns: var(--table-grid-template);
    z-index: 1;
}

.html-table-body-row {
    min-height: var(--table-row-height);
    color: var(--table-body-text);
    background: transparent;
}

.html-table-cell {
    min-width: 0;
    min-height: var(--table-row-height);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    border-right: var(--table-border-width) solid var(--table-border-color);
    border-bottom: var(--table-border-width) solid var(--table-border-color);
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.html-table-cell:last-child {
    border-right: 0;
}

.html-table-header-cell:not(:last-child) {
    border-right-color: var(--table-header-text);
}

.html-table-body-row:last-child .html-table-cell {
    border-bottom: 0;
}

.html-table-watermark {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 0;
    width: var(--table-watermark-width);
    aspect-ratio: 1 / 1;
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    opacity: var(--table-watermark-opacity);
    pointer-events: none;
    transform: translate(-50%, -50%) rotate(var(--table-watermark-rotation));
}

.html-table-selection-frame {
    position: absolute;
    border: 2px solid #2f6fed;
    outline: 1px solid rgba(255, 255, 255, 0.82);
    box-sizing: border-box;
    cursor: move;
    z-index: 9;
    pointer-events: auto;
}

.html-table-selection-frame.is-locked {
    border-style: dashed;
    border-color: #9a3412;
    cursor: default;
}

.html-table-resize-handle {
    position: absolute;
    top: 50%;
    right: -8px;
    width: 16px;
    height: 42px;
    padding: 0;
    border: 2px solid #2f6fed;
    border-radius: 999px;
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(47, 111, 237, 0.22);
    cursor: ew-resize;
    transform: translateY(-50%);
}

.table-config-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.table-config-list {
    display: grid;
    gap: 8px;
}

.table-config-row {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) minmax(70px, 0.8fr);
    gap: 8px;
    align-items: center;
}

.table-preview-tools {
    display: grid;
    gap: 8px;
    margin: 10px 0;
}

.preview-status {
    min-height: 28px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--muted);
    background: #fffaf0;
    font-size: 12px;
}

canvas {
    display: block;
}

textarea[data-fabric-hiddentextarea] {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 1px !important;
    height: 1px !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    resize: none !important;
}

.context-menu {
    position: fixed;
    z-index: 50;
    min-width: 190px;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdfa;
    box-shadow: 0 20px 45px rgba(36, 35, 31, 0.24);
}

.context-menu button {
    display: block;
    width: 100%;
    min-height: 32px;
    margin: 0;
    padding: 7px 9px;
    border-radius: 6px;
    color: var(--ink);
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.context-menu button:hover,
.context-menu button.is-active {
    color: #fffaf0;
    background: var(--red);
}

.context-menu .danger-menu-item {
    color: var(--red-deep);
}

.menu-control {
    display: grid;
    gap: 7px;
    margin: 6px 0;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff5ef;
}

.toast-host {
    position: fixed;
    right: 18px;
    top: 92px;
    z-index: 80;
    display: grid;
    gap: 8px;
}

.toast-message {
    max-width: min(320px, calc(100vw - 36px));
    padding: 10px 13px;
    border-radius: 8px;
    color: #fffaf0;
    background: var(--ink);
    box-shadow: 0 14px 30px rgba(36, 35, 31, 0.24);
    animation: toast-in 0.2s ease;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.template-library-view {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 28px clamp(18px, 4vw, 42px) 42px;
    background:
        linear-gradient(180deg, rgba(255, 250, 240, 0.94), rgba(247, 241, 231, 0.96)),
        var(--paper);
}

.template-library-inner {
    width: min(1180px, 100%);
    margin: 0 auto;
}

.template-library-toolbar {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.template-library-toolbar h2 {
    margin: 0;
    font-size: 28px;
    line-height: 1.15;
}

.template-library-toolbar p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.library-primary-button,
.library-secondary-button {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 9px 14px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.library-primary-button {
    color: #fff;
    background: linear-gradient(135deg, #d72d3e, #a9182a);
    box-shadow: 0 10px 22px rgba(185, 31, 49, 0.22);
}

.library-primary-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(185, 31, 49, 0.25);
}

.library-secondary-button {
    color: var(--ink);
    background: transparent;
}

.library-secondary-button:hover {
    background: rgba(36, 35, 31, 0.07);
}

.template-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
    gap: 18px;
    align-items: start;
}

.template-library-card {
    width: 100%;
    max-width: 228px;
    justify-self: center;
    border: 1px solid #e8ddcc;
    border-radius: 16px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 10px 24px rgba(43, 30, 18, 0.08);
    cursor: pointer;
    outline: none;
    animation: fadeInCard 0.24s ease both;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.template-library-card:hover,
.template-library-card:focus-visible {
    transform: translateY(-2px);
    border-color: rgba(185, 31, 49, 0.32);
    box-shadow: 0 18px 34px rgba(43, 30, 18, 0.13);
}

.template-card-head {
    min-height: 36px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.template-card-head h3 {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: #191814;
    font-size: 14px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-card-head span {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 11px;
}

.template-card-preview {
    position: relative;
    aspect-ratio: 210 / 297;
    overflow: hidden;
    border-radius: 12px;
    background: linear-gradient(135deg, #f5efe5, #e7ddce);
}

.template-paper-preview {
    position: absolute;
    inset: 14px 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(222, 209, 189, 0.86);
    border-radius: 6px;
    background: #fffdf8;
    box-shadow: 0 14px 28px rgba(36, 35, 31, 0.15);
}

.template-paper-preview span {
    width: 52px;
    height: 52px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--red-deep);
    background: #fff5ef;
    font-size: 18px;
    font-weight: 900;
}

.template-card-thumbnail {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 8px;
    background: #f8f1e8;
}

.template-card-float-actions {
    position: absolute;
    top: 9px;
    right: 9px;
    z-index: 2;
    display: flex;
    gap: 6px;
    opacity: 0;
    transform: translateY(-3px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.template-library-card:hover .template-card-float-actions,
.template-library-card:focus-within .template-card-float-actions {
    opacity: 1;
    transform: translateY(0);
}

.template-card-float-actions button,
.template-card-export button {
    min-height: 28px;
    border-radius: 999px;
    padding: 5px 8px;
    color: #2f2b25;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 8px 18px rgba(36, 35, 31, 0.14);
    cursor: pointer;
}

.template-card-float-actions button[data-template-action="delete"] {
    color: #c22135;
}

.template-card-export {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    z-index: 2;
    display: flex;
    justify-content: flex-end;
    padding: 28px 9px 9px;
    background: linear-gradient(180deg, transparent, rgba(36, 35, 31, 0.54));
}

.template-card-foot {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
}

.user-template-card-description {
    min-height: 2.8em;
    display: -webkit-box;
    margin: 8px 0 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.template-empty-state {
    width: min(560px, 100%);
    margin: 74px auto;
    padding: 28px 20px;
    text-align: center;
}

.empty-state-icon {
    width: 76px;
    height: 76px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--red);
    background: #fffaf0;
    box-shadow: var(--shadow);
    font-size: 42px;
    font-weight: 900;
}

.user-template-empty-state .empty-state-icon {
    font-size: 30px;
}

.template-empty-state h2 {
    margin: 18px 0 8px;
    font-size: 24px;
}

.template-empty-state p {
    max-width: 420px;
    margin: 0 auto 20px;
    color: var(--muted);
}

.library-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(36, 35, 31, 0.5);
}

.library-dialog {
    width: min(520px, 100%);
    overflow: hidden;
    border-radius: 16px;
    background: #fffdf8;
    box-shadow: 0 28px 70px rgba(36, 35, 31, 0.28);
    animation: scaleInDialog 0.18s ease both;
}

.library-dialog-header,
.library-dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 20px;
}

.library-dialog-header {
    border-bottom: 1px solid var(--line);
}

.library-dialog-header h2 {
    margin: 0;
    font-size: 18px;
}

.dialog-icon-button {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.dialog-icon-button:hover {
    background: rgba(36, 35, 31, 0.07);
    color: var(--ink);
}

.library-dialog-body {
    display: grid;
    gap: 18px;
    padding: 20px;
}

.library-field,
.library-check {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.library-field input {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--ink);
    background: #fff;
}

.library-check {
    grid-template-columns: auto 1fr;
    align-items: center;
    color: var(--ink);
}

.library-dialog-footer {
    justify-content: flex-end;
    border-top: 1px solid var(--line);
    background: #faf3e9;
}

.save-template-button {
    background: linear-gradient(135deg, #2d6a4f, #24543f);
}

@keyframes fadeInCard {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleInDialog {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@media (max-width: 980px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .use-workspace {
        grid-template-columns: 1fr;
    }

    .designer-workspace {
        overflow: auto;
        align-content: start;
    }

    .control-panel {
        height: min(52dvh, 520px);
        max-height: none;
        padding-right: 0;
    }

    .control-panel-views {
        overflow: auto;
        padding-right: 0;
    }

    .use-panel {
        max-height: none;
        padding-right: 0;
    }

    .stage-panel,
    .canvas-viewport {
        min-height: 58vh;
    }

    .designer-workspace .stage-panel {
        height: min(64dvh, 720px);
        min-height: 58vh;
    }

    .designer-workspace .canvas-viewport {
        min-height: 0;
    }
}

@media (max-width: 640px) {
    .user-template-library-view {
        padding: 20px 14px 28px;
    }

    .user-template-library-view .template-card-grid {
        grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
        gap: 12px;
    }

    .control-panel-tabs {
        display: none;
    }

    .control-panel-view-select {
        display: block;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .top-actions {
        width: 100%;
    }

    .primary-button {
        flex: 1;
    }

    .workspace {
        padding: 12px;
    }

    .resolution-grid,
    .preset-tools,
    .preset-tools:has(.ghost-button),
    .publish-field-row,
    .text-control-grid,
    .fill-controls {
        grid-template-columns: 1fr;
    }

    .field-row,
    .xlsx-config-panel .field-row {
        grid-template-columns: 1fr;
    }
}
