/* ============================================================================
 * 檔案名稱：css/editor.css（區塊編輯器專屬互動樣式）
 * 對應腳本：editor.js、tools/*.js
 * 載入順序：CSS 第 5 順位
 * ----------------------------------------------------------------------------
 * 【包含內容（僅編輯時需要的互動 UI）】
 *   1. 區塊編輯器紙張（.bk-page）、空白佔位提示（placeholder）、選取高亮與焦點外框
 *   2. 斜線快速插入選單（`/` Slash Menu）、文字反白浮動格式列、左側區塊拖曳把手（.bk-handle）與區塊操作選單
 *   3. 表格編輯互動（儲存格多選框、欄寬與列高拖曳線、快速加列加欄 `+` 按鈕）
 *   4. 圖片編輯互動（八向縮放控制點、比例裁切遮罩與格線、上傳進度佔位框）
 *   5. HTML 雙分頁編輯彈窗與 AI 提示詞精靈、程式碼語言選擇列、數學公式編輯彈窗與 LaTeX 符號面板
 *   6. 連結編輯浮動氣泡與站內搜尋選單、A4 頁面邊界導引虛線、PDF 匯出設定與分頁預覽彈窗
 * ============================================================================ */

/* 工作台區塊編輯器包裝容器 */
/* 區塊編輯器的紙張：寬度＝文章寬度＋左右內距，至少撐滿視口高度
   （外殼、視口、紙張底色見 common.css 的 .ed-shell / .ed-viewport / .ed-page） */
.bk-page {
    width: 100%;
    min-height: 100%;
    padding: var(--ed-page-padding, 48px 24px 96px);
}

.bk-page > .bk-editor-root {
    width: 100%;
    margin: 0 auto;
}

@media (max-width: 768px) {
    .bk-page {
        padding: var(--ed-page-padding-mobile, 24px 18px 64px);
    }
}

/* 編輯器根節點 */
.bk-editor-root {
    outline: none !important;
    min-height: 480px;
    cursor: text;
    position: relative;
}

/* 每個區塊直接子元素 */
.bk-editor-root > * {
    position: relative;
    border-radius: var(--ed-radius-sm, 6px);
    transition: background-color var(--ed-transition, 0.15s cubic-bezier(0.4, 0, 0.2, 1));
}

/* 佔位提示文字 (Placeholder) - 游標所在空區塊顯示 */
.bk-editor-root > [data-placeholder]:empty::before,
.bk-editor-root > [data-placeholder][data-empty="true"]::before {
    content: attr(data-placeholder);
    color: var(--ed-text-muted, #94a3b8);
    opacity: 0.65;
    pointer-events: none;
    user-select: none;
    position: absolute;
    left: 0;
    top: 0;
    font-weight: normal;
}

.bk-editor-root > blockquote[data-placeholder][data-empty="true"]::before {
    left: 1.1em;
}

/* 空的一般段落：只在游標所在那一行顯示提示（整篇只有一個空段落時也顯示） */
.bk-editor-root > p[data-empty="true"]:not(.is-current):not(:only-child)::before {
    content: none;
}

.bk-editor-root > ul > li[data-placeholder][data-empty="true"]::before,
.bk-editor-root > ol > li[data-placeholder][data-empty="true"]::before {
    content: attr(data-placeholder);
    color: var(--ed-text-muted, #94a3b8);
    opacity: 0.65;
    pointer-events: none;
    user-select: none;
    font-weight: normal;
}

/* 分隔線區塊在編輯時的視覺指示與選取感 */
.bk-editor-root > hr {
    cursor: pointer;
    padding: 4px 0;
}
.bk-editor-root > hr:hover {
    border-top-color: var(--ed-accent, #38bdf8);
}

/* ==========================================================================
   斜線指令選單 (Slash Menu)
   ========================================================================== */
.bk-slash-menu {
    position: fixed;
    z-index: 10000;
    width: 300px;
    max-height: 360px;
    overflow-y: auto;
    border-radius: var(--ed-radius-lg, 12px);
    background: var(--ed-panel-bg, #0f172a);
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.08));
    box-shadow: var(--ed-shadow-panel, 0 10px 30px rgba(0, 0, 0, 0.45));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 6px;
    box-sizing: border-box;
    display: none;
    flex-direction: column;
    gap: 2px;
    animation: bkFadeIn var(--ed-transition, 0.15s cubic-bezier(0.4, 0, 0.2, 1));
}

.bk-slash-group-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--ed-text-muted, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 6px 8px 3px;
    user-select: none;
}

.bk-slash-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: var(--ed-radius-md, 8px);
    cursor: pointer;
    user-select: none;
    transition: background-color var(--ed-transition, 0.15s cubic-bezier(0.4, 0, 0.2, 1));
    text-decoration: none;
    color: var(--ed-text, #e2e8f0);
}

.bk-slash-item:hover,
.bk-slash-item.is-selected {
    background: var(--ed-accent-soft, rgba(56, 189, 248, 0.15));
    color: #fff;
}

.bk-slash-icon {
    width: 30px;
    height: 30px;
    border-radius: var(--ed-radius-sm, 6px);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.08));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--ed-ui-font, 13px);
    color: var(--ed-accent, #38bdf8);
    flex-shrink: 0;
}

.bk-slash-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.bk-slash-label {
    font-size: 13.5px;
    font-weight: 500;
    color: inherit;
    line-height: 1.3;
}

