:root { --bg-0: #111; --bg-1: #1b1b1b; --bg-2: #232323; --bg-3: #282828; --bg-4: #2d2d2d; --ctl: #3a3a3a; --ctl-hover: #474747; --line: #111; --line-2: #4a4a4a; --fg-strong: #fff; --fg: #ddd; --fg-mid: #b5b5b5; --fg-dim: #8a8a8a; color-scheme: dark; }
:root[data-theme=light] { --bg-0: #dcdcdc; --bg-1: #ffffff; --bg-2: #e9e9e9; --bg-3: #f3f3f3; --bg-4: #fafafa; --ctl: #e0e0e0; --ctl-hover: #d0d0d0; --line: #c4c4c4; --line-2: #b0b0b0; --fg-strong: #111; --fg: #222; --fg-mid: #4a4a4a; --fg-dim: #6a6a6a; color-scheme: light; }
html, body, #app { height: 100%; margin: 0; }
body { background: var(--bg-2); color: var(--fg); font-family: system-ui, "Segoe UI", sans-serif; font-size: 14px; overflow: hidden; }
.boot { padding: 2rem; color: var(--fg-dim); }
#blazor-error-ui { background: #5a1d1d; bottom: 0; display: none; left: 0; padding: 0.6rem 1.2rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.studio { display: flex; flex-direction: column; height: 100%; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 5px; white-space: nowrap; padding: 6px 10px; background: var(--bg-3); border-bottom: 1px solid var(--line); }
.toolbar .brand { font-weight: 700; letter-spacing: 0.3px; margin-right: 10px; color: var(--fg-strong); }
.toolbar .sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 4px; }
.toolbar > * { flex-shrink: 0; }
.toolbar button .count { display: inline-block; margin-left: 6px; min-width: 16px; padding: 0 5px; border-radius: 8px; background: #fff; color: #2f5fa8; font-size: 11px; font-weight: 700; line-height: 16px; text-align: center; }
.runbar { display: flex; align-items: center; gap: 10px; flex-shrink: 0; height: 26px; padding: 0 10px; background: var(--bg-3); border-top: 1px solid var(--line); font-size: 12px; }
.runbar .status { flex: 1; min-width: 0; color: var(--fg-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.runbar.busy .status { color: var(--fg-strong); }
.runbar .run-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-2); flex-shrink: 0; }
.runbar .run-dot.queued { background: #d9a520; }
.runbar .run-dot.running { background: #4caf50; animation: run-pulse 1.2s ease-in-out infinite; }
@keyframes run-pulse { 50% { opacity: 0.35; } }
.runbar .run-progress { position: relative; width: 240px; height: 8px; flex-shrink: 0; border-radius: 4px; background: var(--bg-0); border: 1px solid var(--line-2); overflow: hidden; }
.runbar .run-progress > div { height: 100%; background: #4caf50; transition: width 0.3s; }
.runbar .run-progress.indeterminate > div { position: absolute; transition: none; animation: run-slide 1.4s linear infinite; }
@keyframes run-slide { from { left: -30%; } to { left: 100%; } }
.runbar .run-pct { width: 34px; flex-shrink: 0; color: var(--fg-strong); text-align: right; }
.runbar .queued { flex-shrink: 0; background: #d9a52033; color: var(--fg-strong); border: 1px solid #d9a520; border-radius: 10px; padding: 0 10px; font: inherit; cursor: pointer; line-height: 18px; }
.runbar .queued:hover { background: #d9a52066; }
.toolbar button, .toolbar label.button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 4px 9px; cursor: pointer; font: inherit; }
.toolbar button:hover:not(:disabled), .toolbar label.button:hover { background: var(--ctl-hover); }
.toolbar button:disabled { opacity: 0.45; cursor: default; }
.toolbar button.primary { background: #2f5fa8; border-color: #3d73c4; color: #fff; }
.tabs { display: flex; align-items: flex-end; gap: 2px; padding: 4px 10px 0; background: var(--bg-2); border-bottom: 1px solid var(--line); overflow-x: auto; min-height: 28px; }
.tabs .tab { display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px 12px; background: var(--bg-4); color: var(--fg-mid); border: 1px solid var(--line-2); border-bottom: 0; border-radius: 6px 6px 0 0; cursor: pointer; white-space: nowrap; max-width: 220px; user-select: none; }
.tabs .tab.active { background: var(--bg-1); color: var(--fg-strong); border-color: var(--line-2); }
.tabs .tab span { overflow: hidden; text-overflow: ellipsis; }
.tabs .tab input { width: 130px; background: var(--bg-0); color: var(--fg-strong); border: 1px solid #4f8fe8; border-radius: 3px; font: inherit; padding: 0 4px; outline: none; }
.tabs .tab button { background: none; border: 0; color: var(--fg-dim); cursor: pointer; padding: 0 2px; font-size: 15px; line-height: 1; }
.tabs .tab button:hover { color: var(--fg-strong); }
.tabs .newtab { background: none; border: 0; color: var(--fg-mid); cursor: pointer; font-size: 18px; padding: 0 8px 2px; }
.tabs .newtab:hover { color: var(--fg-strong); }
.stage { position: relative; flex: 1; min-height: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }

.toast { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111c; color: var(--fg-strong); padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line-2); max-width: 70%; pointer-events: none; }

.widget-edit { position: absolute; z-index: 5; display: flex; }
.widget-edit input, .widget-edit select, .widget-edit textarea { flex: 1; min-width: 0; background: var(--bg-1); color: var(--fg-strong); border: 1px solid #4f8fe8; border-radius: 5px; padding: 2px 8px; font: inherit; outline: none; }
.widget-edit textarea { resize: none; }

.templates { width: min(1100px, 94%); height: 80vh; align-self: flex-start; display: flex; flex-direction: column; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 10px 40px #000a; overflow: hidden; }
.templates .tpl-head { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line-2); }
.templates .tpl-head input { flex: 1; padding: 9px 12px; background: var(--bg-1); color: var(--fg-strong); border: 1px solid var(--line-2); border-radius: 6px; font: inherit; font-size: 15px; outline: none; }
.templates .tpl-count { color: var(--fg-dim); font-size: 12px; min-width: 30px; text-align: right; }
.templates .tpl-groups { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line-2); }
.templates .tpl-groups button.on { background: #2f5fa8; color: #fff; }
.templates .tpl-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); grid-auto-rows: max-content; gap: 10px; padding: 10px; align-content: start; }
.templates .tpl-card { background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.templates .tpl-card:hover { border-color: #4f8fe8; }
.templates .tpl-thumb { position: relative; aspect-ratio: 4 / 3; background: var(--bg-0); display: flex; align-items: center; justify-content: center; color: var(--fg-dim); }
.templates .tpl-thumb img { width: 100%; height: 100%; object-fit: cover; }
.templates .tpl-show { padding: 6px 10px; background: var(--bg-1); color: var(--fg); border: 1px solid var(--line-2); border-radius: 6px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.templates .tpl-show.on { background: var(--accent, #2f6fdb); color: #fff; border-color: transparent; }
.templates .tpl-badge { position: absolute; top: 6px; right: 6px; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 8px; }
.templates .tpl-missing { background: #c94040; color: #fff; }
.templates .tpl-models { background: #3a6ea5; color: #fff; }
.templates .tpl-ready { background: #2e8b57; color: #fff; }
.templates .tpl-untested { background: #8a6d1f; color: #fff; }
.templates .tpl-api { position: absolute; top: 6px; right: 6px; background: #d9a520; color: #111; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 8px; }
.templates .tpl-title { padding: 6px 8px 2px; color: var(--fg-strong); font-weight: 600; font-size: 13px; }
.templates .tpl-desc { margin: 0 8px 8px; color: var(--fg-dim); font-size: 12px; line-height: 1.35; max-height: calc(3 * 1.35em); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.templates .tpl-none { color: var(--fg-dim); padding: 20px; }
.templates .tpl-more { grid-column: 1 / -1; }
.search-backdrop { position: absolute; inset: 0; z-index: 10; background: rgba(0,0,0,0.35); display: flex; justify-content: center; padding-top: 12vh; }
.search { width: min(560px, 92%); align-self: flex-start; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 10px 40px #000a; overflow: hidden; }
.search input { width: 100%; box-sizing: border-box; padding: 12px 14px; background: var(--bg-1); color: var(--fg-strong); border: 0; border-bottom: 1px solid var(--line-2); font: inherit; font-size: 15px; outline: none; }
.search ul { list-style: none; margin: 0; padding: 4px; max-height: 50vh; overflow-y: auto; }
.search li { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 5px; cursor: pointer; }
.search li.on { background: #2f5fa8; color: #fff; }
.search li .cat { color: var(--fg-dim); font-size: 12px; }
.search li.none { color: var(--fg-dim); cursor: default; }

.menu { position: absolute; z-index: 20; list-style: none; margin: 0; padding: 4px; min-width: 190px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: 0 8px 28px #000a; }
.menu li { padding: 6px 12px; border-radius: 4px; cursor: pointer; }
.menu li:hover { background: #2f5fa8; color: #fff; }
.menu li.has-sub { position: relative; display: flex; justify-content: space-between; gap: 12px; }
.menu li.has-sub .arrow { color: inherit; opacity: 0.7; }
.menu .sub { display: none; left: 100%; top: -5px; color: var(--fg); }
.menu li.has-sub:hover > .sub, .menu li.has-sub.open > .sub { display: block; }
.menu.flip .sub { left: auto; right: 100%; }
.toolbar button.danger { background: #8a2f2f; border-color: #b04545; color: #fff; }
.toolbar label.check { display: flex; align-items: center; gap: 5px; color: var(--fg-mid); font-size: 12px; margin-left: 4px; cursor: pointer; }
.toolbar label.check input { accent-color: #4f8fe8; }
.toolbar label.check input.batch { width: 46px; background: var(--bg-3); color: var(--fg); border: 1px solid var(--line-2); border-radius: 3px; padding: 2px 4px; }
.toolbar select.engine { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 3px 6px; font: inherit; max-width: 210px; }

.toolbar button.on { background: #2f5fa8; border-color: #3d73c4; color: #fff; }
.toolbar button.on:hover:not(:disabled), .toolbar button.primary:hover:not(:disabled) { background: #3d73c4; }
.toolbar button.danger:hover:not(:disabled) { background: #a03a3a; }
.library { position: absolute; left: 0; top: 0; bottom: 0; width: 260px; z-index: 4; display: flex; flex-direction: column; background: var(--bg-2); border-right: 1px solid var(--line); }
.library .lib-filter { margin: 8px; padding: 6px 10px; background: var(--bg-1); color: var(--fg-strong); border: 1px solid var(--line-2); border-radius: 5px; font: inherit; outline: none; }
.library .lib-filter:focus { border-color: #4f8fe8; }
.library .lib-list { flex: 1; overflow-y: auto; padding: 0 6px 8px; user-select: none; }
.library .lib-cat { padding: 5px 6px; margin-top: 4px; color: var(--fg-mid); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; cursor: pointer; display: flex; justify-content: space-between; }
.library .lib-cat span { color: var(--fg-dim); }
.library .lib-node { padding: 5px 10px 5px 18px; border-radius: 4px; cursor: grab; color: var(--fg); }
.library .lib-node:hover { background: #2f5fa8; color: #fff; }
.history { position: absolute; right: 0; top: 0; bottom: 0; width: 300px; z-index: 4; display: flex; flex-direction: column; background: var(--bg-2); border-left: 1px solid var(--line); }
.history .hist-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; color: var(--fg-mid); border-bottom: 1px solid var(--line); }
.history .hist-head button, .history .hist-actions button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 4px; padding: 2px 10px; cursor: pointer; font: inherit; font-size: 12px; }
.history .hist-head button:disabled { opacity: 0.45; cursor: default; }
.history .hist-list { flex: 1; overflow-y: auto; padding: 8px; }
.history .hist-entry { background: var(--bg-4); border: 1px solid var(--line-2); border-left: 3px solid var(--fg-dim); border-radius: 5px; padding: 6px 8px; margin-bottom: 8px; }
.history .hist-entry.running { border-left-color: #4f8fe8; }
.history .hist-entry.done { border-left-color: #4caf6a; }
.history .hist-entry.failed { border-left-color: #c24a4a; }
.history .hist-title { font-size: 12px; color: var(--fg); }
.history .hist-engine { font-size: 11px; color: var(--fg-dim); margin-bottom: 4px; }
.history .hist-error { font-size: 12px; color: #e08080; margin: 4px 0; word-break: break-word; }
.history .hist-thumbs { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.history .hist-thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 3px; cursor: zoom-in; background: var(--bg-0); }
.history .hist-none { color: var(--fg-dim); padding: 12px 4px; }
.lightbox { position: absolute; inset: 0; z-index: 15; background: rgba(0,0,0,0.82); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; cursor: zoom-out; }
.lightbox img { max-width: 90%; max-height: 82%; object-fit: contain; box-shadow: 0 8px 40px #000; }
.lightbox button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 5px 16px; cursor: pointer; font: inherit; }
.history .hist-note { font-size: 12px; color: var(--fg-dim); margin: 4px 0; }
.history .hist-entry.queued { border-left-color: #c9a227; }
.settings { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); z-index: 12; width: 280px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 10px 40px #000a; padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.settings .set-head { display: flex; justify-content: space-between; align-items: center; color: var(--fg-strong); font-weight: 600; }
.settings .set-head button { background: none; border: 0; color: var(--fg-mid); font-size: 18px; cursor: pointer; }
.settings label { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--fg); }
.settings label.row { justify-content: flex-start; }
.settings select, .settings input[type=number] { background: var(--bg-1); color: var(--fg); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 6px; font: inherit; }
.settings input[type=number] { width: 70px; }
.history .hist-entry audio { width: 100%; height: 32px; margin: 4px 0; }
.maskeditor { position: fixed; inset: 0; z-index: 100; background: var(--bg-1); display: flex; flex-direction: column; }
.maskeditor .me-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg-3); border-bottom: 1px solid var(--line); color: var(--fg); }
.maskeditor .me-bar > span:first-child { font-weight: 600; color: var(--fg-strong); margin-right: 8px; }
.maskeditor .me-bar button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 4px 12px; cursor: pointer; font: inherit; }
.maskeditor .me-bar button.on { background: #2f5fa8; border-color: #3d73c4; color: #fff; }
.maskeditor .me-bar button.me-save { background: #2f7a4a; border-color: #3d9a5e; color: #fff; }
.maskeditor .me-spacer { flex: 1; }
.maskeditor .me-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 12px; }
.maskeditor .me-stack { position: relative; max-width: 100%; max-height: 100%; display: flex; }
.maskeditor .me-stack canvas { max-width: calc(100vw - 24px); max-height: calc(100vh - 90px); object-fit: contain; display: block; }
.maskeditor .me-mask { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.55; cursor: crosshair; touch-action: none; }
.models { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); z-index: 12; width: 520px; max-height: 70vh; overflow: hidden; display: flex; flex-direction: column; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 10px 40px #000a; padding: 10px 14px 14px; gap: 8px; }
.models .set-head { display: flex; justify-content: space-between; align-items: center; color: var(--fg-strong); font-weight: 600; }
.models .set-head button { background: none; border: 0; color: var(--fg-mid); font-size: 18px; cursor: pointer; }
.models .model-total { display: flex; justify-content: space-between; align-items: center; color: var(--fg-mid); font-size: 12px; }
.models button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 4px; padding: 2px 10px; cursor: pointer; font: inherit; font-size: 12px; }
.models button:disabled { opacity: 0.45; cursor: default; }
.models .model-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.models .model-file { display: flex; align-items: center; gap: 10px; padding: 3px 6px; border-radius: 4px; color: var(--fg); font-size: 12px; }
.models .model-file:hover { background: var(--bg-4); }
.models .model-file .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.models .model-file .size { color: var(--fg-dim); white-space: nowrap; }
.models .model-file.partial .name { color: #c9a227; }
.models .model-file button { padding: 0 8px; font-size: 14px; }
.models .model-download { background: var(--bg-4); border: 1px solid var(--line-2); border-radius: 5px; padding: 6px 8px; font-size: 12px; color: var(--fg); }
.models .model-download .bar { height: 6px; background: var(--bg-1); border-radius: 3px; margin: 4px 0; overflow: hidden; }
.models .model-download .bar > div { height: 100%; background: #4f8fe8; }
.models .model-download .sub { color: var(--fg-dim); }
.glbviewer { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--bg-1); }
.glbviewer .gv-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--bg-3); border-bottom: 1px solid var(--line-2); color: var(--fg); font-size: 13px; }
.glbviewer .gv-title { font-weight: 600; color: var(--fg-strong); }
.glbviewer .gv-hint { color: var(--fg-dim); font-size: 12px; }
.glbviewer .gv-spacer { flex: 1; }
.glbviewer button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 12px; cursor: pointer; font: inherit; }
.glbviewer .gv-canvas { flex: 1; width: 100%; min-height: 0; touch-action: none; cursor: grab; }
.glbviewer .gv-status { position: absolute; left: 12px; bottom: 10px; color: var(--fg-dim); font-size: 12px; pointer-events: none; }
.glbviewer .gv-status.error { color: #e05555; font-size: 14px; }
.props { position: absolute; right: 0; top: 0; bottom: 0; width: 320px; z-index: 4; display: flex; flex-direction: column; background: var(--bg-2); border-left: 1px solid var(--line); color: var(--fg); font-size: 13px; }
.props.beside { right: 300px; }
.props .props-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; color: var(--fg-mid); border-bottom: 1px solid var(--line); }
.props .props-head button { background: none; border: 0; color: var(--fg-mid); font-size: 18px; cursor: pointer; }
.props .props-body { flex: 1; overflow-y: auto; padding: 4px 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.props .props-none { color: var(--fg-dim); padding: 10px 0; }
.props .props-title { font-weight: 600; color: var(--fg-strong); margin-top: 6px; }
.props .props-section { margin-top: 12px; padding-bottom: 3px; border-bottom: 1px solid var(--line-2); color: var(--fg-mid); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.props label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 4px; }
.props label > span:first-child { color: var(--fg-mid); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.props label.row { justify-content: flex-start; }
.props label.multi { flex-direction: column; align-items: stretch; gap: 3px; }
.props input[type=text], .props input[type=number], .props select, .props textarea { width: 170px; box-sizing: border-box; background: var(--bg-1); color: var(--fg); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 6px; font: inherit; }
.props label.multi textarea { width: 100%; resize: vertical; }
.props input:focus, .props select:focus, .props textarea:focus { outline: none; border-color: #4f8fe8; }
.props .props-kv { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-top: 3px; }
.props .props-kv > span:first-child { color: var(--fg-mid); white-space: nowrap; }
.props .props-kv > :last-child { text-align: right; overflow-wrap: anywhere; min-width: 0; }
.props i { font-style: normal; color: var(--fg-dim); font-size: 11px; margin-left: 4px; }
.props code { color: var(--fg-dim); font-size: 11px; }
.props .props-desc { color: var(--fg-dim); font-size: 12px; }
.props .dim { color: var(--fg-dim); }
.props .missing { color: #e05555; }
.props button.link { background: none; border: 0; padding: 0 0 0 6px; color: #4f8fe8; cursor: pointer; font: inherit; text-align: right; max-width: 190px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; margin-left: auto; }
.props button.link:hover { text-decoration: underline; }
.crumbs { position: absolute; left: 12px; top: 10px; z-index: 3; display: flex; align-items: center; gap: 6px; padding: 4px 10px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 6px; color: var(--fg-mid); font-size: 13px; }
.crumbs button { background: none; border: 0; padding: 0; color: #4f8fe8; cursor: pointer; font: inherit; }
.crumbs button:hover { text-decoration: underline; }
.crumbs b { color: var(--fg-strong); font-weight: 600; }

/* ---- App Mode and the App Builder ---- */
.app-steps { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 4px; padding: 5px 8px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 4px 18px rgba(0,0,0,0.35); font-size: 13px; }
.app-steps-title { color: var(--fg-mid); margin-right: 6px; }
.app-steps button { background: none; border: 1px solid transparent; border-radius: 5px; color: var(--fg-mid); padding: 3px 9px; cursor: pointer; font: inherit; }
.app-steps button b { display: inline-block; width: 18px; height: 18px; line-height: 18px; border-radius: 50%; background: var(--ctl); color: var(--fg); text-align: center; font-size: 11px; margin-right: 4px; }
.app-steps button.on { border-color: #3d73c4; color: var(--fg-strong); }
.app-steps button.on b, .app-steps button.done b { background: #2f5fa8; color: #fff; }
.app-picks { position: absolute; right: 0; top: 0; bottom: 48px; width: 300px; z-index: 5; display: flex; flex-direction: column; background: var(--bg-2); border-left: 1px solid var(--line); font-size: 13px; }
.app-picks .set-head, .app-in .set-head { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; color: var(--fg-strong); font-weight: 600; border-bottom: 1px solid var(--line); }
.app-in .set-head button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 2px 10px; cursor: pointer; font: inherit; font-weight: normal; }
.app-hint { padding: 8px 12px; color: var(--fg-dim); font-size: 12px; }
.app-pick-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 4px; }
.app-pick { display: flex; align-items: center; gap: 6px; padding: 5px 6px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 5px; }
.app-pick b { width: 18px; height: 18px; line-height: 18px; border-radius: 50%; background: #4aa8ff; color: #fff; text-align: center; font-size: 11px; flex-shrink: 0; }
.app-pick span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-pick button { background: none; border: 0; color: var(--fg-mid); cursor: pointer; padding: 0 3px; font-size: 14px; }
.app-pick button:hover { color: var(--fg-strong); }
.app-default { position: absolute; inset: 0 0 48px 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: var(--bg-2); }
.app-default h3 { margin: 0; color: var(--fg-strong); }
.app-default p { margin: 0 0 6px; color: var(--fg-dim); }
.app-default label { display: flex; gap: 8px; align-items: center; min-width: 160px; }
.app-builder-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 48px; z-index: 7; display: flex; align-items: center; gap: 8px; padding: 0 14px; background: var(--bg-3); border-top: 1px solid var(--line); }
.app-builder-bar .grow { flex: 1; }
.app-builder-bar button, .app-default button, .app-run-row button, .app-graph, .app-field label.button, .app-progress button, .app-results button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 5px 14px; cursor: pointer; font: inherit; }
.app-builder-bar button.primary, .app-default button.primary, .app-run-row button.primary { background: #2f5fa8; border-color: #3d73c4; color: #fff; }
.app-progress button.danger { background: #8a2f2f; border-color: #b04545; color: #fff; }
.app-builder-bar button:disabled, .app-run-row button:disabled { opacity: 0.5; cursor: default; }
.appmode { position: absolute; inset: 0; z-index: 5; display: flex; background: var(--bg-1); }
.appmode.preview { bottom: 48px; }
.app-out { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-progress { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--line); color: var(--fg-strong); font-size: 13px; }
.app-progress span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-progress .run-progress { position: relative; width: 220px; height: 8px; border-radius: 4px; background: var(--bg-0); border: 1px solid var(--line-2); overflow: hidden; }
.app-progress .run-progress > div { height: 100%; background: #4caf50; transition: width 0.3s; }
.app-progress .run-progress.indeterminate > div { position: absolute; transition: none; animation: run-slide 1.4s linear infinite; }
.app-results { flex: 1; min-height: 0; overflow: auto; display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: center; gap: 14px; padding: 18px; }
.app-results img { max-width: 100%; max-height: calc(100% - 4px); object-fit: contain; border-radius: 6px; box-shadow: 0 6px 26px rgba(0,0,0,0.4); cursor: zoom-in; }
.app-results pre { max-width: 100%; white-space: pre-wrap; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 6px; padding: 10px 12px; margin: 0; }
.app-empty { margin: auto; color: var(--fg-dim); }
.app-runs { display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; border-top: 1px solid var(--line); background: var(--bg-2); flex-shrink: 0; }
.app-run { width: 64px; height: 64px; flex-shrink: 0; border-radius: 5px; border: 2px solid var(--line-2); background: var(--bg-3); display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: pointer; color: var(--fg-mid); font-size: 12px; }
.app-run img { width: 100%; height: 100%; object-fit: cover; }
.app-run.on { border-color: #4aa8ff; }
.app-run.queued { border-style: dashed; border-color: #d9a520; cursor: default; }
.app-run.failed { border-color: #b04545; }
.app-run.running { border-color: #4caf50; }
.app-in { width: 340px; flex-shrink: 0; display: flex; flex-direction: column; background: var(--bg-2); border-left: 1px solid var(--line); font-size: 13px; }
.app-in-body { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 10px; }
.app-field { display: flex; flex-direction: column; gap: 5px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.app-field.missing { color: #e05555; }
.app-field-node { color: var(--fg-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.app-field > label { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.app-field > label > span:first-child { color: var(--fg-mid); }
.app-field > label.row { justify-content: flex-start; }
.app-field > label.multi { flex-direction: column; align-items: stretch; gap: 3px; }
.app-field input[type=text], .app-field input[type=number], .app-field select, .app-field textarea { width: 190px; box-sizing: border-box; background: var(--bg-1); color: var(--fg); border: 1px solid var(--line-2); border-radius: 4px; padding: 4px 6px; font: inherit; }
.app-field > label.multi textarea { width: 100%; resize: vertical; }
.app-field label.button { align-self: flex-start; }
.app-picture { max-width: 100%; max-height: 200px; object-fit: contain; border-radius: 5px; align-self: center; }
.app-run-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); }
.app-run-row .batch { width: 60px; background: var(--bg-1); color: var(--fg); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 5px; font: inherit; }
.app-run-row button.primary { flex: 1; padding: 8px 14px; font-weight: 600; }
.app-graph { margin: 0 12px 12px; }
@media (max-width: 760px) {
    .appmode { flex-direction: column; }
    .app-in { width: auto; max-height: 55%; border-left: 0; border-top: 1px solid var(--line); }
    .app-picks { width: 100%; top: auto; height: 45%; }
    .app-steps { left: 8px; right: 8px; transform: none; flex-wrap: wrap; }
}

/* ---- Workflow library (Workflows / Apps sidebar) and the Save dialog ---- */
.library.workflows { z-index: 6; } /* above the app view: the library is used from an app too */
.workflows .wf-tabs { display: flex; gap: 4px; padding: 8px 8px 0; }
.workflows .wf-tabs button { flex: 1; background: var(--ctl); color: var(--fg-mid); border: 1px solid var(--line-2); border-radius: 5px; padding: 4px 8px; cursor: pointer; font: inherit; }
.workflows .wf-tabs button.on { background: #2f5fa8; border-color: #3d73c4; color: #fff; }
.workflows .wf-create { width: 100%; margin: 4px 0; background: var(--ctl); color: var(--fg); border: 1px dashed var(--line-2); border-radius: 5px; padding: 6px; cursor: pointer; font: inherit; }
.workflows .wf-create:hover { border-color: #4f8fe8; color: var(--fg-strong); }
.workflows .wf-item { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 4px; cursor: pointer; color: var(--fg); }
.workflows .wf-item:hover { background: var(--bg-3); }
.workflows .wf-item.active { background: #2f5fa833; color: var(--fg-strong); }
.workflows .wf-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workflows .wf-item small { color: var(--fg-dim); font-size: 11px; white-space: nowrap; }
.workflows .wf-item button { background: none; border: 0; color: var(--fg-dim); cursor: pointer; padding: 0 3px; font-size: 13px; visibility: hidden; }
.workflows .wf-item:hover button, .workflows .wf-item.confirm button { visibility: visible; }
.workflows .wf-item button:hover { color: var(--fg-strong); }
.workflows .wf-item.confirm { cursor: default; background: var(--bg-3); }
.workflows .wf-item.confirm button { border: 1px solid var(--line-2); border-radius: 4px; padding: 1px 8px; color: var(--fg); background: var(--ctl); font-size: 12px; }
.workflows .wf-item.confirm button.danger { background: #8a2f2f; border-color: #b04545; color: #fff; }
.workflows .wf-app { font-size: 10px; font-weight: 600; text-transform: uppercase; color: #fff; background: #2f5fa8; border-radius: 3px; padding: 0 4px; }
.workflows .wf-rename { width: 100%; box-sizing: border-box; margin: 2px 0; padding: 4px 8px; background: var(--bg-1); color: var(--fg-strong); border: 1px solid #4f8fe8; border-radius: 4px; font: inherit; outline: none; }
.workflows .wf-foot { display: flex; align-items: center; gap: 6px; padding: 8px; border-top: 1px solid var(--line); font-size: 12px; }
.workflows .wf-foot button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 3px 10px; cursor: pointer; font: inherit; }
.workflows .wf-foot span { color: var(--fg-dim); margin-left: auto; white-space: nowrap; }
.modal-back { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: #0008; }
.save-dialog { width: min(420px, calc(100vw - 32px)); box-sizing: border-box; padding: 16px 18px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 10px 40px #000a; display: flex; flex-direction: column; gap: 10px; }
.save-dialog h3 { margin: 0; color: var(--fg-strong); font-size: 15px; }
.save-dialog p { margin: 0; color: var(--fg-dim); font-size: 12px; }
.save-dialog p.warn { color: #e0b040; }
.save-dialog input { padding: 6px 10px; background: var(--bg-1); color: var(--fg-strong); border: 1px solid var(--line-2); border-radius: 5px; font: inherit; outline: none; }
.save-dialog input:focus { border-color: #4f8fe8; }
.save-dialog .row { display: flex; justify-content: flex-end; gap: 8px; }
.save-dialog button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 5px 14px; cursor: pointer; font: inherit; }
.save-dialog button.primary { background: #2f5fa8; border-color: #3d73c4; color: #fff; }

/* ---- Keyboard shortcuts ---- */
.settings .set-button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 4px 10px; cursor: pointer; font: inherit; }
.shortcuts { width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 80px); box-sizing: border-box; display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 10px 40px #000a; font-size: 13px; }
.shortcuts .set-head { display: flex; justify-content: space-between; align-items: center; color: var(--fg-strong); font-weight: 600; }
.shortcuts .set-head button { background: none; border: 0; color: var(--fg-mid); font-size: 18px; cursor: pointer; }
.shortcuts .sc-filter { padding: 6px 10px; background: var(--bg-1); color: var(--fg-strong); border: 1px solid var(--line-2); border-radius: 5px; font: inherit; outline: none; }
.shortcuts .sc-filter:focus { border-color: #4f8fe8; }
.shortcuts .sc-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.shortcuts .sc-row { display: flex; align-items: center; gap: 6px; padding: 4px 4px; border-bottom: 1px solid var(--line); }
.shortcuts .sc-row.changed .sc-name { color: #7fb4ff; }
.shortcuts .sc-name { flex: 1; min-width: 0; color: var(--fg); }
.shortcuts .sc-keys { min-width: 170px; display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-start; background: none; border: 1px solid transparent; border-radius: 5px; padding: 3px 5px; cursor: pointer; color: var(--fg); font: inherit; }
.shortcuts .sc-keys:hover { border-color: var(--line-2); }
.shortcuts .sc-keys.capturing { border-color: #4f8fe8; color: #7fb4ff; outline: none; }
.shortcuts kbd { background: var(--bg-1); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 6px; font-family: inherit; font-size: 12px; line-height: 18px; color: var(--fg-strong); }
.shortcuts .sc-none { color: var(--fg-dim); }
.shortcuts .sc-act { background: none; border: 0; color: var(--fg-mid); cursor: pointer; font-size: 15px; padding: 0 4px; }
.shortcuts .sc-act:disabled { opacity: 0.3; cursor: default; }
.shortcuts .sc-foot { display: flex; align-items: center; gap: 10px; color: var(--fg-mid); }
.shortcuts .sc-foot span { flex: 1; }
.shortcuts .sc-foot button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 4px 12px; cursor: pointer; font: inherit; }

/* ---- Node templates ---- */
.templates-manage .tpl-list { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.templates-manage .tpl-row { display: flex; gap: 6px; align-items: center; }
.templates-manage .tpl-row input { flex: 1; }
.templates-manage .row { align-items: center; }
.templates-manage .row .grow { flex: 1; }
.save-dialog label.button { background: var(--ctl); color: var(--fg); border: 1px solid var(--line-2); border-radius: 5px; padding: 5px 14px; cursor: pointer; font: inherit; }
