/* SketchFrame editor styles */

:root {
    --bg: #f4f4f6;
    --panel: #ffffff;
    --panel-2: #f6f6f8;
    --line: #e4e4e9;
    --line-2: #d3d3db;
    --text: #1d1d22;
    --muted: #6c6c77;
    --accent: #2f6fed;
    --accent-2: #1f5bd6;
    --accent-soft: #e7eefd;
    --danger: #d64545;
    --canvas: #e8e8ed;
    --canvas-dot: #d0d0d8;
    --shadow: 0 10px 32px rgba(18, 18, 38, 0.14);
    --shadow-sm: 0 2px 8px rgba(18, 18, 38, 0.08);
    --radius: 10px;
    --focus: 0 0 0 3px rgba(47, 111, 237, 0.32);
    --sel: #2f80ed;
    --guide: #ff2f7d;
    --ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --top: 52px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #121215;
    --panel: #1a1a1f;
    --panel-2: #212127;
    --line: #2b2b33;
    --line-2: #3a3a44;
    --text: #ececf2;
    --muted: #9b9ba8;
    --accent: #5b8cff;
    --accent-2: #7aa2ff;
    --accent-soft: #212d4a;
    --danger: #ff6b6b;
    --canvas: #0e0e11;
    --canvas-dot: #24242b;
    --shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
html:has(body.sf) { overflow: hidden; }

body.sf {
    margin: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 var(--ui);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.4; }
:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }
kbd {
    font: 11px/1 var(--ui);
    padding: 3px 6px;
    border-radius: 5px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--muted);
    white-space: nowrap;
}
code { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

/* ---------------------------------------------------------------- buttons */

.sf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: var(--panel);
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.sf-btn:hover:not(:disabled) { background: var(--panel-2); }
.sf-btn.sm { height: 28px; padding: 0 9px; font-size: 12px; }
.sf-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.sf-btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.sf-btn.ghost { border-color: transparent; background: transparent; }
.sf-btn.ghost:hover:not(:disabled) { background: var(--panel-2); }
.sf-btn.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.sf-btn svg { flex: none; }

.sf-iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    flex: none;
}
.sf-iconbtn:hover:not(:disabled) { background: var(--panel-2); }
.sf-iconbtn.is-on { background: var(--accent-soft); color: var(--accent); }
.sf-iconbtn.sm { width: 26px; height: 26px; border-radius: 6px; }
.sf-iconbtn.is-danger:hover:not(:disabled) { color: var(--danger); }
.sf-linkbtn { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 600; text-decoration: underline; }

.sf-vsep { width: 1px; height: 22px; background: var(--line); flex: none; margin: 0 4px; }
.sf-muted { color: var(--muted); }
.sf-pad { padding: 12px 14px; margin: 0; }
.sf-pad-x { padding: 4px 14px 16px; }
.sf-stack { display: grid; gap: 8px; }

/* ----------------------------------------------------------------- header */

.sf-top {
    height: var(--top);
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: relative;
    z-index: 20;
}
.sf-top-l, .sf-top-c, .sf-top-r { display: flex; align-items: center; gap: 4px; min-width: 0; }
.sf-top-l { flex: 1 1 0; overflow: hidden; }
.sf-top-c { flex: 0 0 auto; }
.sf-top-r { flex: 1 1 0; justify-content: flex-end; }

.sf-back {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    height: 34px;
    padding: 0 10px 0 4px;
    border-radius: 8px;
    color: var(--accent);
    font-weight: 600;
    font-size: 15px;
    text-decoration: none;
    flex: none;
}
.sf-back:hover { background: var(--accent-soft); }
.sf-back svg { width: 22px; height: 22px; }

