/* ===================== PDF 编辑器 ===================== */
/* 复刻 iLovePDF「编辑 PDF」的三栏工作台：顶栏 + 缩略图侧栏 + 画布 + 属性面板 */
/* 工具页默认占满整个电脑端屏幕（保留左侧导航），与工具箱规范一致 */
body.page-pdf-editor-full .app { max-width: 100%; }
body.page-pdf-editor-full .main-content { max-width: 100%; width: 100%; border-right: 0; }

.pe-app {
    /* 编辑器专用色板：中性工作台 + 站点强调色 */
    --pe-accent: #136ce9;
    --pe-accent-weak: rgba(19, 108, 233, .12);
    --pe-stage: #eceef1;
    --pe-sheet: #ffffff;
    --pe-bar: #ffffff;
    --pe-line: #e3e6ea;
    --pe-line-2: #eef0f3;
    --pe-ink: #1f2430;
    --pe-ink-2: #5b6472;
    --pe-ink-3: #8b95a5;
    --pe-ok: #12a150;
    --pe-warn: #e8a317;
    --pe-danger: #e0382f;
    --pe-radius: 10px;
    --pe-top-h: 54px;
    --pe-offset: 56px;   /* 站点顶栏实际高度，由 JS 测量回填 */

    position: relative;
    height: calc(100vh - var(--pe-offset));
    min-height: 480px;
    box-sizing: border-box;
    overflow: hidden;
    color: var(--pe-ink);
    background: var(--pe-stage);
    font-size: 14px;
}

@supports (height: 100dvh) {
    .pe-app { height: calc(100dvh - var(--pe-offset)); }
}

/* ★关键：[hidden] 必须能压过 display:flex，否则空状态与编辑器会互相叠着显示 */
.pe-editor[hidden],
.pe-loading[hidden],
.pe-empty[hidden] { display: none !important; }

[data-theme="dark"] .pe-app {
    --pe-stage: #171a20;
    --pe-sheet: #22262e;
    --pe-bar: #1c2027;
    --pe-line: #2f343d;
    --pe-line-2: #262a32;
    --pe-ink: #e6e9ef;
    --pe-ink-2: #a2abba;
    --pe-ink-3: #6f7887;
    --pe-accent: #4a97ff;
    --pe-accent-weak: rgba(74, 151, 255, .18);
}

.pe-app *,
.pe-app *::before,
.pe-app *::after { box-sizing: border-box; }

/* ===================== 通用控件 ===================== */
.pe-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent;
    font-size: 13.5px; font-weight: 500; font-family: inherit; line-height: 1;
    cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.pe-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.pe-btn-primary { background: var(--pe-accent); color: #fff; }
.pe-btn-primary:hover { filter: brightness(1.08); }
.pe-btn-ghost { background: var(--pe-bar); color: var(--pe-ink-2); border-color: var(--pe-line); }
.pe-btn-ghost:hover { background: var(--pe-accent-weak); color: var(--pe-accent); border-color: var(--pe-accent); }
.pe-btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.pe-btn-danger { background: var(--pe-danger); color: #fff; }
.pe-btn-danger:hover { filter: brightness(1.08); }

.pe-icbtn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; padding: 0; border-radius: 8px; cursor: pointer;
    background: transparent; border: 1px solid transparent; color: var(--pe-ink-2);
    transition: background .15s, color .15s;
}
.pe-icbtn svg { width: 17px; height: 17px; }
.pe-icbtn:hover:not(:disabled) { background: var(--pe-line-2); color: var(--pe-ink); }
.pe-icbtn:disabled { opacity: .35; cursor: not-allowed; }

.pe-input, .pe-select, .pe-textarea {
    width: 100%; height: 34px; padding: 0 10px; font-size: 13.5px; font-family: inherit;
    color: var(--pe-ink); background: var(--pe-bar);
    border: 1px solid var(--pe-line); border-radius: 8px; outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.pe-textarea { height: auto; min-height: 72px; padding: 8px 10px; line-height: 1.6; resize: vertical; }
.pe-input:focus, .pe-select:focus, .pe-textarea:focus {
    border-color: var(--pe-accent); box-shadow: 0 0 0 3px var(--pe-accent-weak);
}
.pe-select { appearance: none; padding-right: 26px; cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, var(--pe-ink-3) 50%),
                      linear-gradient(135deg, var(--pe-ink-3) 50%, transparent 50%);
    background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
    background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.pe-select-sm { height: 30px; font-size: 12.5px; width: auto; padding: 0 24px 0 8px;
    background-position: calc(100% - 13px) 13px, calc(100% - 8px) 13px; }

.pe-range { width: 100%; accent-color: var(--pe-accent); cursor: pointer; }
.pe-label { display: block; font-size: 12px; color: var(--pe-ink-2); margin-bottom: 5px; }
.pe-label b { color: var(--pe-ink); font-weight: 600; }
.pe-field { margin-bottom: 13px; }
.pe-chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--pe-ink-2); cursor: pointer; }
.pe-chk input { accent-color: var(--pe-accent); width: 15px; height: 15px; cursor: pointer; }
.pe-tip { font-size: 12.5px; color: var(--pe-ink-3); line-height: 1.65; margin: 0 0 10px; }
.pe-tip-warn { color: var(--pe-danger); }
.pe-row { display: flex; gap: 8px; align-items: center; }
.pe-row > * { min-width: 0; }
.pe-grow { flex: 1 1 auto; }