.bk-slash-desc {
    font-size: 11.5px;
    color: var(--ed-text-muted, #94a3b8);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bk-slash-item.is-selected .bk-slash-desc {
    color: rgba(255, 255, 255, 0.7);
}

/* ==========================================================================
   選取浮動工具列 (Floating Selection Toolbar)
   採用與固定工具列完全一致的 .sn-tool-btn 與 .sn-divider 樣式
   ========================================================================== */
.bk-floating-toolbar {
    position: fixed;
    z-index: 10001;
    display: none;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    border-radius: var(--ed-radius-md, 8px);
    background: var(--ed-bar-bg, rgba(15, 23, 42, 0.96));
    border: 1px solid var(--ed-border-strong, rgba(56, 189, 248, 0.35));
    box-shadow: var(--ed-shadow-panel, 0 10px 30px rgba(0, 0, 0, 0.45));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    animation: bkFadeIn var(--ed-transition, 0.15s cubic-bezier(0.4, 0, 0.2, 1));
    box-sizing: border-box;
}

@keyframes bkFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 下拉選單 (高度與按鈕尺寸一致 36px) */
.bk-tb-select {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.08));
    color: var(--ed-text, #e2e8f0);
    font-size: var(--ed-ui-font, 13px);
    height: var(--ed-btn-size, 36px);
    padding: 0 8px;
    border-radius: var(--ed-radius-md, 8px);
    outline: none;
    cursor: pointer;
    font-family: inherit;
}
.bk-tb-select option {
    background: var(--ed-panel-bg, #0f172a);
    color: var(--ed-text, #e2e8f0);
}

/* 浮動連結輸入條 */
.bk-tb-link-input-wrap {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
}
.bk-tb-link-input {
    background: var(--ed-border);
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.08));
    color: #fff;
    font-size: var(--ed-ui-font, 13px);
    height: var(--ed-btn-size, 36px);
    padding: 0 10px;
    border-radius: var(--ed-radius-md, 8px);
    outline: none;
    width: 180px;
    box-sizing: border-box;
}
.bk-tb-link-input:focus {
    border-color: var(--ed-accent, #38bdf8);
}


/* ==========================================================================
   編輯器共用工具列 (EditorToolbar) 補充樣式 (原 editor_common.css 併入)
   - 按鈕、群組、分隔線、彈出面板等基礎樣式沿用 canvas.css 的 .sn-toolbar / .sn-tool-btn
     （手繪筆記、PDF 標註、區塊編輯三種模式外觀一致）
   - 本區塊只放區塊編輯器工具列需要的補充規則
   ========================================================================== */


/* 文字類型下拉：寬度足以顯示「項目清單」 */
.ed-toolbar .ed-type-select {
    min-width: 96px !important;
    max-width: 140px !important;
}

/* 格式按鈕啟用中（例如游標在粗體字上） */
.ed-toolbar .sn-tool-btn.active {
    color: var(--ed-accent, #38bdf8) !important;
}


/* ==========================================================================
   區塊操作、左側標籤＋把手、拖曳與選單 (TASK-033)
   ========================================================================== */
.bk-editor-root {
    padding-left: 64px;
    --bk-tag-c: var(--ed-accent, #38bdf8);
    --bk-tag-bg: var(--ed-accent-soft, rgba(56, 189, 248, .15));
    --bk-tag-bd: var(--ed-border-strong, rgba(56, 189, 248, .35));
}

/* 舊 CSS 偽元素標籤由真實元素 .gut 取代 (TASK-033) */
.bk-editor-root > :is(p, h1, h2, h3, h4, h5, h6, blockquote, ul, ol, figure, .bk-table, .tb-block, .bk-image-block, .im-block, .hb-block, .cb, .mb, .pb, .lc)::after {
    display: none !important;
}

/* 程式碼與連結卡片區塊溢出處理：編輯器內保留可見標籤，圓角由內部元素處理 */
.bk-editor-root > .cb,
.bk-editor-root > .lc { overflow: visible; }
.bk-editor-root > .cb > .cb-head { border-radius: 9px 9px 0 0; }

.bk-editor-root > .lc.sel,
.bk-editor-root > .lc.is-selected {
    border-color: var(--ed-accent, #38bdf8);
    box-shadow: 0 0 0 2px var(--ed-accent, #38bdf8);
}

/* 區塊拖曳、高亮與動畫 */
.bk-editor-root > .picked {
    outline: 2px solid var(--ed-accent, #38bdf8) !important;
    outline-offset: 3px !important;
    border-radius: 4px;
}
.bk-editor-root > .dragging {
    opacity: .35 !important;
}
.bk-editor-root > .flash {
    animation: edBlockFlash .9s ease !important;
}
@keyframes edBlockFlash {
    0% { background: var(--ed-accent-soft, rgba(56, 189, 248, .18)); }
    100% { background: transparent; }
}

/* 左側：標籤＋拖曳把手（跟著滑鼠移過或游標所在區塊） */
.gut {
    position: absolute;
    display: none;
    align-items: center;
    gap: 2px;
    z-index: 50;
    height: 24px;
    user-select: none;
    pointer-events: auto;
}
.gut .lb {
    min-width: 30px;
    padding: 3px 6px;
    border-radius: var(--ed-radius-sm, 6px);
    /* .gut 掛在紙張上（不在 .bk-editor-root 內），變數取不到，直接寫統一藍色 */
    border: 1px solid var(--ed-border-strong, rgba(56, 189, 248, .35));
    background: var(--ed-accent-soft, rgba(56, 189, 248, .15));
    color: var(--ed-accent, #38bdf8);
    font: 600 11px/1 -apple-system, "PingFang TC", "Noto Sans TC", sans-serif;
    letter-spacing: .02em;
    text-align: center;
    white-space: nowrap;
    box-sizing: border-box;
}
.gut .grip {
    width: 20px;
    height: 24px;
    border: 0;
    border-radius: 5px;
    background: none;
    color: var(--ed-muted, #94a3b8);
    cursor: grab;
    font: 16px/24px sans-serif;
    letter-spacing: -3px;
    padding: 0 4px 0 2px;
    touch-action: none;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.gut .grip:hover {
    background: var(--ed-accent-soft, rgba(56, 189, 248, .15));
    color: var(--ed-accent, #38bdf8);
}
.gut .grip:active {
    cursor: grabbing;
}
.ed-shell.readonly .gut,
.preview .gut,
[contenteditable="false"] .gut {
    display: none !important;
}
@media (max-width: 700px) {
    .gut .lb {
        display: none !important;
    }
}

/* 拖曳放下標示線 */
.drop {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    box-shadow: 0 0 0 3px var(--ed-accent-soft, rgba(56, 189, 248, .15));
    display: none;
    z-index: 60;
    pointer-events: none;
}
.drop::before {
    content: "";
    position: absolute;
    left: -5px;
    top: -3.5px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ed-accent, #38bdf8);
}

/* 拖曳游標小卡片 */
.ghost {
    position: fixed;
    z-index: 9970;
    pointer-events: none;
    opacity: .85;
    background: var(--ed-page, #0f172a);
    color: var(--ed-text, #e2e8f0);
    border: 1px solid var(--ed-border-strong, rgba(56, 189, 248, .35));
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
    padding: 8px 12px;
    max-width: 420px;
    max-height: 120px;
    overflow: hidden;
    font-size: 14px;
    transform: rotate(1.5deg);
    box-sizing: border-box;
}
.ghost .gl {
    font-size: 11px;
    color: var(--ed-accent, #38bdf8);
    font-weight: 600;
    margin-bottom: 2px;
}
body.is-dragging,
body.is-dragging * {
    cursor: grabbing !important;
    user-select: none !important;
}

/* 區塊選單 */
.bm {
    position: fixed;
    z-index: 9960;
    width: 228px;
    background: var(--ed-panel, #0f172a);
    border: 1px solid var(--ed-border-strong, rgba(56, 189, 248, .35));
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
    display: none;
    color: var(--ed-text, #e2e8f0);
    font-size: 13.5px;
    box-sizing: border-box;
}
.bm .it {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: background 0.12s;
}
.bm .it:hover,
.bm .it.on {
    background: var(--ed-accent-soft, rgba(56, 189, 248, .15));
}
.bm .it .ic {
    width: 20px;
    text-align: center;
    color: var(--ed-muted, #94a3b8);
}
.bm .it .ic i { font-size: 13px; }
.bm .it.del .ic { color: inherit; }
.bm .it kbd {
    margin-left: auto;
    background: none;
    border: 0;
    color: var(--ed-muted, #94a3b8);
    font-size: 11.5px;
    padding: 0;
}
.bm .it.dis {
    opacity: .35;
    pointer-events: none;
}
.bm .it.del {
    color: var(--ed-danger, #fe5461);
}
.bm .sep {
    height: 1px;
    background: var(--ed-border, rgba(255, 255, 255, .08));
    margin: 5px 4px;
}
.bm .al {
    display: flex;
    gap: 4px;
    padding: 4px 8px 6px;
    align-items: center;
}
.bm .al span {
    color: var(--ed-muted, #94a3b8);
    font-size: 12px;
    margin-right: auto;
}
.bm .al button {
    width: 34px;
    height: 28px;
    border: 1px solid var(--ed-border, rgba(255, 255, 255, .08));
    border-radius: 6px;
    background: none;
    color: var(--ed-text, #e2e8f0);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.bm .al button.on {
    background: var(--ed-accent-soft, rgba(56, 189, 248, .15));
    border-color: var(--ed-border-strong, rgba(56, 189, 248, .35));
    color: var(--ed-accent, #38bdf8);
}

/* 浮動工具列對齊圖示 (ico) */
.ico {
    display: inline-block;
    width: 16px;
    height: 12px;
    vertical-align: middle;
    background:
        linear-gradient(currentColor, currentColor) 0 0/100% 2px no-repeat,
        linear-gradient(currentColor, currentColor) var(--x, 0) 50%/var(--w, 60%) 2px no-repeat,
        linear-gradient(currentColor, currentColor) 0 100%/100% 2px no-repeat;
}
.ico.l { --x: 0; --w: 60%; }
.ico.c { --x: 50%; --w: 60%; }
.ico.r { --x: 100%; --w: 60%; }

@media (max-width: 640px) {
    /* 手機只顯示拖曳把手（20px），留出空間避免蓋到文字 */
    .bk-editor-root { padding-left: 26px; }
    .bk-editor-root > :is(p, h1, h2, h3, h4, h5, h6, blockquote, ul, ol, figure, .bk-table, .tb-block, .bk-image-block, .im-block, .hb-block, .cb, .mb, .pb)::after {
        left: 0;
        top: -14px;
        transform: none;
        padding: 1px 5px;
        font-size: 10px;
    }
    .bk-editor-root > *:hover::after { opacity: 0; }
    .bk-editor-root > .is-current::after { opacity: 1; }
}

/* ==========================================================================
   表格區塊編輯器互動專屬樣式 (選取、把手、拖曳、快速插入)
   ========================================================================== */
.bk-tb td:focus, .bk-tb th:focus {
    box-shadow: inset 0 0 0 2px var(--ed-accent, #38bdf8);
}

.bk-tb .is-sel {
    background-image: linear-gradient(var(--ed-accent-soft, rgba(56, 189, 248, .2)), var(--ed-accent-soft, rgba(56, 189, 248, .2)));
    box-shadow: inset 0 0 0 1px var(--ed-border-strong, rgba(56, 189, 248, .55));
}

.bk-table-scroll.is-scrolled .is-sticky:focus {
    box-shadow: inset 0 0 0 2px var(--ed-accent, #38bdf8);
}

.bk-table.is-active .bk-table-scroll,
.bk-table-block.is-active .bk-table-scroll {
    border-color: var(--ed-border-strong, rgba(56, 189, 248, .55));
    box-shadow: 0 0 0 3px var(--ed-accent-soft, rgba(56, 189, 248, .2));
}

.bk-tb.rz-col, .bk-tb.rz-col * {
    cursor: col-resize !important;
}

.bk-tb.rz-row, .bk-tb.rz-row * {
    cursor: row-resize !important;
}

/* 拉寬 / 拉高把手：只有選到表格時出現 */
.tbx-rz {
    position: absolute;
    z-index: 2;
    display: none;
}

.bk-table.is-active .tbx-rz,
.tb-block.is-active .tbx-rz {
    display: block;
}

/* 表格四邊把手（置中細長條，全內置） */
.tbx-rz-r {
    top: 50%;
    transform: translateY(-50%);
    right: 0;
    width: 10px;
    height: 40px;
    cursor: ew-resize;
}

.tbx-rz-l {
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    width: 10px;
    height: 40px;
    cursor: ew-resize;
}

.tbx-rz-b {
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: 40px;
    height: 10px;
    cursor: ns-resize;
}

.tbx-rz-t {
    left: 50%;
    transform: translateX(-50%);
    top: 0;
    width: 40px;
    height: 10px;
    cursor: ns-resize;
}

/* 表格四角把手（全內置） */
.tbx-rz-tl {
    top: 0;
    left: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
}

.tbx-rz-tr {
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nesw-resize;
}

.tbx-rz-bl {
    bottom: 0;
    left: 0;
    width: 14px;
    height: 14px;
    cursor: nesw-resize;
}

.tbx-rz-br,
.tbx-rz-c {
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
}

.tbx-rz-r::after {
    content: "";
    position: absolute;
    right: 2px;
    top: 50%;
    width: 4px;
    height: 36px;
    margin-top: -18px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    opacity: .65;
}

.tbx-rz-l::after {
    content: "";
    position: absolute;
    left: 2px;
    top: 50%;
    width: 4px;
    height: 36px;
    margin-top: -18px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    opacity: .65;
}

.tbx-rz-b::after {
    content: "";
    position: absolute;
    bottom: 2px;
    left: 50%;
    height: 4px;
    width: 36px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    opacity: .65;
}

.tbx-rz-t::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 50%;
    height: 4px;
    width: 36px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    opacity: .65;
}

.tbx-rz-tl::after,
.tbx-rz-tr::after,
.tbx-rz-bl::after,
.tbx-rz-br::after,
.tbx-rz-c::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    opacity: .8;
}

.tbx-rz-tl::after {
    top: 3px;
    left: 3px;
}

.tbx-rz-tr::after {
    top: 3px;
    right: 3px;
}

.tbx-rz-bl::after {
    bottom: 3px;
    left: 3px;
}

.tbx-rz-br::after,
.tbx-rz-c::after {
    bottom: 3px;
    right: 3px;
}

.tbx-rz:hover::after {
    opacity: 1;
}

/* 快速插入按鈕與導引線 */
.tbx-plus {
    position: fixed;
    z-index: 140;
    display: none;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border-radius: 50%;
    border: 0;
    background: var(--ed-accent);
    color: #0b1220;
    font-size: 15px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
    padding: 0;
    outline: none;
}

.tbx-plus.show {
    display: block;
}

.tbx-guide {
    position: fixed;
    z-index: 139;
    display: none;
    background: var(--ed-accent);
    pointer-events: none;
    border-radius: 1px;
}

.tbx-guide.show {
    display: block;
}

body.is-resizing, body.is-resizing * {
    user-select: none !important;
}

/* ==========================================================================
   圖片區塊編輯器介面 (Image Block Editor Interface)
   ========================================================================== */
.bk-image-block, .im-block {
    position: relative;
    user-select: none;
    margin: 20px 0 24px;
}

.bk-image-block.is-active .bk-image-frame,
.im-block.is-active .im-frame {
    outline: 2px solid var(--ed-accent, #38bdf8);
    outline-offset: 2px;
}

.im-wrapfig {
    position: relative;
}

/* 調整寬高把手 (TASK-025：四角＋右下邊把手，全部內置) */
.im-rz {
    position: absolute;
    z-index: 3;
    display: none;
    box-sizing: border-box;
}

.bk-image-block.is-active .im-rz,
.im-block.is-active .im-rz {
    display: block;
}

.bk-image-block.is-cropping .im-rz,
.im-block.is-cropping .im-rz {
    display: none !important;
}

/* 邊把手 */
.im-rz-r {
    top: 16px;
    bottom: 16px;
    right: 0;
    width: 12px;
    cursor: ew-resize;
}

.im-rz-l {
    top: 16px;
    bottom: 16px;
    left: 0;
    width: 12px;
    cursor: ew-resize;
}

.im-rz-b {
    left: 16px;
    right: 16px;
    bottom: 0;
    height: 12px;
    cursor: ns-resize;
}

.im-rz-t {
    left: 16px;
    right: 16px;
    top: 0;
    height: 12px;
    cursor: ns-resize;
}

/* 四角把手 */
.im-rz-tl {
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
}

.im-rz-tr {
    top: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nesw-resize;
}

.im-rz-bl {
    bottom: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nesw-resize;
}

.im-rz-br,
.im-rz-c {
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
}

/* 把手內部圖示 */
.im-rz-r::after {
    content: "";
    position: absolute;
    right: 3px;
    top: 50%;
    width: 4px;
    height: 36px;
    margin-top: -18px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
}

.im-rz-l::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 50%;
    width: 4px;
    height: 36px;
    margin-top: -18px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
}

.im-rz-b::after {
    content: "";
    position: absolute;
    bottom: 3px;
    left: 50%;
    height: 4px;
    width: 36px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
}

.im-rz-t::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 50%;
    height: 4px;
    width: 36px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
}

.im-rz-tl::after,
.im-rz-tr::after,
.im-rz-bl::after,
.im-rz-br::after,
.im-rz-c::after {
    content: "";
    position: absolute;
    width: 9px;
    height: 9px;
    border-radius: 2px;
    background: var(--ed-accent, #38bdf8);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
}

.im-rz-tl::after {
    top: 3px;
    left: 3px;
}

.im-rz-tr::after {
    top: 3px;
    right: 3px;
}

.im-rz-bl::after {
    bottom: 3px;
    left: 3px;
}

.im-rz-br::after,
.im-rz-c::after {
    bottom: 3px;
    right: 3px;
}

/* 連結標籤 */
.im-link-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    background: rgba(15, 23, 42, .8);
    color: var(--ed-text);
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 5px;
    pointer-events: none;
}

/* 上傳中佔位外框 */
.im-up {
    border: 1.5px dashed var(--ed-border-strong, rgba(148, 163, 184, .4));
    border-radius: 10px;
    padding: 22px;
    display: flex;
    gap: 16px;
    align-items: center;
    background: rgba(148, 163, 184, .05);
}

.im-up img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
    flex: none;
    background: rgba(148, 163, 184, .15);
}

.im-up .info {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--ed-text, #e2e8f0);
}

.im-up .name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.im-up .bar {
    height: 6px;
    border-radius: 3px;
    background: rgba(148, 163, 184, .2);
    margin: 10px 0 6px;
    overflow: hidden;
}

.im-up .bar i {
    display: block;
    height: 100%;
    background: var(--ed-accent, #38bdf8);
    transition: width .15s;
}

.im-up .sub {
    color: var(--ed-text-muted, #94a3b8);
    font-size: 12px;
}

.im-up.err {
    border-color: rgba(248, 113, 113, .6);
}

.im-up.err .sub {
    color: #f87171;
}

.im-up .acts {
    display: flex;
    gap: 6px;
}

.im-up .acts button {
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .12);
    color: var(--ed-text, #e2e8f0);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12.5px;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s ease;
}

.im-up .acts button:hover {
    background: rgba(255, 255, 255, .12);
}

.ed-theme-light .im-up .acts button {
    background: #f1f5f9;
    border-color: rgba(15, 23, 42, .12);
}

/* ==========================================================================
   圖片裁切模式舞台 (Crop Stage - TASK-024)
   ========================================================================== */
.crop-stage {
    position: relative;
    user-select: none;
}

.crop-stage img {
    display: block;
    width: 100%;
    height: auto;
    max-width: none;
    pointer-events: none;
}

.crop-box {
    position: absolute;
    cursor: move;
    box-shadow: 0 0 0 9999px rgba(5, 8, 15, .62);
    outline: 1.5px solid #ffffff;
}

.crop-box::before, .crop-box::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.crop-box::before {
    border-left: 1px solid rgba(255, 255, 255, .35);
    border-right: 1px solid rgba(255, 255, 255, .35);
    left: 33.33%;
    right: 33.33%;
}

.crop-box::after {
    border-top: 1px solid rgba(255, 255, 255, .35);
    border-bottom: 1px solid rgba(255, 255, 255, .35);
    top: 33.33%;
    bottom: 33.33%;
}

.crop-h {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #ffffff;
    border-radius: 3px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
    z-index: 2;
}

.crop-h[data-h="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-h[data-h="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-h[data-h="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-h[data-h="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-h[data-h="n"]  { left: 50%; top: -5px; margin-left: -12px; width: 24px; height: 10px; cursor: ns-resize; }
.crop-h[data-h="s"]  { left: 50%; bottom: -5px; margin-left: -12px; width: 24px; height: 10px; cursor: ns-resize; }
.crop-h[data-h="w"]  { top: 50%; left: -5px; margin-top: -12px; width: 10px; height: 24px; cursor: ew-resize; }
.crop-h[data-h="e"]  { top: 50%; right: -5px; margin-top: -12px; width: 10px; height: 24px; cursor: ew-resize; }

.crop-size {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, .85);
    color: #ffffff;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 5px;
    pointer-events: none;
    white-space: nowrap;
}

/* ==========================================================================
   HTML 區塊編輯器樣式 (TASK-026)
   ========================================================================== */
.hb-block {
    position: relative;
    margin: 28px 0 22px;
    box-sizing: border-box;
}

/* 標籤按鈕 (點擊選取區塊) */
.hb-tab {
    position: absolute;
    left: 0;
    top: -22px;
    z-index: 2;
    display: none;
    align-items: center;
    gap: 6px;
    height: 22px;
    padding: 0 9px;
    border: 0;
    border-radius: 6px 6px 0 0;
    background: var(--ed-accent-soft, rgba(56, 189, 248, .15));
    color: var(--ed-accent, #38bdf8);
    font: 600 11.5px/22px inherit;
    font-family: inherit;
    cursor: pointer;
    box-sizing: border-box;
}

.hb-tab i {
    font-size: 12px;
}

.hb-tab span {
    font-weight: 400;
    opacity: .75;
}

.hb-block:hover .hb-tab,
.hb-block.is-active .hb-tab {
    display: inline-flex;
}

.hb-block:hover .bk-html .hb-frame,
.hb-block:hover .hb-empty {
    outline: 1px solid var(--ed-border-strong, rgba(56, 189, 248, .35));
    outline-offset: 2px;
}

.hb-block.is-active .hb-frame,
.hb-block.is-active .hb-empty {
    outline: 2px solid var(--ed-accent, #38bdf8) !important;
    outline-offset: 2px;
}

.hb-block.is-active .hb-tab {
    background: var(--ed-accent, #38bdf8);
    color: #0b1220;
}

/* 空白區塊提示 */
.hb-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 30px 16px;
    border: 1px dashed var(--ed-border-strong, rgba(56, 189, 248, .35));
    border-radius: 10px;
    color: var(--ed-text-muted, #94a3b8);
    font-size: 13.5px;
}

.hb-empty i {
    font-size: 28px;
    color: var(--ed-accent, #38bdf8);
}

.hb-empty .ed-pbtn {
    flex: none;
}

/* 高度把手 */
.hb-rz {
    position: absolute;
    left: 50%;
    bottom: -8px;
    width: 46px;
    height: 10px;
    margin-left: -23px;
    border-radius: 5px;
    background: var(--ed-accent, #38bdf8);
    border: 2px solid var(--ed-page-bg, #121722);
    cursor: ns-resize;
    display: none;
    z-index: 3;
}

.hb-block.is-active .hb-rz {
    display: block;
}

body.is-resizing iframe {
    pointer-events: none !important;
}

/* 原始碼編輯器彈窗與全螢幕檢視 */
.hb-ed,
.hb-full {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: none;
    box-sizing: border-box;
}

.hb-ed {
    background: rgba(2, 6, 16, .72);
    padding: 24px;
}

.hb-ed.show {
    display: flex;
}

.hb-ed-box {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #0b1220;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
    color: var(--ed-text);
    font-size: 13px;
}

.hb-ed header,
.hb-ed footer,
.hb-full header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    flex-wrap: wrap;
    background: rgba(15, 23, 42, .9);
}

.hb-ed header {
    border-bottom: 1px solid var(--ed-border);
}

.hb-ed footer {
    border-top: 1px solid var(--ed-border);
}

.hb-ed header b,
.hb-full header b {
    font-size: 14px;
    margin-right: 6px;
}

/* 通用按鈕（照 design/html_demo.html；HTML 編輯器、全螢幕視窗使用） */
.ed-pbtn { flex: 1; background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .1); color: var(--ed-text); border-radius: 6px; padding: 7px 8px; font-size: 12.5px; cursor: pointer; white-space: nowrap; font-family: inherit; }
.ed-pbtn:hover:not(:disabled) { border-color: var(--ed-border-strong); color: var(--ed-accent); }
.ed-pbtn:disabled { opacity: .35; cursor: default; }
.ed-pbtn.danger { color: #f87171; }
.ed-pbtn.pri { background: var(--ed-accent); border-color: var(--ed-accent); color: #0b1220; font-weight: 600; }
.ed-pbtn.pri:hover:not(:disabled) { color: #0b1220; filter: brightness(1.1); }

.hb-ed .ed-pbtn,
.hb-full .ed-pbtn {
    flex: none;
}

.hb-sel {
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .1);
    color: var(--ed-text);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12.5px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
}

.hb-ed-body {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 0;
}

.hb-code {
    display: flex;
    min-height: 0;
    min-width: 0;
    border-right: 1px solid var(--ed-border);
    background: var(--ed-viewport-bg);
}

.hb-gut {
    padding: 12px 8px 12px 12px;
    text-align: right;
    color: #475569;
    font: 12.5px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
    white-space: pre;
    overflow: hidden;
    user-select: none;
    min-width: 38px;
}

.hb-code textarea {
    flex: 1;
    min-width: 0;
    resize: none;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--ed-text);
    font: 12.5px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
    padding: 12px;
    white-space: pre;
    overflow: auto;
    tab-size: 2;
}

.hb-code textarea::placeholder {
    color: #475569;
}

.hb-prev {
    position: relative;
    min-height: 0;
    background: var(--ed-page-bg);
}

.hb-prev iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.hb-prev .hb-prev-t {
    position: absolute;
    right: 8px;
    bottom: 6px;
    z-index: 1;
    font-size: 11px;
    color: #64748b;
    pointer-events: none;
}

.hb-ed-tabs {
    display: none;
}

#edSize.err {
    color: #f87171;
}

@media (max-width: 760px) {
    .hb-ed { padding: 0; }
    .hb-ed-box { border-radius: 0; border: 0; }
    .hb-ed-tabs { display: inline-flex; }
    .hb-ed-body { grid-template-columns: 1fr; }
    .hb-ed-body[data-t="code"] .hb-prev,
    .hb-ed-body[data-t="prev"] .hb-code { display: none; }
    .hb-ed footer .muted { display: none; }
}

/* 全螢幕檢視 */
.hb-full {
    background: var(--ed-viewport-bg);
    flex-direction: column;
}

.hb-full.show {
    display: flex;
}

.hb-full header {
    border-bottom: 1px solid var(--ed-border);
    color: var(--ed-text);
}

.hb-full iframe {
    flex: 1;
    width: 100%;
    border: 0;
    display: block;
}

.hb-x {
    background: none;
    border: 0;
    color: var(--ed-text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
}

.hb-x:hover {
    color: var(--ed-text);
}

/* ==========================================================================
   💻 程式碼區塊編輯器樣式 (Block Code Editor - TASK-027)
   ========================================================================== */
.cb.is-active {
    box-shadow: 0 0 0 2px var(--ed-accent, #38bdf8), 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* 「結果＋原始碼」模式：HTML 標籤移進分頁那一行（左邊），與結果／原始碼同一行 */
.hb-block:has(.hb-tabs-nav) .hb-tab {
    top: 11px;
    border-radius: 6px;
}

/* ==========================================================================
   📐 數學公式編輯器樣式 (Block Math Editor - TASK-029)
   ========================================================================== */

/* 編輯器中公式區塊選取狀態 */
.bk-editor-root > .mb {
    border-radius: var(--ed-radius, 8px);
    border: 1px solid transparent;
    transition: border-color .15s, background .15s;
}

.bk-editor-root > .mb:hover {
    border-color: var(--ed-border, rgba(255,255,255,.08));
}

.bk-editor-root > .mb.on {
    border-color: var(--ed-border-strong, rgba(56,189,248,.35));
    background: rgba(56,189,248,.03);
}

/* 公式編輯面板 */
.mb-ed {
    display: none;
    border-top: 1px solid var(--ed-border, rgba(255,255,255,.08));
    padding: 10px 12px 12px;
    background: var(--ed-panel, #0f172a);
    border-radius: 0 0 var(--ed-radius, 8px) var(--ed-radius, 8px);
}

.mb.on .mb-ed {
    display: block;
}

.preview .mb-ed {
    display: none !important;
}

.preview .mb,
.preview .mb:hover {
    border-color: transparent;
    background: none;
}

/* 輸入框與錯誤訊息 */
.mb-ed .ta,
.pop .ta {
    width: 100%;
    min-height: 64px;
    resize: vertical;
    border: 1px solid var(--ed-border, rgba(255,255,255,.08));
    border-radius: 6px;
    background: rgba(0,0,0,.25);
    color: var(--ed-text, #e2e8f0);
    font: 14px/1.6 ui-monospace, Menlo, Consolas, monospace;
    padding: 8px 10px;
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s;
}

.ed-theme-light .mb-ed .ta,
.ed-theme-light .pop .ta {
    background: #ffffff;
    color: #1f2937;
    border-color: rgba(15,23,42,.12);
}

.mb-ed .ta:focus,
.pop .ta:focus {
    border-color: var(--ed-border-strong, rgba(56,189,248,.35));
}

.err-msg {
    color: var(--ed-danger, #fe5461);
    font-size: 12.5px;
    margin-top: 4px;
    min-height: 1em;
    line-height: 1.4;
}

/* 選項列（編號、說明） */
.opts {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px 16px;
    align-items: center;
    margin-top: 8px;
    font-size: 13px;
    color: var(--ed-muted, #94a3b8);
}

.opts input[type=text] {
    background: transparent;
    border: 1px solid var(--ed-border, rgba(255,255,255,.08));
    border-radius: 6px;
    color: var(--ed-text, #e2e8f0);
    padding: 3px 8px;
    font: inherit;
    width: 180px;
    box-sizing: border-box;
}

.ed-theme-light .opts input[type=text] {
    color: #1f2937;
    border-color: rgba(15,23,42,.12);
}

.opts .cap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.opts .cap input {
    flex: 1;
    width: auto;
    min-width: 0;
}

/* 操作列（快捷鍵說明、按鈕） */
.acts {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.kh {
    margin-right: auto;
    font-size: 12px;
    color: var(--ed-muted, #94a3b8);
}

@media (max-width: 600px) {
    .kh {
        display: none;
    }
}

.acts .btn,
.opts .btn {
    white-space: nowrap;
}

.mb-ed .btn,
.pop .btn {
    border: 1px solid var(--ed-border, rgba(255,255,255,.08));
    background: none;
    color: var(--ed-text, #e2e8f0);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    transition: all .15s;
}

.ed-theme-light .mb-ed .btn,
.ed-theme-light .pop .btn {
    color: #1f2937;
    border-color: rgba(15,23,42,.12);
}

.mb-ed .btn:hover,
.pop .btn:hover {
    background: rgba(255,255,255,.06);
}

.ed-theme-light .mb-ed .btn:hover,
.ed-theme-light .pop .btn:hover {
    background: rgba(15,23,42,.04);
}

.mb-ed .btn.pri,
.pop .btn.pri {
    background: var(--ed-accent, #38bdf8);
    border-color: var(--ed-accent, #38bdf8);
    color: #04121c;
    font-weight: 600;
}

.mb-ed .btn.pri:hover,
.pop .btn.pri:hover {
    filter: brightness(1.1);
}

.mb-ed .btn.del,
.pop .btn.del {
    color: var(--ed-danger, #fe5461);
}

.mb-ed .btn.del:hover,
.pop .btn.del:hover {
    background: rgba(254,84,97,.12);
    border-color: var(--ed-danger, #fe5461);
}

.mb-ed .btn.tg.act,
.pop .btn.tg.act {
    background: var(--ed-accent-soft, rgba(56,189,248,.15));
    border-color: var(--ed-border-strong, rgba(56,189,248,.35));
    color: var(--ed-accent, #38bdf8);
}

.mb-ed .btn.tg.act::before,
.pop .btn.tg.act::before {
    content: "✓ ";
}

/* 符號面板 (Math Palette) */
.pal-top {
    margin-top: 8px;
}

.pal-q {
    width: 100%;
    border: 1px solid var(--ed-border, rgba(255,255,255,.08));
    border-radius: 6px;
    background: transparent;
    color: var(--ed-text, #e2e8f0);
    padding: 5px 10px;
    font: inherit;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s;
}

.ed-theme-light .pal-q {
    color: #1f2937;
    border-color: rgba(15,23,42,.12);
}

.pal-q:focus {
    border-color: var(--ed-border-strong, rgba(56,189,248,.35));
}

.pal-tabs {
    display: flex;
    gap: 2px;
    margin: 6px 0 6px;
    flex-wrap: wrap;
}

.pal-tabs button {
    border: 0;
    background: none;
    color: var(--ed-muted, #94a3b8);
    padding: 3px 9px;
    border-radius: 5px;
    cursor: pointer;
    font: inherit;
    font-size: 12.5px;
    transition: all .15s;
}

.pal-tabs button:hover {
    color: var(--ed-text, #e2e8f0);
    background: rgba(255,255,255,.04);
}

.ed-theme-light .pal-tabs button:hover {
    color: #1f2937;
    background: rgba(15,23,42,.04);
}

.pal-tabs button.on {
    background: var(--ed-accent-soft, rgba(56,189,248,.15));
    color: var(--ed-accent, #38bdf8);
    font-weight: 600;
}

.pal {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 176px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.pal button {
    min-width: 40px;
    min-height: 38px;
    border: 1px solid var(--ed-border, rgba(255,255,255,.08));
    border-radius: 6px;
    background: transparent;
    color: var(--ed-text, #e2e8f0);
    cursor: pointer;
    padding: 0 6px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color .15s, background .15s;
}

.ed-theme-light .pal button {
    color: #1f2937;
    border-color: rgba(15,23,42,.12);
}

.pal button:hover {
    border-color: var(--ed-border-strong, rgba(56,189,248,.35));
    background: var(--ed-accent-soft, rgba(56,189,248,.15));
}

.pal.tpl button {
    height: auto;
    padding: 6px 10px;
    text-align: left;
    display: block;
}

.pal.tpl small {
    display: block;
    color: var(--ed-muted, #94a3b8);
    font-size: 11px;
}

/* 行內公式小視窗 (#edMathInlinePop.pop) */
.pop {
    position: relative;
    margin: 6px 0 14px;
    background: var(--ed-panel, #0f172a);
    border: 1px solid var(--ed-border-strong, rgba(56,189,248,.35));
    border-radius: var(--ed-radius, 8px);
    padding: 10px 12px 12px;
    display: none;
    color: var(--ed-text, #e2e8f0);
    font-size: 14px;
    line-height: 1.6;
    user-select: none;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
}

.ed-theme-light .pop {
    background: #ffffff;
    color: #1f2937;
    border-color: rgba(14,116,144,.4);
}

.pop .hd {
    font-size: 12px;
    color: var(--ed-accent, #38bdf8);
    font-weight: 600;
}

.pop .pv {
    min-height: 30px;
    padding: 6px 4px;
    text-align: center;
    overflow-x: auto;
}

.pop .ta {
    min-height: 40px;
}

.pop .row {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 8px;
    align-items: center;
}

/* ==========================================================================
   分頁線、頁面邊界、匯出設定與 PDF 預覽 (TASK-030)
   規格依據：.ai-tasks/design/pagebreak_link_demo.html
   ========================================================================== */

/* 分頁線 */
.bk-editor-root .pb {
    height: 34px;
    margin: 18px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ed-accent, #38bdf8);
    font-size: 12.5px;
    cursor: pointer;
    user-select: none;
    position: relative;
}
.bk-editor-root .pb::before {
    content: "";
    flex: 1;
    border-top: 2px dashed var(--ed-border-strong, rgba(56,189,248,.35));
}
.bk-editor-root .pb span {
    order: -1;
    flex: 1;
    border-top: 2px dashed var(--ed-border-strong, rgba(56,189,248,.35));
}
.bk-editor-root .pb b {
    font-weight: 600;
    padding: 2px 10px;
    border: 1px solid var(--ed-border-strong, rgba(56,189,248,.35));
    border-radius: 999px;
    background: var(--ed-accent-soft, rgba(56,189,248,.15));
    white-space: nowrap;
}
.bk-editor-root > .pb.sel {
    outline: 2px solid var(--ed-accent, #38bdf8);
    outline-offset: 3px;
    border-radius: 4px;
}
.ed-theme-light .bk-editor-root .pb {
    color: #0e7490;
}
.ed-theme-light .bk-editor-root .pb::before,
.ed-theme-light .bk-editor-root .pb span {
    border-top-color: rgba(14,116,144,.4);
}
.ed-theme-light .bk-editor-root .pb b {
    border-color: rgba(14,116,144,.4);
    background: rgba(14,116,144,.1);
}

/* 頁面邊界（自動換頁位置） */
.pg-guide {
    position: absolute;
    left: 0;
    right: 0;
    height: 0;
    border-top: 1px dashed rgba(148,163,184,.55);
    pointer-events: none;
    z-index: 3;
}
.pg-guide i {
    position: absolute;
    right: 8px;
    top: -10px;
    font: 600 11px/18px -apple-system, "PingFang TC", sans-serif;
    font-style: normal;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--ed-page, #121722);
    color: var(--ed-muted, #94a3b8);
    border: 1px solid rgba(148,163,184,.4);
}
.ed-theme-light .pg-guide i {
    background: #fbfaf6;
    color: #64748b;
}
.pg-guide::after {
    display: none !important;
}

/* 匯出設定對話框 */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1060;
    background: rgba(2,6,15,.7);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.show {
    display: flex;
}
.mbox {
    background: var(--ed-panel, #0f172a);
    border: 1px solid var(--ed-border-strong, rgba(56,189,248,.35));
    border-radius: 12px;
    width: min(560px, 100%);
    max-height: calc(100vh - 32px);
    overflow: auto;
    padding: 18px;
    color: var(--ed-text, #e2e8f0);
    box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.mbox h3 {
    margin: 0 0 6px;
    font-size: 16px;
    color: var(--ed-text, #e2e8f0);
}
.grid2 {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 10px 12px;
    align-items: center;
    margin-top: 12px;
    font-size: 13.5px;
}
.grid2 > span {
    color: var(--ed-muted, #94a3b8);
}
@media (max-width: 520px) {
    .grid2 {
        grid-template-columns: 1fr;
    }
}

.sg {
    display: inline-flex;
    border: 1px solid var(--ed-border, rgba(255,255,255,.12));
    border-radius: 7px;
    overflow: hidden;
}
.sg button {
    border: 0;
    background: none;
    color: var(--ed-muted, #94a3b8);
    padding: 5px 12px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.sg button:hover {
    background: rgba(255,255,255,.05);
}
.sg button.on {
    background: var(--ed-accent-soft, rgba(56,189,248,.18));
    color: var(--ed-accent, #38bdf8);
}

.srow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 0;
    user-select: none;
}

/* 模態對話框按鈕群組 */
.mbox .ed-p-btns,
.mbox .row {
    display: flex !important;
    gap: 10px !important;
    justify-content: flex-end !important;
    align-items: center !important;
    margin-top: 20px !important;
}
.mbox .ed-pbtn,
.mbox .btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 6px 16px !important;
    font-size: 13.5px !important;
    line-height: 1.4 !important;
    border-radius: var(--ed-radius-sm, 6px) !important;
    border: 1px solid var(--ed-border-strong, rgba(56, 189, 248, .35)) !important;
    background: rgba(255, 255, 255, 0.05) !important;
    color: var(--ed-text, #e2e8f0) !important;
    cursor: pointer !important;
    transition: all var(--ed-transition, 0.15s ease) !important;
    font-weight: 500 !important;
    transform: none !important;
    width: auto !important;
    text-decoration: none !important;
}
.mbox .ed-pbtn:hover,
.mbox .btn:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
    transform: none !important;
}
.mbox .ed-pbtn.primary,
.mbox .ed-pbtn.pri,
.mbox .btn.pri,
.mbox .btn.primary {
    background: var(--ed-accent, #38bdf8) !important;
    border-color: var(--ed-accent, #38bdf8) !important;
    color: #04121c !important;
    font-weight: 600 !important;
}
.mbox .ed-pbtn.primary:hover,
.mbox .btn.pri:hover {
    background: #0284c7 !important;
    border-color: #0284c7 !important;
    color: #fff !important;
    transform: none !important;
}

/* PDF 預覽視窗 */
.pv {
    position: fixed;
    inset: 0;
    z-index: 1060;
    background: #1f2430;
    display: none;
    flex-direction: column;
}
.pv.show {
    display: flex;
}
.pv header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--ed-panel-bg);
    border-bottom: 1px solid #1e293b;
    color: var(--ed-text);
}
.pv header .ed-pbtn,
.pv header .btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 5px 14px !important;
    font-size: 13px !important;
    border-radius: var(--ed-radius-sm, 6px) !important;
    border: 1px solid var(--ed-border-strong, rgba(56, 189, 248, .35)) !important;
    background: rgba(255, 255, 255, 0.05) !important;
    color: var(--ed-text, #e2e8f0) !important;
    cursor: pointer !important;
    transition: all var(--ed-transition, 0.15s ease) !important;
    transform: none !important;
    width: auto !important;
}
.pv header .ed-pbtn:hover,
.pv header .btn:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
    transform: none !important;
}
.pv header .ed-pbtn.primary,
.pv header .btn.pri,
.pv header .btn.primary {
    background: var(--ed-accent, #38bdf8) !important;
    border-color: var(--ed-accent, #38bdf8) !important;
    color: #04121c !important;
    font-weight: 600 !important;
}
.pv header .ed-pbtn.primary:hover,
.pv header .btn.pri:hover {
    background: #0284c7 !important;
    border-color: #0284c7 !important;
    color: #fff !important;
    transform: none !important;
}
.pv header .grow {
    flex: 1;
}
.pv .sheets {
    flex: 1;
    overflow: auto;
    padding: 24px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
}
.sheet {
    position: relative;
    background: #fff;
    color: #1f2937;
    box-shadow: 0 6px 24px rgba(0,0,0,.45);
    flex: none;
    overflow: hidden;
    --ed-page: #fff;
    --ed-text: #1f2937;
    --ed-muted: #64748b;
    --ed-border: rgba(15,23,42,.15);
    --ed-accent: #0e7490;
    --ed-accent-soft: rgba(14,116,144,.1);
    --ed-border-strong: rgba(14,116,144,.4);
}
.sheet .ct {
    position: absolute;
    overflow: hidden;
    font-size: 16px;
    line-height: 1.8;
}
.sheet .part {
    overflow: hidden;
}
.sheet .part > * {
    margin-bottom: 0 !important;
}
.sheet .part h1 { font-size: 1.7em; margin: .2em 0 .5em; line-height: 1.3; }
.sheet .part h2 { font-size: 1.3em; margin: 1.2em 0 .4em; line-height: 1.35; }
.sheet .part p { margin: .5em 0; }
.sheet .part table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: .92em; }
.sheet .part td, .sheet .part th { border: 1px solid var(--ed-border); padding: 6px 10px; text-align: left; }
.sheet .part th { background: var(--ed-accent-soft); }
.sheet .part pre { margin: 14px 0; background: #f1f5f9; color: #1f2937; border-radius: 8px; padding: 12px 16px; font: 13px/1.7 ui-monospace, Menlo, monospace; white-space: pre; overflow: hidden; }
.sheet .part a { color: #0e7490; text-decoration: underline; }
.sheet .part a[target="_blank"]::after {
    content: "↗";
    font-size: 0.75em;
    margin-left: 2px;
    text-decoration: none;
    display: inline-block;
    line-height: 1;
}
.sheet .ft {
    position: absolute;
    left: 0;
    right: 0;
    font-size: 11px;
    color: #94a3b8;
}
.sheet .hd {
    position: absolute;
    left: 0;
    right: 0;
    font-size: 11px;
    color: #94a3b8;
    text-align: left;
}

/* ==========================================================================
   連結面板與小泡泡 (TASK-031 / TASK-032)
   對接 design/pagebreak_link_demo.html
   ========================================================================== */

/* ==========================================================================
   連結屬性面板與小泡泡 (TASK-031 / TASK-032 / 右側屬性面板升級)
   對接 design/pagebreak_link_demo.html 與右側抽屜式屬性面板
   ========================================================================== */

/* 右側屬性面板內的連結控制項（取代原本浮動彈窗） */
.ed-link-panel,
.ed-panel-in .lp {
    display: flex;
    flex-direction: column;
    width: 100%;
    color: var(--ed-text, #f1f5f9);
    position: static !important;
    max-height: none !important;
    overflow: visible !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    box-sizing: border-box;
}

/* 徹底隱藏任何遺留之浮動彈窗 */
body > .lp {
    display: none !important;
}

.ed-link-panel .tabs,
.ed-panel-in .lp .tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 6px;
}
.ed-link-panel .tabs button,
.ed-panel-in .lp .tabs button {
    border: 0;
    background: none;
    color: var(--ed-muted, #94a3b8);
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    transition: background 0.15s, color 0.15s;
}
.ed-link-panel .tabs button.on,
.ed-panel-in .lp .tabs button.on {
    background: var(--ed-accent-soft, rgba(56, 189, 248, 0.15));
    color: var(--ed-accent, #38bdf8);
}
.ed-link-panel .fld,
.ed-panel-in .lp .fld {
    margin-top: 10px;
}
.ed-link-panel .fld > label,
.ed-panel-in .lp .fld > label {
    display: block;
    font-size: 12px;
    color: var(--ed-muted, #94a3b8);
    margin-bottom: 4px;
}
.ed-link-panel .in,
.ed-panel-in .lp .in {
    width: 100%;
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.1));
    border-radius: 6px;
    background: rgba(0, 0, 0, .2);
    color: var(--ed-text, #f1f5f9);
    padding: 6px 10px;
    font: inherit;
    font-size: 13.5px;
    outline: none;
    box-sizing: border-box;
}
.ed-link-panel .in:focus,
.ed-panel-in .lp .in:focus {
    border-color: var(--ed-border-strong, #38bdf8);
}
.ed-link-panel .err,
.ed-panel-in .lp .err {
    color: var(--ed-danger, #ef4444);
    font-size: 12px;
    min-height: 1em;
    margin-top: 3px;
}
.ed-link-panel .sg,
.ed-panel-in .lp .sg {
    display: inline-flex;
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.1));
    border-radius: 7px;
    overflow: hidden;
}
.ed-link-panel .sg button,
.ed-panel-in .lp .sg button {
    border: 0;
    background: none;
    color: var(--ed-muted, #94a3b8);
    padding: 5px 12px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.ed-link-panel .sg button.on,
.ed-panel-in .lp .sg button.on {
    background: var(--ed-accent-soft, rgba(56, 189, 248, 0.15));
    color: var(--ed-accent, #38bdf8);
}
.ed-link-panel .res,
.ed-panel-in .lp .res {
    margin-top: 6px;
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.1));
    border-radius: 6px;
    max-height: 168px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.15);
}
.ed-link-panel .res div,
.ed-panel-in .lp .res div {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    gap: 8px;
    align-items: baseline;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.ed-link-panel .res div:last-child,
.ed-panel-in .lp .res div:last-child {
    border-bottom: none;
}
.ed-link-panel .res div:hover,
.ed-link-panel .res div.on,
.ed-panel-in .lp .res div:hover,
.ed-panel-in .lp .res div.on {
    background: var(--ed-accent-soft, rgba(56, 189, 248, 0.15));
}
.ed-link-panel .res small,
.ed-panel-in .lp .res small {
    color: var(--ed-muted, #94a3b8);
    font-size: 11px;
    flex: none;
}
.ed-link-panel .res .u,
.ed-panel-in .lp .res .u {
    margin-left: auto;
    color: var(--ed-muted, #94a3b8);
    font-size: 11px;
    white-space: nowrap;
}
.ed-link-panel .res .h2,
.ed-panel-in .lp .res .h2 {
    padding-left: 24px;
}
.ed-link-panel .row,
.ed-panel-in .lp .row {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 12px;
    flex-wrap: wrap;
}
.ed-link-panel .kh,
.ed-panel-in .lp .kh {
    font-size: 12px;
    color: var(--ed-muted, #94a3b8);
    margin-right: auto;
}
.lp .btn {
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.1));
    background: none;
    color: var(--ed-text, #f1f5f9);
    border-radius: 6px;
    padding: 5px 12px;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    white-space: nowrap;
    transition: border-color 0.15s;
}
.lp .btn:hover {
    border-color: var(--ed-border-strong, #38bdf8);
}
.lp .btn.pri {
    background: var(--ed-accent, #38bdf8);
    border-color: var(--ed-accent, #38bdf8);
    color: #04121c;
    font-weight: 600;
}
.lp .btn.del {
    color: var(--ed-danger, #ef4444);
}

/* 連結小泡泡 */
.bub {
    position: fixed;
    z-index: 9945;
    display: none;
    align-items: center;
    gap: 2px;
    background: var(--ed-panel, #0f172a);
    border: 1px solid var(--ed-border-strong, #38bdf8);
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
    color: var(--ed-text, #f1f5f9);
    font-size: 13px;
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
}
.bub .u {
    padding: 0 8px;
    color: var(--ed-muted, #94a3b8);
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bub button {
    border: 0;
    background: none;
    color: var(--ed-text, #f1f5f9);
    padding: 4px 9px;
    border-radius: 5px;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    transition: background 0.15s;
}
.bub button:hover {
    background: var(--ed-accent-soft, rgba(56, 189, 248, 0.15));
}
.bub .del {
    color: var(--ed-danger, #ef4444);
}

/* 編輯區連結文字與新分頁箭頭 ↗ (TASK-031 / TASK-032) */
.bk-editor-root a {
    color: var(--ed-accent, #38bdf8);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    transition: color var(--ed-transition, 0.15s cubic-bezier(0.4, 0, 0.2, 1));
}
.bk-editor-root a:hover {
    color: var(--ed-accent-strong, #00d9ff);
}
.bk-editor-root a[target="_blank"]::after,
.bk-editor-root a[data-target="_blank"]::after {
    content: "↗";
    font-size: 0.75em;
    margin-left: 2px;
    text-decoration: none;
    display: inline-block;
    line-height: 1;
}
.bk-editor-root a.on {
    background: var(--ed-accent-soft, rgba(56, 189, 248, 0.15));
    border-radius: 3px;
}