.sf-brand { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; flex: none; }
.sf-brand-mark { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: var(--accent); color: #fff; }

.sf-project-name {
    min-width: 60px;
    width: 220px;
    max-width: 30vw;
    height: 32px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    font-weight: 600;
    text-overflow: ellipsis;
}
.sf-project-name:hover { border-color: var(--line); }
.sf-project-name:focus { border-color: var(--accent); background: var(--panel); outline: none; box-shadow: var(--focus); }
.sf-saved { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sf-saved.is-bad { color: var(--danger); font-weight: 600; }

.sf-skin-switch { display: inline-flex; padding: 3px; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; }
.sf-skin-switch button { height: 26px; border: 0; padding: 0 10px; border-radius: 6px; background: transparent; font-size: 12px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.sf-skin-switch button.is-on { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }
.sf-skin-switch .sk { font-family: "Balsamiq Sans", cursive; }

.sf-run-cta svg { fill: currentColor; }

/* ----------------------------------------------------------------- layout */

.sf-body { flex: 1 1 auto; display: flex; min-height: 0; position: relative; overflow: hidden; }

.sf-panel {
    background: var(--panel);
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: none;
}
.sf-left { width: 272px; border-right: 1px solid var(--line); }
.sf-right { width: 296px; border-left: 1px solid var(--line); }
body.sf-left-closed .sf-left, body.sf-right-closed .sf-right { display: none; }

.sf-sheet-handle { display: none; }
.sf-panel-close { display: none; }

.sf-tabs { display: flex; align-items: center; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); }
.sf-tabs [data-tab] {
    flex: 1;
    height: 34px;
    border: 0;
    background: none;
    border-bottom: 2px solid transparent;
    font-weight: 600;
    font-size: 13px;
    color: var(--muted);
}
.sf-tabs [data-tab].is-on { color: var(--text); border-bottom-color: var(--accent); }
.sf-pane { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

.sf-search { position: relative; margin: 12px 12px 8px; }
.sf-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.sf-search input, .sf-input {
    width: 100%;
    height: 36px;
    padding: 0 10px 0 34px;
    border: 1px solid var(--line-2);
    border-radius: 9px;
    background: var(--panel-2);
}
.sf-input { padding-left: 12px; margin-bottom: 12px; }
.sf-search input:focus, .sf-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); background: var(--panel); }

.sf-cats { display: flex; gap: 6px; padding: 2px 12px 10px; overflow-x: auto; scrollbar-width: none; }
.sf-cats::-webkit-scrollbar { display: none; }
.sf-chip {
    flex: none;
    height: 28px;
    padding: 0 11px;
    border-radius: 999px;
    border: 1px solid var(--line-2);
    background: var(--panel);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}
.sf-chip.is-on { background: var(--text); border-color: var(--text); color: var(--panel); }

.sf-lib { padding: 0 12px 20px; }
.sf-lib-h { margin: 14px 2px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.sf-lib-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.sf-lib-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 70px;
    padding: 8px 4px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--text);
    font-size: 11.5px;
    text-align: center;
    line-height: 1.15;
    cursor: grab;
    transition: border-color 0.12s, background 0.12s, transform 0.12s;
}
.sf-lib-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.sf-lib-item:active { cursor: grabbing; transform: scale(0.97); }
.sf-lib-item svg { color: var(--muted); }
.sf-lib-sym { position: relative; display: grid; }
.sf-lib-del {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: var(--panel-2);
    color: var(--muted);
    display: grid;
    place-items: center;
    opacity: 0;
}
.sf-lib-sym:hover .sf-lib-del, .sf-lib-del:focus-visible { opacity: 1; }
@media (pointer: coarse) { .sf-lib-del { opacity: 1; } }
.sf-lib-del:hover { color: var(--danger); }
.sf-lib-item:hover svg { color: var(--accent); }

.sf-pane-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; }
.sf-pages { display: grid; gap: 10px; padding: 0 12px 20px; }
.sf-page { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--panel); cursor: pointer; }
.sf-page:hover { border-color: var(--line-2); }
.sf-page.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sf-page-thumb { display: flex; justify-content: center; align-items: center; height: 116px; background: var(--canvas); border-radius: 6px; overflow: hidden; }
.sf-page-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.sf-page-num { font-size: 11px; font-weight: 700; color: var(--muted); min-width: 16px; }
.sf-page-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sf-layers { padding: 4px 8px 20px; }
.sf-layer {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 4px 0 8px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 13px;
}
.sf-layer:hover { background: var(--panel-2); }
.sf-layer.is-sel { background: var(--accent-soft); color: var(--accent); }
.sf-layer.is-hidden .sf-layer-name { opacity: 0.45; text-decoration: line-through; }
.sf-layer-ic { display: flex; color: var(--muted); }
.sf-layer-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sf-layer-tag { display: flex; color: var(--muted); }
.sf-layer .sf-iconbtn { opacity: 0; }
.sf-layer:hover .sf-iconbtn, .sf-layer.is-hidden [data-lact="hide"], .sf-layer.is-locked [data-lact="lock"] { opacity: 1; }
.sf-layers-tip { font-size: 12px; margin: 10px 14px 4px; }