/* ★ 键盘可达性：统一焦点环（无障碍 / 更科学的可用体验） */
.pe-app .pe-btn:focus-visible,
.pe-app .pe-icbtn:focus-visible,
.pe-app .pe-tool:focus-visible,
.pe-app .pe-mini:focus-visible,
.pe-app .pe-ptab:focus-visible,
.pe-app .pe-thumb:focus-visible,
.pe-app .pe-segbtn:focus-visible,
.pe-app .pe-align button:focus-visible,
.pe-app .pe-list-item:focus-visible,
.pe-app .pe-zoom-label:focus-visible,
.pe-app .pe-color:focus-visible,
.pe-app .pe-panel-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--pe-accent-weak);
}
.pe-app .pe-btn-primary:focus-visible { box-shadow: 0 0 0 3px rgba(19, 108, 233, .4); }
.pe-app .pe-btn-danger:focus-visible { box-shadow: 0 0 0 3px rgba(224, 56, 47, .35); }
.pe-app .pe-tool.is-on:focus-visible,
.pe-app .pe-btn-xs.is-on:focus-visible,
.pe-app .pe-segbtn.is-on:focus-visible,
.pe-app .pe-align button.is-on:focus-visible {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, .5), 0 0 0 6px var(--pe-accent-weak);
}
/* 轻量按压反馈，强化可点击感知 */
.pe-app .pe-btn:active:not(:disabled),
.pe-app .pe-icbtn:active:not(:disabled),
.pe-app .pe-mini:active:not(:disabled) { transform: translateY(1px); }

.pe-color {
    width: 34px; height: 30px; padding: 2px; border: 1px solid var(--pe-line);
    border-radius: 7px; background: var(--pe-bar); cursor: pointer;
}
.pe-color::-webkit-color-swatch-wrapper { padding: 0; }
.pe-color::-webkit-color-swatch { border: none; border-radius: 4px; }

