/* JK PDF Editor — web. Colours follow the desktop app (indigo → blue → teal accent). */

:root {
    color-scheme: light;
    --accent: #3b5bdb;
    --accent-strong: #2f4ac0;
    --accent-soft: rgba(59, 91, 219, 0.12);
    --accent-text: #ffffff;
    --grad: linear-gradient(135deg, #5b4bff 0%, #3b5bdb 55%, #0fb5a8 100%);
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --surface-3: #eef1f6;
    --viewer: #e9ecf2;
    --border: rgba(15, 23, 42, 0.10);
    --border-strong: rgba(15, 23, 42, 0.18);
    --text: #1b1f2a;
    --text-2: #4b5468;
    --text-3: #7a8396;
    --danger: #d92d20;
    --warn: #b54708;
    --warn-bg: #fff4e5;
    --ok: #15803d;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);
    --page-shadow: 0 1px 3px rgba(15, 23, 42, 0.18), 0 6px 18px rgba(15, 23, 42, 0.10);
    --sel-fill: rgba(59, 130, 246, 0.28);
    --hover-fill: rgba(59, 130, 246, 0.10);
    --radius: 10px;
    --radius-sm: 7px;
    --font: "Inter", "Segoe UI", system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans SC", sans-serif;
    --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;
    --appbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --accent: #7c8cff;
        --accent-strong: #95a2ff;
        --accent-soft: rgba(124, 140, 255, 0.18);
        --accent-text: #0f1220;
        --bg: #121317;
        --surface: #1c1d22;
        --surface-2: #202127;
        --surface-3: #2a2b32;
        --viewer: #16171b;
        --border: rgba(255, 255, 255, 0.09);
        --border-strong: rgba(255, 255, 255, 0.16);
        --text: #e9eaee;
        --text-2: #b6bac6;
        --text-3: #868b98;
        --danger: #ff6b5f;
        --warn: #ffb057;
        --warn-bg: #3a2a14;
        --ok: #4ade80;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
        --page-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
        --sel-fill: rgba(96, 165, 250, 0.33);
        --hover-fill: rgba(96, 165, 250, 0.14);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --accent: #7c8cff;
    --accent-strong: #95a2ff;
    --accent-soft: rgba(124, 140, 255, 0.18);
    --accent-text: #0f1220;
    --bg: #121317;
    --surface: #1c1d22;
    --surface-2: #202127;
    --surface-3: #2a2b32;
    --viewer: #16171b;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #e9eaee;
    --text-2: #b6bac6;
    --text-3: #868b98;
    --danger: #ff6b5f;
    --warn: #ffb057;
    --warn-bg: #3a2a14;
    --ok: #4ade80;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    --page-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
    --sel-fill: rgba(96, 165, 250, 0.33);
    --hover-fill: rgba(96, 165, 250, 0.14);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--text-3); }
.pad { padding: 12px; }
.error { color: var(--danger); margin: 6px 0 0; }