/* ----------------------------------------------------------------- canvas */

.sf-stage { flex: 1 1 auto; position: relative; min-width: 0; overflow: hidden; background-color: var(--canvas); background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px); background-size: 22px 22px; }
.sf-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    cursor: default;
}
body.is-space .sf-viewport, body.tool-hand .sf-viewport { cursor: grab; }
body.is-panning .sf-viewport { cursor: grabbing; }
.sf-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.sf-boardbg {
    position: absolute;
    left: 0;
    top: 0;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 12px 40px rgba(0, 0, 0, 0.12);
}
.sf-boardbg.sf-grid-on {
    background-image:
        linear-gradient(to right, rgba(60, 60, 90, 0.06) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(60, 60, 90, 0.06) 1px, transparent 1px),
        linear-gradient(to right, rgba(60, 60, 90, 0.1) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(60, 60, 90, 0.1) 1px, transparent 1px);
    background-size: 10px 10px, 10px 10px, 50px 50px, 50px 50px;
}
.sf-boardbg.sf-grid-on.sf-grid-coarse {
    background-image:
        linear-gradient(to right, rgba(60, 60, 90, 0.1) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(60, 60, 90, 0.1) 1px, transparent 1px);
    background-size: 50px 50px, 50px 50px;
}
.sf-board { position: absolute; left: 0; top: 0; }

.sf-board .sf-el:not(.is-locked):hover { outline: calc(1.5px / var(--z, 1)) solid rgba(47, 128, 237, 0.5); }
body.is-moving .sf-board .sf-el:hover, body.is-panning .sf-board .sf-el:hover, body.tool-hand .sf-board .sf-el:hover { outline: none; }
.sf-board .sf-el.is-hidden { opacity: 0.28; }
.sf-linkbadge {
    position: absolute;
    top: -9px;
    right: -9px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--sel);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(calc(1 / var(--z, 1)));
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    z-index: 2;
}