.pe-swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.pe-swatch {
    width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
    border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.pe-swatch.is-on { border-color: var(--pe-ink); }

.pe-emptyhint { padding: 26px 16px; text-align: center; color: var(--pe-ink-3); font-size: 13px; line-height: 1.8; }

/* ===================== 空状态 ===================== */
.pe-empty { position: absolute; inset: 0; overflow-y: auto; background: var(--pe-stage); }
.pe-empty-inner { max-width: 880px; margin: 0 auto; padding: 30px 20px 60px; }

.pe-hero {
    display: flex; gap: 18px; align-items: flex-start; padding: 24px;
    background: var(--pe-bar); border: 1px solid var(--pe-line);
    border-radius: 16px; box-shadow: 0 4px 20px rgba(0, 0, 0, .05);
}
.pe-hero-icon {
    flex: 0 0 auto; width: 58px; height: 58px; border-radius: 15px; display: flex;
    align-items: center; justify-content: center; color: #fff;
    background: linear-gradient(135deg, #2f8bff, #136ce9);
    box-shadow: 0 6px 18px rgba(19, 108, 233, .32);
}
.pe-hero-icon svg { width: 30px; height: 30px; }
.pe-hero-text { min-width: 0; flex: 1 1 auto; max-width: 600px; }
.pe-hero-text h1 { margin: 0 0 7px; font-size: 25px; font-weight: 700; letter-spacing: -.3px; }
.pe-hero-text p { margin: 0 0 12px; font-size: 14px; line-height: 1.75; color: var(--pe-ink-2); }
.pe-hero-text strong { color: var(--pe-ink); }
.pe-hero-tags { display: flex; flex-wrap: wrap; gap: 7px; }
.pe-tag {
    font-size: 12px; padding: 4px 10px; border-radius: 20px;
    background: var(--pe-accent-weak); color: var(--pe-accent); font-weight: 500;
}

.pe-drop {
    margin-top: 18px; padding: 54px 24px; text-align: center; cursor: pointer;
    background: var(--pe-bar); border: 2px dashed var(--pe-line); border-radius: 16px;
    transition: border-color .18s, background .18s, transform .18s;
}
.pe-drop:hover, .pe-drop:focus-visible { border-color: var(--pe-accent); background: var(--pe-accent-weak); outline: none; }
.pe-drop.is-over { border-color: var(--pe-accent); background: var(--pe-accent-weak); transform: scale(1.005); }
.pe-drop-icon { width: 52px; height: 52px; margin: 0 auto 14px; color: var(--pe-accent); }
.pe-drop-icon svg { width: 100%; height: 100%; }
.pe-drop-title { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.pe-drop-sub { font-size: 13.5px; color: var(--pe-ink-2); margin-bottom: 8px; }
.pe-drop-hint { font-size: 12.5px; color: var(--pe-ink-3); }

.pe-url { margin-top: 18px; padding: 18px 20px; background: var(--pe-bar);
    border: 1px solid var(--pe-line); border-radius: 14px; }
.pe-url-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.pe-url-row { display: flex; gap: 9px; }
.pe-url-note { margin: 8px 0 0; font-size: 12px; color: var(--pe-ink-3); }

.pe-help {
    margin-top: 18px; background: var(--pe-bar); border: 1px solid var(--pe-line);
    border-radius: 14px; padding: 14px 20px;
}
.pe-help summary { cursor: pointer; font-size: 14px; font-weight: 600; list-style: none;
    display: flex; align-items: center; gap: 8px; }
.pe-help summary::-webkit-details-marker { display: none; }
.pe-help summary::before {
    content: ''; width: 0; height: 0; border-left: 6px solid var(--pe-ink-3);
    border-top: 4.5px solid transparent; border-bottom: 4.5px solid transparent;
    transition: transform .2s;
}
.pe-help[open] summary::before { transform: rotate(90deg); }
.pe-help-body { padding-top: 14px; font-size: 13.5px; line-height: 1.85; color: var(--pe-ink-2); }
.pe-help-body h3 { margin: 16px 0 7px; font-size: 14px; color: var(--pe-ink); }
.pe-help-body h3:first-child { margin-top: 0; }
.pe-help-body ul { margin: 0 0 10px; padding-left: 20px; }
.pe-help-body li { margin-bottom: 5px; }
.pe-help-body p { margin: 0 0 10px; }

/* ===================== 加载中 ===================== */
.pe-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: var(--pe-stage); z-index: 60; }
.pe-loading-box { text-align: center; width: min(340px, 80vw); }
.pe-spinner {
    width: 40px; height: 40px; margin: 0 auto 16px; border-radius: 50%;
    border: 3px solid var(--pe-line); border-top-color: var(--pe-accent);
    animation: pe-spin .8s linear infinite;
}
@keyframes pe-spin { to { transform: rotate(360deg); } }
.pe-loading-text { font-size: 14px; color: var(--pe-ink-2); margin-bottom: 12px; }
.pe-progress { height: 5px; border-radius: 3px; background: var(--pe-line); overflow: hidden; }
.pe-progress-bar { height: 100%; width: 0; background: var(--pe-accent); transition: width .2s; }

/* ===================== 编辑器布局 ===================== */
.pe-editor { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--pe-stage); }

.pe-top {
    flex: 0 0 auto; height: 52px; display: flex; align-items: center; gap: 12px;
    padding: 0 12px; background: var(--pe-bar); border-bottom: 1px solid var(--pe-line);
    box-shadow: 0 1px 0 var(--pe-line), 0 2px 10px rgba(15, 20, 28, .04);
    position: relative; z-index: 30;
}
.pe-top-l { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 0; }
.pe-top-c { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.pe-top-r { display: flex; align-items: center; gap: 8px; flex: 1 1 0; justify-content: flex-end; }
.pe-file { min-width: 0; }
.pe-file-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.pe-file-meta { font-size: 11.5px; color: var(--pe-ink-3); white-space: nowrap; }

.pe-grp { display: flex; align-items: center; gap: 2px; padding: 2px;
    background: var(--pe-stage); border-radius: 9px; }
.pe-zoom { gap: 3px; }
.pe-zoom-label {
    min-width: 54px; height: 28px; padding: 0 6px; font-size: 12.5px; font-weight: 600;
    color: var(--pe-ink-2); background: transparent; border: 0; border-radius: 6px;
    cursor: pointer; font-family: inherit;
}
.pe-zoom-label:hover { background: var(--pe-bar); color: var(--pe-accent); }
.pe-btns svg { width: 15px; height: 15px; }

/* 窄屏专用的「属性面板」入口与浮层关闭条：桌面端隐藏 */
.pe-propsbtn, .pe-panel-close { display: none; }
.pe-side-head, .pe-props-tabs { position: relative; }
.pe-panel-close { position: absolute; right: 6px; top: 6px; z-index: 2; width: 26px; height: 26px; }
.pe-props-tabs { padding-right: 32px; }
.pe-props-tabs .pe-panel-close { top: 50%; margin-top: -13px; right: 4px; }
.pe-props-tabs .pe-ptab { min-width: 0; }

/* 三栏 */
.pe-body { flex: 1 1 auto; display: grid; grid-template-columns: 196px minmax(0, 1fr) 272px; min-height: 0; }
.pe-editor.no-side .pe-body { grid-template-columns: 0 minmax(0, 1fr) 272px; }
.pe-editor.no-side .pe-side { display: none; }
.pe-editor.no-props .pe-body { grid-template-columns: 196px minmax(0, 1fr) 0; }
.pe-editor.no-props .pe-props { display: none; }
.pe-editor.no-side.no-props .pe-body { grid-template-columns: 0 minmax(0, 1fr) 0; }

/* ===================== 左侧缩略图 ===================== */
.pe-side {
    display: flex; flex-direction: column; min-height: 0;
    background: var(--pe-bar); border-right: 1px solid var(--pe-line);
}
.pe-side-head { padding: 10px 10px 8px; border-bottom: 1px solid var(--pe-line-2); }
.pe-side-title { font-size: 12.5px; font-weight: 600; color: var(--pe-ink-2); display: block; margin-bottom: 8px; }
.pe-side-title b { color: var(--pe-accent); }
.pe-side-acts { display: flex; flex-wrap: wrap; gap: 4px; }
.pe-mini {
    height: 25px; padding: 0 8px; font-size: 11.5px; font-family: inherit; cursor: pointer;
    color: var(--pe-ink-2); background: var(--pe-stage);
    border: 1px solid var(--pe-line); border-radius: 6px; transition: .15s;
}
.pe-mini:hover:not(:disabled) { color: var(--pe-accent); border-color: var(--pe-accent); }
.pe-mini:disabled { opacity: .4; cursor: not-allowed; }
.pe-mini-danger:hover:not(:disabled) { color: var(--pe-danger); border-color: var(--pe-danger); }

.pe-thumbs { flex: 1 1 auto; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 9px; }
.pe-thumb {
    position: relative; border: 2px solid var(--pe-line); border-radius: 8px; overflow: hidden;
    cursor: pointer; background: #fff; transition: border-color .15s, box-shadow .15s;
}
.pe-thumb:hover { border-color: var(--pe-accent); }
.pe-thumb.is-sel { border-color: var(--pe-accent); box-shadow: 0 0 0 2px var(--pe-accent-weak); }
.pe-thumb.is-cur::after {
    content: ''; position: absolute; inset: 0; border: 2px solid var(--pe-accent);
    border-radius: 6px; pointer-events: none;
}
.pe-thumb.is-drag { opacity: .4; }
.pe-thumb.is-over { border-color: var(--pe-ok); box-shadow: 0 -3px 0 var(--pe-ok) inset; }
.pe-thumb canvas, .pe-thumb-img { display: block; width: 100%; height: auto; background: #fff; }
.pe-thumb-ph { aspect-ratio: 1 / 1.414; display: flex; align-items: center; justify-content: center;
    color: #b6bcc6; font-size: 22px; }
.pe-thumb-no {
    position: absolute; left: 4px; top: 4px; min-width: 20px; height: 20px; padding: 0 5px;
    display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600;
    color: #fff; background: rgba(31, 36, 48, .78); border-radius: 5px;
}
.pe-thumb-rot {
    position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 5px;
    display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
    color: #fff; background: rgba(19, 108, 233, .9);
}
.pe-thumb-acts {
    position: absolute; right: 4px; bottom: 4px; display: flex; gap: 3px;
    opacity: 0; transition: opacity .15s;
}
.pe-thumb:hover .pe-thumb-acts, .pe-thumb.is-sel .pe-thumb-acts { opacity: 1; }
.pe-thumb-acts button {
    width: 24px; height: 24px; border: 0; border-radius: 5px; cursor: pointer; font-size: 12px;
    color: #fff; background: rgba(31, 36, 48, .8); display: flex; align-items: center; justify-content: center;
}
.pe-thumb-acts button:hover { background: var(--pe-accent); }
.pe-thumb-acts button.del:hover { background: var(--pe-danger); }

/* ===================== 中间：工具栏 + 画布 ===================== */
.pe-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.pe-tools {
    flex: 0 0 auto; display: flex; align-items: center; gap: 3px; padding: 7px 10px;
    background: var(--pe-bar); border-bottom: 1px solid var(--pe-line);
    box-shadow: 0 1px 6px rgba(15, 20, 28, .035);
    overflow-x: auto; scrollbar-width: none;
}
.pe-tools::-webkit-scrollbar { display: none; }
.pe-tool {
    display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
    min-width: 52px; padding: 5px 7px; border: 1px solid transparent; border-radius: 8px;
    background: transparent; cursor: pointer; color: var(--pe-ink-2);
    font-size: 11px; font-family: inherit; white-space: nowrap; transition: .15s;
}
.pe-tool svg { width: 19px; height: 19px; }
.pe-tool:hover { background: var(--pe-line-2); color: var(--pe-ink); }
.pe-tool.is-on { background: var(--pe-accent); color: #fff; }
.pe-tool-danger:hover { color: var(--pe-danger); background: rgba(224, 56, 47, .1); }
.pe-tools-sep { width: 1px; height: 26px; background: var(--pe-line); margin: 0 4px; flex: 0 0 auto; }

.pe-stage { flex: 1 1 auto; overflow: auto; padding: 22px; scroll-behavior: smooth; }
.pe-pages { display: flex; flex-direction: column; align-items: center; gap: 22px; min-height: 100%; }

.pe-page {
    position: relative; flex: 0 0 auto; background: var(--pe-sheet);
    box-shadow: 0 3px 14px rgba(0, 0, 0, .16); border-radius: 2px;
}
.pe-page.is-active { box-shadow: 0 0 0 2px var(--pe-accent), 0 6px 20px rgba(0, 0, 0, .2); }
.pe-page canvas { display: block; border-radius: 2px; }
.pe-page-ph { display: flex; align-items: center; justify-content: center; color: var(--pe-ink-3); font-size: 13px; }
.pe-page-tag {
    position: absolute; left: 0; top: -19px; font-size: 11.5px; color: var(--pe-ink-3);
    display: flex; align-items: center; gap: 6px;
}
.pe-page-tag b { color: var(--pe-ink-2); font-weight: 600; }
.pe-page-badge {
    padding: 1px 6px; border-radius: 4px; font-size: 10.5px; font-weight: 600;
    background: var(--pe-accent-weak); color: var(--pe-accent);
}

/* 元素层 */
.pe-lyr { position: absolute; inset: 0; overflow: visible; }
.pe-lyr svg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.pe-el { position: absolute; transform-origin: center center; }
.pe-el-text {
    padding: 2px 3px; outline: none; white-space: pre-wrap; word-break: break-word;
    line-height: 1.35; cursor: move; user-select: none;
}
.pe-el-text[contenteditable="true"] { cursor: text; user-select: text; box-shadow: 0 0 0 2px var(--pe-accent); }
.pe-el-image { overflow: hidden; }
.pe-el-image img { width: 100%; height: 100%; display: block; object-fit: fill; pointer-events: none; }
.pe-el.is-sel-text { box-shadow: 0 0 0 1.5px var(--pe-accent); }

/* 选区与控制手柄 */
.pe-selbox { position: absolute; pointer-events: none; border: 1.5px solid var(--pe-accent); }
.pe-handle {
    position: absolute; width: 11px; height: 11px; margin: -6px 0 0 -6px; background: #fff;
    border: 1.5px solid var(--pe-accent); border-radius: 2px; pointer-events: auto;
}
.pe-handle.is-rot {
    width: 13px; height: 13px; margin-left: -6.5px; border-radius: 50%;
    background: var(--pe-accent); border-color: #fff; cursor: grab;
}
.pe-handle[data-h="nw"], .pe-handle[data-h="se"] { cursor: nwse-resize; }
.pe-handle[data-h="ne"], .pe-handle[data-h="sw"] { cursor: nesw-resize; }
.pe-handle[data-h="n"], .pe-handle[data-h="s"] { cursor: ns-resize; }
.pe-handle[data-h="e"], .pe-handle[data-h="w"] { cursor: ew-resize; }
.pe-cropline { position: absolute; pointer-events: none; border: 1.5px dashed var(--pe-warn); }
.pe-crophandle {
    position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; background: var(--pe-warn);
    border: 1.5px solid #fff; border-radius: 2px; pointer-events: auto;
}
.pe-crophandle[data-h="nw"], .pe-crophandle[data-h="se"] { cursor: nwse-resize; }
.pe-crophandle[data-h="ne"], .pe-crophandle[data-h="sw"] { cursor: nesw-resize; }
.pe-crophandle[data-h="n"], .pe-crophandle[data-h="s"] { cursor: ns-resize; }
.pe-crophandle[data-h="e"], .pe-crophandle[data-h="w"] { cursor: ew-resize; }

/* ===================== 右侧属性面板 ===================== */
.pe-props { display: flex; flex-direction: column; min-height: 0;
    background: var(--pe-bar); border-left: 1px solid var(--pe-line); }
.pe-props-tabs { display: flex; flex: 0 0 auto; border-bottom: 1px solid var(--pe-line); }
.pe-ptab {
    flex: 1 1 0; height: 40px; border: 0; background: transparent; cursor: pointer;
    font-size: 13px; font-family: inherit; color: var(--pe-ink-3);
    border-bottom: 2px solid transparent; transition: .15s;
}
.pe-ptab:hover { color: var(--pe-ink); }
.pe-ptab.is-on { color: var(--pe-accent); border-bottom-color: var(--pe-accent); font-weight: 600; }
.pe-props-body { flex: 1 1 auto; overflow-y: auto; padding: 14px; }

.pe-sec { margin-bottom: 18px; }
.pe-sec:last-child { margin-bottom: 4px; }
.pe-sec-t {
    font-size: 11.5px; font-weight: 700; color: var(--pe-ink-3); text-transform: uppercase;
    letter-spacing: .6px; margin: 0 0 9px; padding-bottom: 6px; border-bottom: 1px solid var(--pe-line-2);
}
.pe-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pe-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pe-grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pe-btn-xs {
    height: 30px; padding: 0 8px; font-size: 12px; border-radius: 7px; cursor: pointer;
    border: 1px solid var(--pe-line); background: var(--pe-bar); color: var(--pe-ink-2);
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    font-family: inherit; transition: .15s;
}
.pe-btn-xs svg { width: 14px; height: 14px; }
.pe-btn-xs:hover { color: var(--pe-accent); border-color: var(--pe-accent); }
.pe-btn-xs.is-on { background: var(--pe-accent); color: #fff; border-color: var(--pe-accent); }
.pe-btn-xs:disabled { opacity: .4; cursor: not-allowed; }
.pe-btn-xs.is-danger { color: var(--pe-danger); }
.pe-btn-xs.is-danger:hover { background: var(--pe-danger); color: #fff; border-color: var(--pe-danger); }
.pe-btn-w { width: 100%; }

.pe-align { display: flex; gap: 3px; }
.pe-align button {
    flex: 1 1 0; height: 30px; border: 1px solid var(--pe-line); background: var(--pe-bar);
    cursor: pointer; border-radius: 7px; color: var(--pe-ink-2); display: flex;
    align-items: center; justify-content: center; font-size: 13px; transition: .15s;
}
.pe-align button:hover { border-color: var(--pe-accent); color: var(--pe-accent); }
.pe-align button.is-on { background: var(--pe-accent); border-color: var(--pe-accent); color: #fff; }

.pe-list { display: flex; flex-direction: column; gap: 5px; }
.pe-list-item {
    display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 8px;
    background: var(--pe-stage); border: 1px solid transparent; cursor: pointer; font-size: 12.5px;
}
.pe-list-item:hover { border-color: var(--pe-accent); }
.pe-list-item.is-on { border-color: var(--pe-accent); background: var(--pe-accent-weak); }
.pe-list-item .t { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pe-list-item .x { color: var(--pe-ink-3); font-size: 14px; }
.pe-list-item .x:hover { color: var(--pe-danger); }

/* ===================== 弹窗 ===================== */
.pe-mask {
    position: fixed; inset: 0; z-index: 120000; display: flex; align-items: center; justify-content: center;
    padding: 20px; background: rgba(15, 20, 28, .55); backdrop-filter: blur(3px);
}
.pe-mask[hidden] { display: none !important; }
.pe-modal {
    width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column;
    background: var(--pe-bar); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
    overflow: hidden;
}
.pe-modal-sm { max-width: 400px; }
.pe-modal-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 15px 18px; border-bottom: 1px solid var(--pe-line-2);
}
.pe-modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.pe-modal-body { padding: 18px; overflow-y: auto; }
.pe-modal-foot {
    display: flex; gap: 9px; justify-content: flex-end;
    padding: 13px 18px; border-top: 1px solid var(--pe-line-2);
}

.pe-signpad-wrap { position: relative; border: 1px dashed var(--pe-line); border-radius: 12px; overflow: hidden; }
.pe-signpad { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; background: #fff; }
.pe-sign-line {
    position: absolute; left: 8%; right: 8%; bottom: 26%; height: 1px;
    background: rgba(0, 0, 0, .18); pointer-events: none;
}
.pe-sign-line[hidden] { display: none; }
.pe-sign-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.pe-sign-btns { display: flex; gap: 8px; }

.pe-seg { display: flex; gap: 3px; padding: 3px; background: var(--pe-stage); border-radius: 9px; margin-bottom: 16px; }
.pe-segbtn {
    flex: 1 1 0; height: 32px; border: 0; border-radius: 7px; cursor: pointer;
    background: transparent; color: var(--pe-ink-2); font-size: 13px; font-family: inherit; transition: .15s;
}
.pe-segbtn.is-on { background: var(--pe-bar); color: var(--pe-accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

/* ===================== Toast ===================== */
.pe-toast {
    position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(14px);
    z-index: 200000; max-width: min(460px, 88vw); padding: 11px 18px; border-radius: 10px;
    background: rgba(28, 32, 39, .95); color: #fff; font-size: 13.5px; line-height: 1.5;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .3); opacity: 0; pointer-events: none;
    transition: opacity .22s, transform .22s; text-align: center;
}
.pe-toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }
.pe-toast.is-err { background: rgba(200, 44, 36, .96); }
.pe-toast.is-ok { background: rgba(16, 130, 70, .96); }

/* ===================== 响应式 ===================== */
/* 窄桌面：属性面板收窄 */
@media (max-width: 1400px) {
    .pe-body { grid-template-columns: 176px minmax(0, 1fr) 252px; }
    .pe-editor.no-side .pe-body { grid-template-columns: 0 minmax(0, 1fr) 252px; }
}
@media (max-width: 1200px) {
    .pe-body { grid-template-columns: 160px minmax(0, 1fr) 232px; }
    .pe-editor.no-side .pe-body { grid-template-columns: 0 minmax(0, 1fr) 232px; }
    .pe-file-name { max-width: 22vw; }
}

/* 平板 / 小屏：侧栏与属性面板改为浮层，默认收起（由 .side-open / .props-open 控制） */
@media (max-width: 991px) {
    .pe-app { min-height: 420px; }
    .pe-body { grid-template-columns: minmax(0, 1fr); position: relative; }
    .pe-editor.no-side .pe-body,
    .pe-editor.no-props .pe-body,
    .pe-editor.no-side.no-props .pe-body { grid-template-columns: minmax(0, 1fr); }

    .pe-side, .pe-props {
        position: absolute; top: 0; bottom: 0; z-index: 25; width: min(80vw, 300px);
        box-shadow: 0 0 28px rgba(0, 0, 0, .26);
        transition: transform .24s ease;
    }
    .pe-side { left: 0; transform: translateX(-102%); }
    .pe-props { right: 0; transform: translateX(102%); }
    .pe-editor.side-open .pe-side { transform: none; border-radius: 0 14px 14px 0; }
    .pe-editor.props-open .pe-props { transform: none; border-radius: 14px 0 0 14px; }
    /* 窄屏下 no-side 不再隐藏侧栏（它只是桌面端的「关掉侧栏」） */
    .pe-editor.no-side .pe-side { display: flex; }
    .pe-editor.no-props .pe-props { display: flex; }

    .pe-scrim {
        position: absolute; inset: 0; z-index: 24; background: rgba(15, 20, 28, .42);
        opacity: 0; pointer-events: none; transition: opacity .22s;
    }
    .pe-scrim.is-on { opacity: 1; pointer-events: auto; }
    /* 属性面板入口只在窄屏出现（桌面端常驻，无需按钮） */
    .pe-propsbtn { display: inline-flex; }
    /* 浮层里的关闭条 */
    .pe-panel-close { display: flex; }

    /* 平板顶栏换行时让右侧按钮簇保持内容宽度，把剩余空间让给文件名 */
    .pe-top { height: auto; min-height: 50px; flex-wrap: wrap; padding: 7px 10px; gap: 8px; }
    .pe-top-l { flex: 1 1 auto; min-width: 0; }
    .pe-top-r { flex: 0 0 auto; }
    .pe-top-c { order: 3; flex: 1 1 100%; justify-content: center; }
    .pe-tool { min-width: 50px; padding: 5px 6px; font-size: 11px; }
    .pe-file-name { max-width: 40vw; }
    .pe-stage { padding: 16px; }
    .pe-empty-inner { padding: 20px 14px 48px; }
    .pe-hero { flex-direction: column; gap: 12px; padding: 18px; }
    .pe-hero-text h1 { font-size: 22px; }
    .pe-url-row { flex-direction: column; }
    .pe-url-row .pe-btn { width: 100%; }
}

/* 桌面端：属性面板常驻，隐藏窄屏专用控件 */
@media (min-width: 992px) {
    .pe-propsbtn, .pe-panel-close { display: none !important; }
}

/* 手机 */
@media (max-width: 767px) {
    .pe-app { font-size: 13.5px; }
    .pe-top { padding: 6px 8px; gap: 6px; }
    .pe-btn { height: 32px; padding: 0 11px; font-size: 13px; }
    .pe-icbtn { width: 34px; height: 34px; }
    .pe-btns span { display: none; }
    .pe-btns { padding: 0 9px; }
    .pe-tool { min-width: 44px; padding: 6px 3px; font-size: 10px; }
    .pe-tool svg { width: 18px; height: 18px; }
    .pe-stage { padding: 12px; }
    .pe-pages { gap: 16px; }
    .pe-drop { padding: 38px 18px; }
    .pe-hero { padding: 16px; }
    .pe-hero-icon { width: 48px; height: 48px; border-radius: 13px; }
    .pe-hero-icon svg { width: 25px; height: 25px; }
    .pe-hero-text h1 { font-size: 20px; }
    .pe-hero-text p { font-size: 13px; }
    .pe-side, .pe-props { width: min(88vw, 320px); }
    .pe-thumbs, .pe-props-body { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
    .pe-modal { max-width: 100%; border-radius: 14px; }
    .pe-input, .pe-select, .pe-textarea { font-size: 16px; }  /* 防 iOS 聚焦缩放 */
    .pe-modal-foot .pe-btn { flex: 1 1 0; }
    .pe-props-body { padding: 13px; }
    /* 底部 Toast 避开全面屏底部安全区 */
    .pe-toast { bottom: calc(34px + env(safe-area-inset-bottom)); }
}

/* 超小屏：进一步压缩工具栏，保证单手可操作 */
@media (max-width: 380px) {
    .pe-hero-text h1 { font-size: 18px; }
    .pe-tool { min-width: 40px; font-size: 9.5px; }
    .pe-tool svg { width: 17px; height: 17px; }
}

@media print {
    .pe-app { display: none !important; }
}