.ic {
    width: 18px;
    height: 18px;
    flex: none;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.ic.flip { transform: rotate(180deg); }

/* ------------------------------------------------------------------ buttons & inputs */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible, .seg:focus-visible, .swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.accent { background: var(--accent); border-color: transparent; color: var(--accent-text); font-weight: 600; }
.btn.accent:hover:not(:disabled) { background: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn.ghost.on, .btn.tool.on { background: var(--accent-soft); color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.big { height: 44px; padding: 0 22px; font-size: 15px; border-radius: 10px; }
.btn.small { height: 28px; padding: 0 9px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 10px; }
.icon-btn { width: 34px; padding: 0; }
.icon-btn .lang-code { display: none; }

.input {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
}
.input.small { height: 30px; width: 130px; }
.input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

select {
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    padding: 0 8px;
    width: 100%;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 20px;
    background: var(--surface-3);
    color: var(--text-2);
}
.badge.accent { background: var(--accent); color: var(--accent-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge .ic { width: 12px; height: 12px; }

kbd {
    font-family: var(--mono);
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 5px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    white-space: nowrap;
}

/* ------------------------------------------------------------------ app bar */

.appbar {
    height: var(--appbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 15px; flex: none; }
.brand:hover { text-decoration: none; }
.appbar-center { flex: 1; min-width: 0; display: flex; align-items: center; }
.appbar-end { display: flex; align-items: center; gap: 4px; flex: none; }
.lang-menu summary { width: auto; padding: 0 10px; gap: 6px; }
.lang-menu summary .lang-code { display: inline; font-size: 13px; }

.doc-title { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--text-2); }
.doc-title .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--text); }
.doc-title .dirty { color: var(--accent); font-size: 12px; }

[data-theme-choice="light"] .theme-dark, [data-theme-choice="light"] .theme-system,
[data-theme-choice="dark"] .theme-light, [data-theme-choice="dark"] .theme-system,
[data-theme-choice="system"] .theme-light, [data-theme-choice="system"] .theme-dark,
html:not([data-theme-choice]) .theme-light, html:not([data-theme-choice]) .theme-dark { display: none; }

/* ------------------------------------------------------------------ menus */

details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-pop {
    position: absolute;
    top: calc(100% + 6px);
    min-width: 220px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 50;
}
.menu-pop.right { right: 0; }
.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    background: none;
    border-radius: 6px;
    text-align: start;
    color: var(--text);
    cursor: pointer;
}
.menu-item:hover:not(:disabled) { background: var(--surface-3); text-decoration: none; }
.menu-item:disabled { opacity: 0.45; cursor: default; }
.menu-item.danger { color: var(--danger); }
.menu-item .check { visibility: hidden; color: var(--accent); }
.menu-item.checked .check { visibility: visible; }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.show-sm { display: none; }

/* ------------------------------------------------------------------ home */

.home { max-width: 1080px; margin: 0 auto; padding: 48px 24px 32px; }
.hero { display: grid; gap: 28px; }
.hero-text { text-align: center; }
.hero h1 {
    font-size: clamp(28px, 4.2vw, 44px);
    font-weight: 800;
    letter-spacing: -0.02em;
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.lead { margin: 12px auto 0; max-width: 640px; color: var(--text-2); font-size: 16px; }

.dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 44px 24px;
    border: 2px dashed var(--border-strong);
    border-radius: 18px;
    background: var(--surface);
    cursor: pointer;
    text-align: center;
    transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.over { transform: scale(1.01); }
.dropzone.compact { padding: 22px; flex-direction: row; justify-content: center; }
.drop-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: var(--grad);
    color: #fff;
}
.dropzone.compact .drop-icon { width: 40px; height: 40px; border-radius: 12px; }
.drop-icon .ic { width: 26px; height: 26px; }
.drop-title { font-size: 16px; font-weight: 600; }
.drop-note { color: var(--text-3); font-size: 12px; }
.drop-progress { display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(320px, 80%); }
.drop-progress .bar { width: 100%; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; position: relative; }
.drop-progress .bar::after { content: ""; position: absolute; inset: 0; width: var(--p, 0%); background: var(--grad); transition: width 0.15s; }
.drop-progress .label { font-size: 12px; color: var(--text-2); }

.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.quick-card {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.12s, box-shadow 0.12s;
}
.quick-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); text-decoration: none; }
.quick-card b { display: block; }
.quick-card small { display: block; color: var(--text-3); margin-top: 2px; }
.qc-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none; }
.qc-icon.c1 { background: linear-gradient(135deg, #5b4bff, #3b5bdb); }
.qc-icon.c2 { background: linear-gradient(135deg, #3b5bdb, #0fb5a8); }
.qc-icon.c3 { background: linear-gradient(135deg, #f0662a, #ffb15c); }

.features { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 44px; }
.feature { padding: 18px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.feature .ic { width: 22px; height: 22px; color: var(--accent); }
.feature h3 { font-size: 15px; margin: 10px 0 6px; }
.feature p { margin: 0; color: var(--text-2); font-size: 13px; }
.privacy {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-top: 28px;
    padding: 14px 16px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--text-2);
}
.privacy .ic { color: var(--accent); margin-top: 1px; }
.privacy p { margin: 0; }
.footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; max-width: 1080px; margin: 0 auto; padding: 18px 24px 28px; color: var(--text-3); font-size: 12px; }

.notfound { text-align: center; padding: 80px 24px; display: grid; gap: 14px; justify-items: center; }

/* ------------------------------------------------------------------ editor shell */

.editor-shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.editor-empty { flex: 1; display: grid; place-items: center; padding: 24px; }
.editor-empty .dropzone { width: min(560px, 100%); }
.loading { display: grid; justify-items: center; gap: 12px; color: var(--text-2); }

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    min-height: 48px;
    overflow-x: auto;
    scrollbar-width: none;
    z-index: 20;
}
.toolbar::-webkit-scrollbar { display: none; }
.segmented { display: flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-3); flex: none; }
.seg {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    font-weight: 500;
}
.seg .ic { width: 16px; height: 16px; }
.seg.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.tools { display: flex; align-items: center; gap: 2px; flex: 1 0 auto; }
.toolbar > *, .tools > * { flex-shrink: 0; }
.tb-sep { width: 1px; height: 22px; background: var(--border-strong); margin: 0 6px; }
.sel-count { margin-left: 8px; color: var(--text-2); font-size: 13px; white-space: nowrap; }
.zoom { display: flex; align-items: center; gap: 2px; flex: none; }
.zoom-value {
    min-width: 56px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}
.page-indicator { color: var(--text-2); font-size: 13px; margin-right: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.workspace { flex: 1; display: flex; min-height: 0; position: relative; }

.sidebar {
    width: 232px;
    flex: none;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    min-height: 0;
}
.sb-closed .sidebar { display: none; }
.sb-tabs { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); }
.sb-tabs button { flex: 1; height: 32px; border: 0; border-radius: 6px; background: none; color: var(--text-2); cursor: pointer; display: grid; place-items: center; }
.sb-tabs button.on { background: var(--accent-soft); color: var(--accent); }
.sb-body { flex: 1; overflow: auto; min-height: 0; }
.thumbs { display: grid; gap: 14px; padding: 14px 18px; }
.thumb { border: 0; background: none; padding: 0; cursor: pointer; display: grid; gap: 4px; justify-items: center; color: var(--text-2); font-size: 12px; }
.thumb img { width: 100%; background: #fff; border-radius: 3px; box-shadow: var(--page-shadow); outline: 2px solid transparent; outline-offset: 2px; }
.thumb.current img { outline-color: var(--accent); }
.thumb.current span { color: var(--accent); font-weight: 600; }
.bm-tree, .bm-tree ul { list-style: none; margin: 0; padding: 0; }
.bm-tree { padding: 8px; }
.bm-tree ul { padding-left: 14px; }
.bm {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border: 0;
    border-radius: 6px;
    background: none;
    cursor: pointer;
    text-align: start;
}
.bm:hover { background: var(--surface-3); }
.bm small { color: var(--text-3); }
.search-form { padding: 10px; display: grid; gap: 6px; }
.search-box { display: flex; align-items: center; gap: 6px; padding: 0 8px; height: 34px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); }
.search-box input { border: 0; outline: 0; background: none; flex: 1; min-width: 0; }
.search-box .ic { width: 16px; height: 16px; color: var(--text-3); }
.check, .radio { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.hits { list-style: none; margin: 0; padding: 0 6px 10px; }
.hits button { width: 100%; text-align: start; border: 0; background: none; padding: 8px; border-radius: 6px; cursor: pointer; display: grid; gap: 2px; }
.hits button:hover { background: var(--surface-3); }
.hits b { font-size: 12px; color: var(--accent); }
.hits span { font-size: 12px; color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.center { flex: 1; min-width: 0; position: relative; display: flex; }

/* ------------------------------------------------------------------ viewer */

.viewer { flex: 1; overflow: auto; background: var(--viewer); outline: none; position: relative; overscroll-behavior: contain; }
.viewer.drop-over { box-shadow: inset 0 0 0 3px var(--accent); }
.pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 24px; width: max-content; min-width: 100%; }
.pages.two { display: grid; grid-template-columns: repeat(2, max-content); justify-content: center; column-gap: 16px; row-gap: 16px; }
.page { position: relative; background: #fff; box-shadow: var(--page-shadow); flex: none; user-select: none; -webkit-user-select: none; touch-action: none; }
.viewer[data-tool="select"] .page, .viewer[data-tool="hand"] .page,
.viewer[data-tool="selectAnnot"] .page, .viewer[data-tool="selectObject"] .page, .viewer[data-tool="editText"] .page { touch-action: pan-x pan-y; }
.pimg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.ov { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ov * { vector-effect: non-scaling-stroke; }
.ov .tsel { fill: var(--sel-fill); }
.ov .flash { fill: rgba(255, 176, 0, 0.45); stroke: #ff8a00; stroke-width: 1px; animation: flash 2.4s ease-out forwards; }
@keyframes flash { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
.ov .dashed, .ov .mark.region { fill: var(--hover-fill); stroke: var(--accent); stroke-width: 1.5px; stroke-dasharray: 5 4; }
.ov .area { stroke: none; }
.ov .mark.found { fill: var(--hover-fill); stroke: var(--accent); stroke-width: 2.5px; }
.ov .selframe { fill: none; stroke: var(--accent); stroke-width: 1.5px; stroke-dasharray: 5 4; }
.ov .handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5px; }
.ov .hover { fill: var(--hover-fill); stroke: var(--accent); stroke-width: 1px; stroke-dasharray: 4 3; }

.viewer[data-tool="select"] .page, .viewer[data-tool="highlight"] .page, .viewer[data-tool="underline"] .page,
.viewer[data-tool="strike"] .page, .viewer[data-tool="editText"] .page { cursor: text; }
.viewer[data-tool="hand"] .page { cursor: grab; }
.viewer.panning .page { cursor: grabbing; }
.viewer[data-tool="selectAnnot"] .page, .viewer[data-tool="selectObject"] .page { cursor: default; }
.viewer[data-tool="rect"] .page, .viewer[data-tool="ellipse"] .page, .viewer[data-tool="line"] .page, .viewer[data-tool="arrow"] .page,
.viewer[data-tool="ink"] .page, .viewer[data-tool="textbox"] .page, .viewer[data-tool="barcode"] .page,
.viewer[data-tool="note"] .page, .viewer[data-tool="addText"] .page { cursor: crosshair; }

.jk-editor { position: absolute; z-index: 5; }
.jk-editor textarea {
    display: block;
    margin: 0;
    padding: 1px 2px;
    border: 1px dashed var(--accent);
    background: rgba(255, 255, 255, 0.92);
    resize: none;
    overflow: hidden;
    outline: none;
    white-space: pre-wrap;
    min-width: 40px;
    color-scheme: light;
}
.jk-editor textarea[wrap="off"] { white-space: pre; }
.jk-minibar {
    position: absolute;
    z-index: 6;
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 9px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.jk-minibar button { width: 32px; height: 30px; border: 0; border-radius: 6px; background: none; cursor: pointer; display: grid; place-items: center; color: var(--text); }
.jk-minibar button:hover { background: var(--surface-3); }
.jk-minibar button.ok { background: var(--accent); color: var(--accent-text); }
.jk-minibar button.danger { color: var(--danger); }
.jk-minibar .ic { width: 16px; height: 16px; }

.jk-menu, .jk-popover {
    position: fixed;
    z-index: 60;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px;
}
.jk-menu { min-width: 160px; display: grid; }
.jk-menu button { border: 0; background: none; text-align: start; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.jk-menu button:hover { background: var(--surface-3); }
.jk-menu hr { border: 0; height: 1px; background: var(--border); margin: 4px; }
.jk-popover { width: 280px; display: grid; gap: 8px; padding: 10px; }
.jk-popover textarea { width: 100%; resize: vertical; border-radius: 7px; border: 1px solid var(--border-strong); padding: 8px; background: var(--surface); }
.jk-popover .row { display: flex; justify-content: flex-end; gap: 6px; }

/* ------------------------------------------------------------------ pages mode */

.page-grid {
    flex: 1;
    overflow: auto;
    background: var(--viewer);
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 22px;
    padding: 24px;
    align-content: start;
}
.pg { display: grid; gap: 6px; justify-items: center; cursor: pointer; padding: 8px; border-radius: 10px; border: 2px solid transparent; }
.pg:hover { background: var(--hover-fill); }
.pg.sel { border-color: var(--accent); background: var(--accent-soft); }
.pg.drop { box-shadow: -4px 0 0 var(--accent); }
.pg-img { width: 100%; height: 204px; display: grid; place-items: center; }
.pg-img img { max-width: 100%; background: #fff; box-shadow: var(--page-shadow); pointer-events: none; }
.pg-num { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ properties */

.props {
    width: 260px;
    flex: none;
    overflow-y: auto;
    background: var(--surface);
    border-left: 1px solid var(--border);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.props h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); margin-bottom: 10px; display: flex; justify-content: space-between; }
.props h3 .muted { text-transform: none; letter-spacing: 0; }
.props .hint { color: var(--text-3); font-size: 12px; margin: 0; }
.props input[type="range"] { width: 100%; accent-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--c, transparent);
    cursor: pointer;
    padding: 0;
    position: relative;
    display: grid;
    place-items: center;
}
.swatch.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch.none .ic { width: 14px; height: 14px; color: var(--text-3); }
.swatch.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); overflow: hidden; }
.swatch.custom input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--text-2); margin-bottom: 10px; }
.field input[type="number"] { height: 34px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); padding: 0 8px; width: 100%; }
.row { display: flex; align-items: flex-end; gap: 6px; margin-bottom: 10px; }
.row .field { flex: 1; margin: 0; }
.note-edit { width: 100%; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); padding: 8px; margin: 10px 0 6px; resize: vertical; }

/* ------------------------------------------------------------------ barcode panel */

.barcode-panel {
    position: fixed;
    right: 16px;
    top: calc(var(--appbar-h) + 60px);
    width: min(360px, calc(100vw - 32px));
    max-height: calc(100vh - var(--appbar-h) - 90px);
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 12px;
    z-index: 40;
    display: grid;
    gap: 10px;
}
.bp-head { display: flex; align-items: center; gap: 6px; }
.bp-head h3 { flex: 1; font-size: 15px; }
.bp-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-2); display: grid; gap: 8px; }
.bp-top { display: flex; justify-content: space-between; align-items: center; }
.bp-text { margin: 0; font-family: var(--mono); font-size: 13px; white-space: pre-wrap; word-break: break-all; max-height: 240px; overflow: auto; user-select: text; }
.bp-field { display: grid; grid-template-columns: 100px 1fr; gap: 8px; font-size: 12px; }
.bp-field span:first-child { color: var(--text-3); }
.bp-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.bp-link .ic { width: 14px; height: 14px; }

/* ------------------------------------------------------------------ toast, busy, modal */

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    max-width: min(560px, calc(100vw - 32px));
    padding: 10px 16px;
    border-radius: 10px;
    background: #1f2430;
    color: #fff;
    box-shadow: var(--shadow);
    z-index: 90;
    font-size: 13px;
    animation: toast-in 0.18s ease-out;
}
.toast.warn { background: #7a2e0e; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.busy, .jk-busy body::after {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.12);
    z-index: 80;
    cursor: progress;
}
.jk-busy body::after { content: ""; }
.spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid var(--accent-soft);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 20, 0.45);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 100;
    animation: fade 0.12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
    width: min(520px, 100%);
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.modal.narrow { width: min(420px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 20px; }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 4px 20px 16px; overflow: auto; }
.modal-body p { margin: 0 0 10px; color: var(--text-2); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--border); }
.split-form { display: grid; gap: 8px; }
.indent { padding-left: 26px; display: flex; align-items: center; gap: 8px; }
.info { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.info dt { color: var(--text-3); }
.info dd { margin: 0; word-break: break-all; }
.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.keys td:first-child { width: 45%; }

#components-reconnect-modal { display: none; }
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected,
#components-reconnect-modal.components-reconnect-retrying {
    display: grid;
    position: fixed;
    inset: 0;
    place-items: center;
    background: rgba(10, 12, 20, 0.35);
    z-index: 200;
}
.reconnect-card { background: var(--surface); border-radius: 14px; padding: 22px 26px; box-shadow: var(--shadow); display: grid; gap: 10px; justify-items: center; max-width: 360px; text-align: center; }
.reconnect-card p { margin: 0; }
#components-reconnect-modal .msg-show, #components-reconnect-modal .msg-failed, #components-reconnect-modal .msg-rejected { display: none; }
#components-reconnect-modal.components-reconnect-show .msg-show,
#components-reconnect-modal.components-reconnect-retrying .msg-show { display: block; }
#components-reconnect-modal.components-reconnect-failed .msg-failed { display: block; }
#components-reconnect-modal.components-reconnect-rejected .msg-rejected { display: block; }
#components-reconnect-modal.components-reconnect-failed .spinner,
#components-reconnect-modal.components-reconnect-rejected .spinner { display: none; }
#components-reconnect-modal .btn.msg-failed, #components-reconnect-modal .btn.msg-rejected { display: none; }
#components-reconnect-modal.components-reconnect-failed .btn.msg-failed,
#components-reconnect-modal.components-reconnect-rejected .btn.msg-rejected { display: inline-flex; }