/* selection overlay (screen space) */
.sf-overlay, .sf-textedit-host { position: absolute; inset: 0; pointer-events: none; }
.sf-selbox { position: absolute; border: 1.5px solid var(--sel); pointer-events: none; }
.sf-selbox.is-locked { border-style: dashed; border-color: #8a8a99; }
.sf-selitem { position: absolute; border: 1px dashed var(--sel); pointer-events: none; }
.sf-handle {
    position: absolute;
    width: 11px;
    height: 11px;
    background: #fff;
    border: 1.5px solid var(--sel);
    border-radius: 3px;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    touch-action: none;
}
.sf-handle::after { content: ""; position: absolute; inset: -8px; }
.h-nw { left: 0; top: 0; cursor: nwse-resize; }
.h-n { left: 50%; top: 0; cursor: ns-resize; }
.h-ne { left: 100%; top: 0; cursor: nesw-resize; }
.h-e { left: 100%; top: 50%; cursor: ew-resize; }
.h-se { left: 100%; top: 100%; cursor: nwse-resize; }
.h-s { left: 50%; top: 100%; cursor: ns-resize; }
.h-sw { left: 0; top: 100%; cursor: nesw-resize; }
.h-w { left: 0; top: 50%; cursor: ew-resize; }
.sf-lockbadge { position: absolute; top: -11px; right: -11px; width: 22px; height: 22px; border-radius: 50%; background: #6b6b78; color: #fff; display: grid; place-items: center; }
.sf-sizebadge { position: absolute; transform: translateX(-50%); padding: 2px 7px; border-radius: 6px; background: var(--sel); color: #fff; font-size: 11px; font-weight: 600; white-space: nowrap; }
.sf-guide { position: absolute; pointer-events: none; }
.sf-guide.is-v { top: 0; bottom: 0; border-left: 1px solid var(--guide); }
.sf-guide.is-h { left: 0; right: 0; border-top: 1px solid var(--guide); }
.sf-marquee { position: absolute; border: 1px solid var(--sel); background: rgba(47, 128, 237, 0.08); }

.sf-textedit {
    position: absolute;
    pointer-events: auto;
    resize: none;
    padding: 6px 8px;
    border: 2px solid var(--sel);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.97);
    color: #222;
    line-height: 1.35;
    box-shadow: var(--shadow);
    outline: none;
    z-index: 5;
}

@media (pointer: coarse) {
    .sf-handle { width: 18px; height: 18px; border-radius: 50%; border-width: 2px; }
    .sf-handle::after { inset: -10px; }
}

/* floating canvas controls */
.sf-float {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    z-index: 6;
}
.sf-zoomctl { right: 12px; bottom: 12px; }
.sf-zoomctl [data-zoom-label] { width: 56px; height: 32px; border: 0; border-radius: 7px; background: transparent; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sf-zoomctl [data-zoom-label]:hover { background: var(--panel-2); }
.sf-zoomctl .sf-iconbtn, .sf-pagechip .sf-iconbtn { width: 32px; height: 32px; }
.sf-pagechip { left: 12px; bottom: 12px; max-width: calc(100% - 300px); overflow: hidden; }
.sf-pagechip-name { display: inline-flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto; max-width: 220px; height: 32px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; font-weight: 600; font-size: 13px; }
.sf-pagechip-name:hover { background: var(--panel-2); }
.sf-pagechip-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sf-pagechip-name small { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

.sf-selbar { display: none; left: 50%; bottom: 12px; transform: translateX(-50%); }
.sf-selbar .sf-iconbtn { width: 40px; height: 40px; }

.sf-empty { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 4; padding: 16px; }
.sf-empty-card {
    pointer-events: auto;
    max-width: 380px;
    text-align: center;
    padding: 22px 22px 20px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}
.sf-empty-card h2 { margin: 6px 0 6px; font-size: 18px; }
.sf-empty-card p { margin: 0 0 16px; color: var(--muted); }
.sf-empty-card .sf-row { justify-content: center; }
.sf-empty-ic { width: 46px; height: 46px; margin: 0 auto; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

/* ------------------------------------------------------------- inspector */

.sf-panel-head { display: flex; align-items: center; justify-content: space-between; height: 44px; padding: 0 12px 0 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.sf-inspector { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 16px; }
.sf-insp-head { display: flex; align-items: center; gap: 8px; padding: 12px 10px 8px 14px; }
.sf-insp-head b { font-size: 14px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sf-insp-head > svg { color: var(--accent); flex: none; }
.sf-insp-actions { display: flex; gap: 0; }
.sf-note { display: flex; align-items: flex-start; gap: 6px; margin: 2px 14px 8px; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); color: var(--muted); font-size: 12px; line-height: 1.4; }
.sf-note svg { flex: none; margin-top: 2px; }
.sf-sec { border-top: 1px solid var(--line); }
.sf-sec summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 38px;
    padding: 0 14px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}
.sf-sec summary::-webkit-details-marker { display: none; }
.sf-sec summary::after { content: "▾"; font-size: 12px; transition: transform 0.15s; }
.sf-sec:not([open]) summary::after { transform: rotate(-90deg); }
.sf-sec-body { padding: 0 14px 14px; display: grid; gap: 12px; }
.sf-field { display: grid; gap: 5px; min-width: 0; }
.sf-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.sf-hint { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.sf-inspector input[type="text"], .sf-inspector input[type="number"], .sf-inspector input[type="url"], .sf-inspector select, .sf-inspector textarea {
    width: 100%;
    min-width: 0;
    height: 32px;
    padding: 0 9px;
    border: 1px solid var(--line-2);
    border-radius: 7px;
    background: var(--panel);
    font-size: 13px;
}
.sf-inspector textarea { height: auto; padding: 7px 9px; resize: vertical; line-height: 1.4; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.sf-inspector input:focus, .sf-inspector select:focus, .sf-inspector textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.sf-inspector input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.sf-num-sm { width: 64px !important; flex: none; }
.sf-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sf-row > input[type="text"] { flex: 1; }
.sf-grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.sf-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-items: center; }
.sf-mini { position: relative; display: block; }
.sf-mini > span { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; font-weight: 700; color: var(--muted); display: flex; pointer-events: none; }
.sf-mini input { padding-left: 22px !important; }
.sf-check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; min-height: 28px; }
.sf-check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.sf-seg { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.sf-seg .sf-iconbtn { width: 32px; height: 32px; }
.sf-seg-gap { width: 8px; }
.sf-seg.wide { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sf-color { display: flex; align-items: center; gap: 6px; }
.sf-color input[type="color"] { width: 36px; height: 32px; padding: 2px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--panel); cursor: pointer; flex: none; }
.sf-color.is-none input[type="color"] { background: repeating-linear-gradient(45deg, #fff 0 4px, #e3e3e3 4px 8px); opacity: 0.5; }
.sf-color .sf-hex { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px !important; }
.sf-swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.sf-swatches button { height: 18px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, 0.12); padding: 0; }
.sf-swatches button:hover { transform: scale(1.12); }
.sf-iconprev { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 7px; }
.sf-iconfield input { flex: 1; }
.sf-row > input[data-kind="icon"] { flex: 1; min-width: 60px; }
.sf-imgfield { height: 96px; display: grid; place-items: center; border: 1px dashed var(--line-2); border-radius: 8px; overflow: hidden; background: var(--panel-2); font-size: 12px; }
.sf-imgfield img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ------------------------------------------------------------ popups */

.sf-menu {
    position: fixed;
    z-index: 200;
    min-width: 230px;
    max-width: calc(100vw - 12px);
    max-height: calc(100dvh - 12px);
    overflow-y: auto;
    padding: 5px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 11px;
    box-shadow: var(--shadow);
    display: none;
}
.sf-menu.is-on { display: block; }
.sf-menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 32px;
    padding: 0 10px 0 8px;
    border: 0;
    border-radius: 7px;
    background: none;
    text-align: left;
    font-size: 13px;
}
.sf-menu-item span:nth-child(2) { flex: 1; }
.sf-menu-item:hover:not(:disabled), .sf-menu-item:focus { background: var(--accent-soft); outline: none; box-shadow: none; }
.sf-menu-item.is-danger { color: var(--danger); }
.sf-menu-item.is-checked .sf-menu-ic { color: var(--accent); }
.sf-menu-ic { width: 18px; display: flex; color: var(--muted); }
.sf-menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }
.sf-menu-head { padding: 6px 10px 2px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.sf-quickadd {
    position: fixed;
    z-index: 150;
    width: 330px;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: none;
}
.sf-quickadd.is-on { display: block; }
.sf-quickadd .sf-search { margin: 0 0 6px; }
.sf-quick-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; border-radius: 7px; background: none; text-align: left; }
.sf-quick-item span { flex: 1; font-weight: 600; font-size: 13px; }
.sf-quick-item small { color: var(--muted); font-size: 11px; }
.sf-quick-item svg { color: var(--muted); }
.sf-quick-item.is-on, .sf-quick-item:hover { background: var(--accent-soft); }

.sf-modal {
    position: fixed;
    inset: 0;
    z-index: 180;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(10, 10, 20, 0.45);
}
.sf-modal.is-on { display: flex; }
.sf-modal-card {
    width: 100%;
    max-width: 560px;
    max-height: 86dvh;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.sf-modal.is-wide .sf-modal-card { max-width: 940px; }
.sf-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 20px; border-bottom: 1px solid var(--line); }
.sf-modal-head h3 { margin: 0; font-size: 16px; }
.sf-modal-body { padding: 16px 20px 22px; overflow-y: auto; }
.sf-modal-body > p { margin-top: 0; }

.sf-tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.sf-tpl { display: flex; flex-direction: column; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); text-align: left; }
.sf-tpl:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sf-tpl-thumb { display: flex; justify-content: center; align-items: center; height: 150px; background: var(--canvas); border-radius: 8px; overflow: hidden; margin-bottom: 4px; }
.sf-tpl small { color: var(--muted); }

.sf-icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.sf-icon-cell { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); font-size: 10.5px; color: var(--muted); }
.sf-icon-cell span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sf-icon-cell svg { color: var(--text); }
.sf-icon-cell:hover, .sf-icon-cell.is-on { border-color: var(--accent); background: var(--accent-soft); }

.sf-projects { display: grid; gap: 8px; margin-top: 14px; }
.sf-project { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.sf-project.is-active { border-color: var(--accent); }
.sf-project small { display: block; color: var(--muted); font-size: 12px; }
.sf-pill { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }

.sf-keys { width: 100%; border-collapse: collapse; font-size: 13px; }
.sf-keys td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
.sf-keys td:last-child { text-align: right; }

.sf-toast {
    position: fixed;
    left: 50%;
    bottom: calc(22px + var(--safe-b));
    z-index: 300;
    transform: translate(-50%, 20px);
    max-width: min(92vw, 520px);
    padding: 10px 16px;
    border-radius: 10px;
    background: #222228;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}
.sf-toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.sf-toast.is-warn { background: #8a2c2c; }

.sf-scrim { display: none; }
.sf-bottombar { display: none; }
.sf-show-sm { display: none !important; }
@media (pointer: coarse) { .sf-hide-touch { display: none; } }

/* ------------------------------------------------------- wireframe content */

.sf-skin-sketch { font-family: "Balsamiq Sans", "Comic Neue", "Comic Sans MS", "Chalkboard SE", cursive; }
.sf-skin-wire { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }

.sf-el { position: absolute; box-sizing: border-box; }
.sf-c { position: absolute; inset: 0; line-height: 1.25; color: #222; }
.sf-board .sf-c, .sf-thumb .sf-c, .sf-print .sf-c, .sf-export-host .sf-c, .sf-run-board .sf-c { pointer-events: none; }
.sf-svg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.sf-at { position: absolute; box-sizing: border-box; min-width: 0; }
.sf-tb { width: 100%; max-height: 100%; overflow: hidden; overflow-wrap: anywhere; }
.sf-ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sf-img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.sf-mk-link { color: #1a66d2; text-decoration: underline; }
.sf-li { display: flex; gap: 8px; }
.sf-li-mk { flex: none; min-width: 1em; }
.sf-unknown { display: grid; place-items: center; border: 1px dashed #e5484d; color: #e5484d; font: 700 14px var(--ui); }
.sf-spin { animation: sf-spin 1s linear infinite; }
@keyframes sf-spin { to { transform: rotate(360deg); } }

.sf-thumb { position: relative; overflow: hidden; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); flex: none; }
.sf-thumb-in { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

/* ------------------------------------------------------------------- run */

.sf-run {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: #26262b;
    color: #f1f1f4;
    display: flex;
    flex-direction: column;
    outline: none;
}
.sf-run-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 52px;
    padding: 0 10px;
    background: rgba(24, 24, 28, 0.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    transition: opacity 0.3s, transform 0.3s;
}
.sf-run.is-idle .sf-run-bar { opacity: 0; transform: translateY(-100%); }
.sf-run-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    min-width: 36px;
    padding: 0 9px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font-weight: 600;
    justify-content: center;
}
.sf-run-btn:hover:not(:disabled), .sf-run-btn.is-on { background: rgba(255, 255, 255, 0.12); }
.sf-run-btn.is-on { color: #8fb3ff; }
.sf-run-title {
    flex: 1;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
}
.sf-run-title:hover { background: rgba(255, 255, 255, 0.08); }
.sf-run-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sf-run-title small { opacity: 0.6; font-variant-numeric: tabular-nums; }
.sf-run-tools { display: flex; gap: 2px; }
.sf-run-stage { flex: 1; min-height: 0; display: flex; overflow: auto; padding: 72px 28px 28px; overscroll-behavior: contain; touch-action: pan-x pan-y pinch-zoom; }
.sf-run-frame { position: relative; margin: auto; flex: none; overflow: hidden; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5); border-radius: 3px; background: #fff; }
.sf-run-frame.is-enter { animation: sf-enter 0.26s ease-out; }
@keyframes sf-enter { from { opacity: 0.35; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.sf-run-board { position: absolute; left: 0; top: 0; transform-origin: 0 0; color: #222; }
.sf-run-board .sf-el.has-link, .sf-run-board .sf-el.is-ix { cursor: pointer; }
.sf-run-board [data-idx], .sf-run-board .sf-run-input { pointer-events: auto; cursor: pointer; }
.sf-run-board .sf-el.has-link::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 6px;
    border: 2px solid rgba(47, 128, 237, 0.85);
    background: rgba(47, 128, 237, 0.14);
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}
.sf-run-board.is-hot .sf-el.has-link::after { opacity: 1; }
.sf-run-board.is-flash .sf-el.has-link::after { animation: sf-flash 0.9s ease-out; }
@keyframes sf-flash { 0%, 55% { opacity: 1; } 100% { opacity: 0; } }
.sf-run-input {
    width: 100%;
    height: 100%;
    min-width: 0;
    padding: 0;
    border: 0;
    outline: none;
    background: transparent;
    font: inherit;
    color: inherit;
    resize: none;
    cursor: text !important;
}
select.sf-run-input { cursor: pointer !important; padding: 0 6px; }
.sf-run-input::placeholder { color: #888; opacity: 1; }
.sf-run-notes {
    position: absolute;
    right: 14px;
    bottom: 14px;
    z-index: 3;
    width: min(340px, calc(100% - 28px));
    max-height: 40%;
    overflow-y: auto;
    padding: 14px 16px;
    border-radius: 12px;
    background: #fff4a3;
    color: #3b3200;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    font-size: 14px;
}
.sf-run-notes p { margin: 6px 0 0; white-space: pre-wrap; }
.sf-run-menu {
    position: fixed;
    z-index: 5;
    width: 260px;
    max-height: 60dvh;
    overflow-y: auto;
    padding: 5px;
    border-radius: 11px;
    background: #2f2f36;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}
.sf-run-menu button { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; border-radius: 7px; background: none; color: inherit; text-align: left; }
.sf-run-menu button span { opacity: 0.55; font-size: 12px; min-width: 18px; }
.sf-run-menu button:hover, .sf-run-menu button.is-on { background: rgba(255, 255, 255, 0.1); }
.sf-run-hint {
    position: absolute;
    left: 50%;
    bottom: calc(18px + var(--safe-b));
    transform: translate(-50%, 10px);
    z-index: 3;
    max-width: calc(100% - 24px);
    padding: 9px 14px;
    border-radius: 99px;
    background: rgba(0, 0, 0, 0.75);
    font-size: 13px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
}
.sf-run-hint.is-on { opacity: 1; transform: translate(-50%, 0); }
body.sf-running { overflow: hidden; }

/* ------------------------------------------------------------------ print */

.sf-print { display: none; }
@media print {
    @page { margin: 10mm; }
    body.sf { display: block; height: auto; overflow: visible; background: #fff; }
    body.sf > *:not(.sf-print) { display: none !important; }
    .sf-print { display: block; }
    .sf-print-page { break-after: page; page-break-after: always; }
    .sf-print-page:last-child { break-after: auto; page-break-after: auto; }
    .sf-print-page h2 { margin: 0 0 8px; font: 600 12px var(--ui); color: #555; }
    .sf-print-frame { position: relative; overflow: hidden; border: 1px solid #ddd; }
    .sf-print-in { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
    .sf-print-notes { margin: 10px 0 0; font: 12px/1.5 var(--ui); color: #333; white-space: pre-wrap; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

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

@media (max-width: 1279px) {
    .sf-saved { display: none; }
    .sf-project-name { width: 160px; }
    .sf-top-r .sf-btn-label { display: none; }
    .sf-top-r .sf-btn { padding: 0 9px; }
}

@media (max-width: 1100px) {
    .sf-skin-switch .sf-btn-label { display: none; }
    .sf-brand b { display: none; }
    .sf-top-r { flex: 0 0 auto; }
}

@media (max-width: 1023px) {
    .sf-left, .sf-right {
        position: absolute;
        top: 0;
        bottom: 0;
        z-index: 40;
        box-shadow: var(--shadow);
        transition: transform 0.22s ease, visibility 0.22s;
        display: flex !important;
        visibility: hidden;
    }
    .sf-left { left: 0; transform: translateX(-104%); }
    .sf-right { right: 0; transform: translateX(104%); }
    body.sf-left-open .sf-left, body.sf-right-open .sf-right { transform: none; visibility: visible; }
    .sf-panel-close { display: inline-flex; }
    .sf-scrim { position: fixed; inset: 0; z-index: 35; background: rgba(10, 10, 20, 0.3); }
    body.sf-left-open .sf-scrim, body.sf-right-open .sf-scrim { display: block; }
    body.has-sel .sf-selbar { display: flex; }
    body.has-sel .sf-pagechip { display: none; }
    .sf-pagechip { max-width: calc(100% - 250px); }
}

@media (max-width: 767px) {
    :root { --top: 50px; }
    .sf-top { gap: 2px; padding: 0 4px; }
    .sf-top-c, .sf-hide-sm, .sf-project-name, .sf-brand b { display: none !important; }
    .sf-show-sm { display: inline-flex !important; }
    .sf-back { padding-right: 6px; font-size: 14px; }
    .sf-brand-mark { width: 24px; height: 24px; }
    .sf-top-r .sf-btn { padding: 0 10px; }
    .sf-run-cta span { display: none; }

    .sf-left, .sf-right {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: auto;
        height: min(74dvh, 620px);
        border: 0;
        border-radius: 18px 18px 0 0;
        transform: translateY(calc(100% + 24px));
        padding-bottom: var(--safe-b);
    }
    body.sf-left-open .sf-left, body.sf-right-open .sf-right { transform: none; }
    .sf-sheet-handle { display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 8px auto 0; flex: none; }
    .sf-lib-grid { grid-template-columns: repeat(4, 1fr); }
    .sf-lib-item { min-height: 72px; font-size: 11px; }

    .sf-bottombar {
        display: flex;
        flex: none;
        justify-content: space-around;
        gap: 2px;
        padding: 4px 4px calc(4px + var(--safe-b));
        background: var(--panel);
        border-top: 1px solid var(--line);
        z-index: 20;
    }
    .sf-bottombar button {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        height: 50px;
        border: 0;
        border-radius: 10px;
        background: none;
        font-size: 11px;
        font-weight: 600;
        color: var(--muted);
    }
    .sf-bottombar button:active { background: var(--panel-2); }
    .sf-bottombar .is-run { color: var(--accent); }

    .sf-zoomctl { right: 8px; bottom: 8px; }
    .sf-zoomctl [data-act="zoom-in"], .sf-zoomctl [data-act="zoom-out"] { display: none; }
    .sf-pagechip { left: 8px; bottom: 8px; max-width: calc(100% - 160px); }
    .sf-pagechip [data-act="page-add"] { display: none; }
    .sf-pagechip-name small { display: none; }
    body.has-sel .sf-zoomctl { display: none; }
    .sf-selbar { bottom: 8px; max-width: calc(100% - 16px); overflow-x: auto; }
    .sf-selbar .sf-iconbtn { width: 38px; height: 40px; }

    .sf-modal { padding: 0; align-items: flex-end; }
    .sf-modal-card { max-height: 90dvh; border-radius: 18px 18px 0 0; }
    .sf-modal-body { padding-bottom: calc(22px + var(--safe-b)); }
    .sf-tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .sf-tpl-thumb { height: 110px; }
    .sf-icon-grid { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }
    .sf-empty-card { padding: 18px; }

    .sf-run-bar { height: 50px; padding: 0 4px; gap: 2px; }
    .sf-run-btn span { display: none; }
    .sf-run-btn { min-width: 34px; padding: 0 6px; }
    .sf-run-tools [data-run="fit"], .sf-run-tools [data-run="back"] { display: none; }
    .sf-run-stage { padding: 58px 8px 8px; }
    .sf-run-title { justify-content: flex-start; padding: 0 6px; }
}

@media (max-width: 380px) {
    .sf-back span { display: none; }
    .sf-lib-grid { grid-template-columns: repeat(3, 1fr); }
}

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