/* ------------------------------------------------------------------ merge page */

.tool-page { max-width: 860px; margin: 0 auto; padding: 24px 20px 48px; display: grid; gap: 18px; }
.tool-head { display: grid; gap: 8px; justify-items: start; }
.tool-head h1 { display: flex; align-items: center; gap: 10px; font-size: 26px; }
.tool-head h1 .ic { width: 26px; height: 26px; color: var(--accent); }
.tool-head p { margin: 0; }
.merge-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.merge-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 10px 6px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.merge-item.drop { box-shadow: 0 -3px 0 var(--accent); }
.grip { color: var(--text-3); cursor: grab; display: grid; }
.mi-num { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; }
.mi-main { flex: 1; min-width: 0; display: grid; gap: 6px; }
.mi-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mi-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; }
.mi-meta .range { display: flex; align-items: center; gap: 6px; }
.mi-meta form.inline { display: flex; gap: 6px; }
.mi-actions { display: flex; gap: 2px; }
.tool-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.tool-actions .muted { margin-right: auto; }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 1100px) {
    .props { width: 230px; }
    .sidebar { width: 200px; }
}

@media (max-width: 860px) {
    .features { grid-template-columns: repeat(2, 1fr); }
    .quick { grid-template-columns: 1fr; }
    .hide-sm { display: none !important; }
    .show-sm { display: flex; }
    .brand-name { display: none; }
    .lang-menu summary .lang-code { display: none; }
    .lang-menu summary { width: 34px; padding: 0; }
    .sidebar {
        position: absolute;
        inset: 0 auto 0 0;
        z-index: 25;
        box-shadow: var(--shadow);
        width: min(280px, 85vw);
    }
    .props {
        position: absolute;
        inset: auto 0 0 0;
        width: auto;
        max-height: 42%;
        z-index: 24;
        border-left: 0;
        border-top: 1px solid var(--border);
        box-shadow: var(--shadow);
        flex-direction: row;
        flex-wrap: wrap;
        gap: 14px 22px;
    }
    .props section { min-width: 200px; flex: 1; }
    .pages { padding: 12px; gap: 12px; }
    .page-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; padding: 12px; }
    .home { padding: 28px 16px 24px; }
}

@media (max-width: 520px) {
    .features { grid-template-columns: 1fr; }
    .appbar { gap: 6px; padding: 0 6px 0 10px; }
    .segmented .seg { padding: 0 9px; }
    .merge-item { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
