/* ═══════════════════════════════════════════════════════════════════════════
   Scripting UI — code editor host, script console, Scripts workbench (/engineering/scripts).
   Reads the app.css tokens only, so it renders in both workspaces (.theme-eng / .theme-runtime).
   ═══════════════════════════════════════════════════════════════════════════ */

/* ──────────────────────────── CodeEditor component ──────────────────────────── */
.code-editor { position: relative; min-width: 0; }
.code-editor.fill { height: 100%; display: flex; flex-direction: column; }
.code-editor.fill > .cm-host { flex: 1 1 auto; min-height: 0; }
.cm-host {
    min-width: 0; overflow: hidden;
    border: 1px solid var(--border-strong); border-radius: var(--radius-md);
    background: var(--field);
    transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.cm-host:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.cm-host.is-readonly { background: var(--surface-2); }
.cm-host.is-readonly .cm-editor { background: transparent; }
.cm-host.is-readonly .cm-gutters { background: var(--surface-3); }
.code-editor.fill > .cm-host > .cm-editor { height: 100%; }
.cm-host-dark { border-color: #34363A; background: #1C1D20; }
.cm-host-dark:focus-within { border-color: #8C9096; box-shadow: 0 0 0 3px rgba(180, 183, 188, 0.18); }
.cm-host-dark.is-readonly, .cm-host-dark.is-readonly .cm-gutters { background: #18191B; }
.cm-load-error { margin-top: 0.35rem; font-size: 0.78rem; color: var(--bad); }

/* ──────────────────────────── ScriptConsole component ──────────────────────────── */
.sc-console {
    display: flex; flex-direction: column; min-width: 0; min-height: 0;
    font-size: 0.82rem; color: var(--text);
    background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.sc-head {
    display: flex; align-items: center; gap: 0.6rem; flex: 0 0 auto;
    padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); background: var(--surface-2);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.sc-console:not(:has(.sc-body)) .sc-head { border-bottom: none; border-radius: var(--radius-md); }
.sc-title { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 650; font-size: 0.78rem; color: var(--text-2); white-space: nowrap; }
.sc-status { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 650; white-space: nowrap; min-width: 0; }
.sc-status.ok { color: var(--ok); }
.sc-status.bad { color: var(--bad); }
.sc-status.busy { color: var(--text-2); font-weight: 550; }
.sc-status .sc-dur { color: var(--text-3); font-weight: 500; font-variant-numeric: tabular-nums; }
.sc-idle { color: var(--text-3); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.sc-glyph { font-size: 0.85em; line-height: 1; }
.sc-spacer { flex: 1; }
.sc-clear {
    display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; flex: 0 0 auto;
    border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--text-3); cursor: pointer;
}
.sc-clear:hover { color: var(--text); border-color: var(--border); background: var(--hover); }
.sc-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 0.45rem 0.6rem 0.55rem; display: flex; flex-direction: column; gap: 0.45rem; }
.sc-error {
    display: flex; align-items: flex-start; gap: 0.45rem; padding: 0.4rem 0.55rem;
    border: 1px solid var(--bad-border); border-left: 3px solid var(--bad); border-radius: var(--radius-sm);
    background: var(--bad-bg); color: var(--bad); font-family: var(--font-mono); font-size: 0.78rem; white-space: pre-wrap; word-break: break-word;
}
.sc-error .sc-glyph { margin-top: 0.2rem; font-size: 0.6rem; }
.sc-line { flex: 0 0 auto; padding: 0 5px; border-radius: 3px; background: var(--bad); color: #FFFFFF; font-weight: 700; font-size: 0.7rem; line-height: 1.5; font-family: var(--font-sans); }
.sc-error-text { min-width: 0; }
.sc-logs, .sc-actions { list-style: none; margin: 0; padding: 0; font-family: var(--font-mono); font-size: 0.78rem; }
.sc-log { display: flex; gap: 0.5rem; padding: 1px 0; line-height: 1.45; }
.sc-lvl { flex: 0 0 3.6em; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; color: var(--text-3); padding-top: 1px; font-family: var(--font-sans); }
.sc-msg { min-width: 0; white-space: pre-wrap; word-break: break-word; }
.sc-log.lvl-warn .sc-lvl, .sc-log.lvl-warn .sc-msg { color: var(--warn); }
.sc-log.lvl-error .sc-lvl, .sc-log.lvl-error .sc-msg { color: var(--bad); }
.sc-log.lvl-debug .sc-msg { color: var(--text-3); }
.sc-actions-title { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin-top: 0.15rem; }
.sc-action { display: flex; align-items: baseline; gap: 0.45rem; padding: 2px 0; flex-wrap: wrap; }
.sc-action .icon { flex: 0 0 auto; color: var(--text-3); align-self: center; }
.sc-action-text { color: var(--text); word-break: break-word; }
.sc-action-note { color: var(--text-3); font-family: var(--font-sans); font-size: 0.76rem; }
.sc-nothing { margin: 0; color: var(--text-3); font-size: 0.8rem; }
.sc-console.dark { background: #1C1D20; border-color: #34363A; color: #E6E7E9; }
.sc-console.dark .sc-head { background: #212225; border-color: #34363A; }

/* ──────────────────────────── Scripts page: edge-to-edge (AppNav.FullBleed) ──────────────────────────── */
.scr-page { position: relative; min-width: 0; display: flex; flex-direction: column; }
.eng-content.full-bleed > .scr-page { flex: 1 1 auto; min-height: 0; }
.eng-content.full-bleed > .scr-page > .scr-wb { border: none; border-radius: 0; box-shadow: none; }

.scr-pagebar {
    display: flex; align-items: baseline; gap: 0.35rem 0.85rem; flex: 0 0 auto; min-width: 0;
    padding: 0.55rem 1rem 0.5rem; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.scr-crumbs { margin: 0; flex: 0 0 auto; }
.scr-pagetitle { font-size: 1.12rem; font-weight: 700; letter-spacing: -0.015em; flex: 0 0 auto; }
.scr-pagedesc { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 0.8rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scr-kill-alert { flex: 0 0 auto; margin: 0.5rem 0.75rem; }
.scr-kill-alert > span { flex: 1; min-width: 0; }

/* ──────────────────────────── Workbench grid ──────────────────────────── */
.scr-wb {
    position: relative; flex: 1 1 auto; min-height: 0; min-width: 0;
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "list main" "list console";
    background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); overflow: hidden;
}
.scr-wb.ref-open {
    grid-template-columns: 272px minmax(0, 1fr) 300px;
    grid-template-areas: "list main ref" "list console ref";
}
.scr-wb > * { min-width: 0; min-height: 0; }

/* ── List ── */
.scr-list { grid-area: list; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface-2); }
.scr-list-head { display: flex; gap: 0.45rem; align-items: center; padding: 0.65rem 0.65rem 0.5rem; }
.scr-search { position: relative; flex: 1; min-width: 0; }
.scr-search > .icon, .scr-ref-search > .icon { position: absolute; left: 0.55rem; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.scr-search .form-control, .scr-ref-search .form-control { padding-left: 1.9rem; }
.scr-new { position: relative; flex: 0 0 auto; }
.scr-new .btn { gap: 0.3rem; }
.scr-menu-scrim { position: fixed; inset: 0; z-index: 80; }
.scr-menu {
    position: absolute; z-index: 90; top: calc(100% + 4px); left: 0; width: 260px; padding: 0.3rem;
    background: var(--surface-raised); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    animation: fade 0.12s var(--ease);
}
.scr-menu-item {
    display: flex; align-items: flex-start; gap: 0.6rem; width: 100%; padding: 0.45rem 0.55rem; text-align: left;
    background: none; border: none; border-radius: var(--radius-sm); color: var(--text); cursor: pointer; font-size: 0.84rem;
}
.scr-menu-item > .icon { margin-top: 2px; color: var(--accent-text); flex: 0 0 auto; }
.scr-menu-item span { display: flex; flex-direction: column; min-width: 0; }
.scr-menu-item small { color: var(--text-3); font-size: 0.74rem; }
.scr-menu-item:hover, .scr-menu-item:focus-visible { background: var(--accent-subtle); outline: none; }

.scr-kill { display: flex; align-items: center; gap: 0.55rem; padding: 0.35rem 0.8rem 0.6rem; font-size: 0.8rem; color: var(--text-2); border-bottom: 1px solid var(--border); }
.scr-kill strong.on { color: var(--ok); }
.scr-kill strong.off { color: var(--bad); }

.scr-list-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0.35rem 0.45rem 0.75rem; }
.scr-skel { height: 3rem; margin: 0.4rem 0.2rem; }
.scr-list-error { padding: 0.75rem; font-size: 0.82rem; color: var(--bad); display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start; }
.scr-list-error p { margin: 0; }
.scr-list-note { display: flex; align-items: center; gap: 0.35rem; margin: 0.5rem 0.4rem 0; font-size: 0.74rem; color: var(--text-3); }
.scr-group { margin-top: 0.45rem; }
.scr-group-title {
    display: flex; align-items: center; justify-content: space-between; padding: 0.35rem 0.45rem 0.25rem;
    font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3);
}
.scr-count { font-size: 0.68rem; padding: 0 6px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); letter-spacing: 0; }
.scr-group-empty { padding: 0.3rem 0.5rem 0.4rem; font-size: 0.78rem; color: var(--text-3); }
.scr-items { list-style: none; margin: 0; padding: 0; }
.scr-item {
    position: relative; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 0.15rem; width: 100%; text-align: left;
    padding: 0.42rem 0.5rem 0.45rem 0.6rem; margin: 1px 0; border: 1px solid transparent; border-radius: var(--radius-md);
    background: transparent; color: var(--text); cursor: pointer; font: inherit;
}
.scr-item:hover { background: var(--surface-1); border-color: var(--border); }
.scr-item.active { background: var(--surface-1); border-color: var(--accent-border); box-shadow: var(--shadow-sm); }
.scr-item.active::before { content: ''; position: absolute; left: -1px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.scr-item:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.scr-item-top { display: flex; align-items: center; justify-content: flex-start; gap: 0.45rem; min-width: 0; width: 100%; }
.scr-item-name { flex: 1; min-width: 0; font-size: 0.86rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scr-dirty { color: var(--warn); font-size: 0.7rem; }
.scr-item-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; width: 100%; gap: 0.2rem 0.45rem; padding-left: 1.05rem; font-size: 0.72rem; color: var(--text-3); }
.scr-trigger {
    padding: 0 6px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-1);
    color: var(--text-2); font-weight: 600; white-space: nowrap;
}
.scr-state { font-weight: 600; }
.scr-state.st-running, .scr-state.st-idle { color: var(--ok); }
.scr-state.st-faulted { color: var(--bad); }
.scr-counts { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* State dot: shape + colour (never colour alone) */
.scr-dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--text-disabled); background: transparent; }
.scr-dot.st-running { background: var(--ok); border-color: var(--ok); }
.scr-dot.st-idle { border-color: var(--ok); }
.scr-dot.st-faulted { background: var(--bad); border-color: var(--bad); border-radius: 1px; }
.scr-dot.st-disabled, .scr-dot.st-off { border-style: dashed; }
.scr-dot.st-library { border-color: var(--text-3); border-radius: 2px; }
.scr-dot.st-new { border-color: var(--warn); border-style: dotted; }

/* ── Main ── */
.scr-main { grid-area: main; display: flex; flex-direction: column; min-height: 0; padding: 0.7rem 0.85rem 0.6rem; gap: 0.5rem; overflow-y: auto; }
.scr-mobile-pick { display: none; }
.scr-main-skel { padding: 0.5rem; height: 100%; }
.scr-empty { margin: auto; max-width: 560px; }
.scr-empty-icon { display: inline-flex; padding: 0.75rem; border-radius: var(--radius-lg); background: var(--accent-subtle); color: var(--accent-text); margin-bottom: 0.75rem; }
.scr-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; }
.scr-empty-actions .btn { gap: 0.35rem; }

.scr-toolbar { display: flex; align-items: center; gap: 0.5rem 0.75rem; flex-wrap: wrap; flex: 0 0 auto; }
.scr-title { display: flex; align-items: center; gap: 0.45rem; min-width: 0; flex: 1 1 220px; flex-wrap: wrap; }
.scr-name { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scr-badge {
    font-size: 0.72rem; font-weight: 650; padding: 1px 7px; border-radius: var(--radius-sm); white-space: nowrap;
    background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border-strong);
}
.scr-actions { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.scr-actions .btn { gap: 0.35rem; }
.btn-icon-sm { width: 30px; padding: 0; }
.scr-ref-toggle.on { background: var(--accent-subtle); border-color: var(--accent-border); color: var(--accent-text); }
.scr-hint { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--text-2); padding: 0.3rem 0.55rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); flex: 0 0 auto; }

.scr-settings, .scr-event { flex: 0 0 auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-sunken); }
.scr-settings-toggle {
    display: flex; align-items: center; gap: 0.4rem; width: 100%; padding: 0.38rem 0.6rem; min-width: 0;
    background: none; border: none; color: var(--text-2); font: inherit; font-size: 0.8rem; font-weight: 650; cursor: pointer; text-align: left;
}
.scr-settings-toggle:hover { color: var(--text); }
.scr-settings-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: var(--radius-md); }
.scr-chev { transition: transform var(--duration) var(--ease); flex: 0 0 auto; }
.open > .scr-settings-toggle .scr-chev { transform: rotate(90deg); }
.scr-settings-summary { flex: 1; min-width: 0; font-weight: 500; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scr-settings-grid {
    display: grid; grid-template-columns: minmax(180px, 2fr) repeat(3, minmax(130px, 1fr)); gap: 0.55rem 0.75rem;
    padding: 0.15rem 0.7rem 0.7rem; border: none; margin: 0; min-width: 0;
}
.scr-f { min-width: 0; }
.scr-f .form-label { margin-bottom: 0.2rem; font-size: 0.74rem; }
.scr-f .form-hint { margin-top: 0.2rem; font-size: 0.72rem; }
.scr-f-wide { grid-column: 1 / -1; }
.scr-bad { color: var(--bad) !important; }
.scr-watch { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; min-width: 0; }
.scr-watch-empty { font-size: 0.78rem; color: var(--text-3); }
.scr-chip { cursor: default; padding: 0.12rem 0.25rem 0.12rem 0.55rem; background: var(--surface-1); }
.scr-chip-x { border: none; background: none; color: var(--text-3); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0.2rem; border-radius: 3px; }
.scr-chip-x:hover { color: var(--bad); }
.scr-chip-x:focus-visible { outline: 2px solid var(--focus); }
.scr-watch-picker { flex: 0 1 220px; min-width: 160px; }

.scr-inline-error { flex: 0 0 auto; margin: 0; padding: 0.45rem 0.6rem; font-size: 0.82rem; font-family: var(--font-mono); }
.scr-inline-error > span { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; }
.scr-x {
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 26px; height: 26px;
    border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--text-3); cursor: pointer;
}
.scr-x:hover { color: var(--text); border-color: var(--border); background: var(--hover); }

.scr-editor { flex: 1 1 auto; min-height: 180px; position: relative; }

.scr-event-body { padding: 0 0.7rem 0.6rem; }
.scr-event-json { font-size: 0.78rem; min-height: 0; resize: vertical; }
.scr-event-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 0.35rem; }
.scr-event-foot .form-hint { margin: 0; }

/* ── Reference ── */
.scr-ref { grid-area: ref; display: flex; flex-direction: column; border-left: 1px solid var(--border); background: var(--surface-1); }
.scr-ref-head { display: flex; align-items: center; justify-content: space-between; padding: 0.65rem 0.6rem 0.35rem 0.85rem; }
.scr-ref-head h3 { font-size: 0.86rem; font-weight: 700; }
.scr-ref-search { position: relative; padding: 0 0.7rem 0.5rem; }
.scr-ref-search > .icon { left: 1.25rem; transform: translateY(calc(-50% - 0.25rem)); }
.scr-ref-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 0.7rem 0.9rem; }
.scr-ref-group { margin: 0.65rem 0 0.25rem; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.scr-ref-list { list-style: none; margin: 0; padding: 0; }
.scr-ref-item { position: relative; padding: 0.4rem 0.45rem 0.45rem; border-radius: var(--radius-sm); border-bottom: 1px solid var(--border); }
.scr-ref-item:last-child { border-bottom: none; }
.scr-ref-item:hover { background: var(--surface-2); }
.scr-ref-sig { display: block; font-family: var(--font-mono); font-size: 0.75rem; color: var(--text); word-break: break-word; padding-right: 3.6rem; }
.scr-ref-title { display: block; font-size: 0.8rem; padding-right: 3.6rem; }
.scr-ref-item p { margin: 0.15rem 0 0; font-size: 0.74rem; color: var(--text-2); line-height: 1.4; }
.scr-ref-insert {
    position: absolute; top: 0.35rem; right: 0.35rem; padding: 1px 7px; font-size: 0.7rem; font-weight: 650;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-1); color: var(--accent-text); cursor: pointer;
}
.scr-ref-insert:hover:not(:disabled) { border-color: var(--accent-border); background: var(--accent-subtle); }
.scr-ref-insert:disabled { opacity: 0.45; cursor: not-allowed; }
.scr-safety { margin-top: 0.9rem; padding: 0.55rem 0.7rem; border-radius: var(--radius-md); border: 1px solid var(--info-border); background: var(--info-bg); font-size: 0.76rem; color: var(--text); }
.scr-safety-title { display: flex; align-items: center; gap: 0.35rem; font-weight: 700; color: var(--info); margin-bottom: 0.25rem; }
.scr-safety ul { margin: 0; padding-left: 1rem; }
.scr-safety li { margin: 0.12rem 0; }
.scr-safety code, .scr-ref-item code, .scr-settings-toggle code { font-family: var(--font-mono); font-size: 0.92em; }

/* ── Console ── */
.scr-console { grid-area: console; display: flex; flex-direction: column; height: 220px; border-top: 1px solid var(--border); background: var(--surface-1); }
.scr-wb.console-tall .scr-console { height: min(440px, 55%); }
.scr-wb.console-collapsed .scr-console { height: auto; }
.scr-console-bar { display: flex; align-items: center; gap: 0.5rem; flex: 0 0 auto; padding: 0 0.5rem 0 0.35rem; min-height: 36px; border-bottom: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.scr-wb.console-collapsed .scr-console-bar { border-bottom: none; }
.scr-tabs { display: flex; align-self: stretch; }
.scr-tab {
    display: inline-flex; align-items: center; gap: 0.35rem; padding: 0 0.7rem; min-height: 36px;
    background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-2); font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.scr-tab:hover { color: var(--text); }
.scr-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.scr-tab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.scr-tab-note { font-size: 0.7rem; font-weight: 700; color: var(--text-3); }
.scr-tab-note.ok { color: var(--ok); }
.scr-tab-note.bad { color: var(--bad); }
.scr-tab .spinner-sm { margin: 0; width: 11px; height: 11px; }
.scr-console-tools { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.scr-console-tools .form-control { width: auto; min-height: 26px; padding-top: 0.1rem; padding-bottom: 0.1rem; font-size: 0.76rem; }
.scr-spacer { flex: 1; }
.scr-tool {
    display: inline-flex; align-items: center; gap: 0.3rem; min-height: 26px; padding: 0 0.5rem;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-1); color: var(--text-2);
    font: inherit; font-size: 0.76rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.scr-tool:hover { color: var(--text); border-color: var(--text-3); }
.scr-tool[aria-pressed="true"] { background: var(--accent-subtle); border-color: var(--accent-border); color: var(--accent-text); }
.scr-tool.icon { width: 26px; padding: 0; justify-content: center; border-color: transparent; background: transparent; }
.scr-tool.icon:hover { border-color: var(--border); background: var(--hover); }
.scr-rot-up { transform: rotate(90deg); }

.scr-log {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0.3rem 0;
    font-family: var(--font-mono); font-size: 0.76rem; line-height: 1.5; background: var(--surface-sunken);
}
.scr-log:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.scr-log-empty { padding: 0.6rem 0.8rem; color: var(--text-3); font-family: var(--font-sans); font-size: 0.8rem; }
.scr-log-line { display: flex; gap: 0.6rem; padding: 0 0.75rem; align-items: baseline; }
.scr-log-line:hover { background: var(--hover); }
.scr-log-line .t { flex: 0 0 auto; color: var(--text-3); font-variant-numeric: tabular-nums; }
.scr-log-line .lvl { flex: 0 0 3.4em; font-size: 0.68rem; font-weight: 700; color: var(--text-3); font-family: var(--font-sans); letter-spacing: 0.03em; }
.scr-log-line .s {
    flex: 0 0 auto; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    padding: 0; border: none; background: none; font: inherit; color: var(--accent-text); cursor: pointer;
}
.scr-log-line .s:hover { text-decoration: underline; }
.scr-log-line .m { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; color: var(--text); }
.scr-log-line.lvl-warn .lvl, .scr-log-line.lvl-warn .m { color: var(--warn); }
.scr-log-line.lvl-error .lvl, .scr-log-line.lvl-error .m { color: var(--bad); }
.scr-log-line.lvl-error { background: var(--bad-bg); }
.scr-log-line.lvl-debug .m { color: var(--text-3); }
.scr-test { flex: 1 1 auto; min-height: 0; display: flex; padding: 0.45rem; background: var(--surface-sunken); }
.scr-test > .sc-console { flex: 1; }

/* ── Toast, dialogs, history ── */
.scr-toast {
    position: absolute; z-index: 60; right: 1rem; bottom: 1rem; max-width: min(460px, calc(100% - 2rem));
    display: flex; align-items: center; gap: 0.5rem; padding: 0.55rem 0.5rem 0.55rem 0.8rem;
    background: var(--surface-raised); border: 1px solid var(--border-strong); border-left: 4px solid var(--ok);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg); font-size: 0.84rem; animation: fade 0.15s var(--ease);
}
.scr-toast > span { flex: 1; min-width: 0; }
.scr-toast.ok > .icon { color: var(--ok); }
.scr-toast.bad { border-left-color: var(--bad); }
.scr-toast.bad > .icon { color: var(--bad); }
.scr-dlg-body { font-size: 0.86rem; color: var(--text); }
.scr-dlg-body p + p { margin-top: 0.5rem; }
.scr-dlg-body code { font-family: var(--font-mono); font-size: 0.9em; }
.scr-history { width: min(620px, 100vw); }
.scr-rev-list { list-style: none; margin: 0.6rem 0 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.scr-rev-list li + li { border-top: 1px solid var(--border); }
.scr-rev {
    display: flex; flex-direction: column; gap: 0.1rem; width: 100%; padding: 0.5rem 0.75rem; text-align: left;
    background: var(--surface-1); border: none; color: var(--text); font: inherit; cursor: pointer;
}
.scr-rev:hover { background: var(--surface-2); }
.scr-rev.active { background: var(--accent-subtle); }
.scr-rev:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.scr-rev-when { font-weight: 650; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.scr-rev-meta { font-size: 0.76rem; color: var(--text-3); }
.scr-rev-preview { margin-top: 0.85rem; display: flex; flex-direction: column; gap: 0.5rem; }
.scr-rev-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; font-size: 0.86rem; }
.scr-rev-preview-head .btn { gap: 0.35rem; }

/* ──────────────────────────── Responsive ──────────────────────────── */
@media (max-width: 1280px) {
    .scr-settings-grid { grid-template-columns: minmax(160px, 1fr) repeat(2, minmax(120px, 1fr)); }
}

/* ≤1024: the reference panel floats over the editor behind its toggle */
@media (max-width: 1024px) {
    .scr-wb, .scr-wb.ref-open { grid-template-columns: 240px minmax(0, 1fr); grid-template-areas: "list main" "list console"; }
    .scr-ref {
        position: absolute; z-index: 40; top: 0; right: 0; bottom: 0; width: min(340px, 92%);
        box-shadow: var(--shadow-xl); animation: drawerIn 0.18s var(--ease);
    }
    .scr-settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .scr-f-name { grid-column: 1 / -1; }
    .scr-pagedesc { display: none; }
}

/* ≤768: one column; the script list becomes a select above the editor; the page scrolls */
@media (max-width: 768px) {
    /* app.css releases full-bleed pages to normal document scrolling on phones */
    .scr-pagebar { padding: 0.5rem 0.75rem; }
    .scr-crumbs, .scr-pagedesc { display: none; }
    .scr-wb, .scr-wb.ref-open { display: flex; flex-direction: column; overflow: visible; flex: none; }
    .scr-list { display: none; }
    .scr-mobile-pick { display: block; }
    .scr-mobile-pick .form-label { margin-bottom: 0.2rem; }
    .scr-main { padding: 0.6rem; }
    .scr-editor { flex: 0 0 auto; height: 58vh; min-height: 280px; }
    .scr-console { height: 260px; }
    .scr-wb.console-tall .scr-console { height: 420px; }
    .scr-ref { position: fixed; top: var(--eng-topbar-h); width: 100%; max-width: none; border-left: none; z-index: 260; }
    .scr-settings-grid { grid-template-columns: minmax(0, 1fr); }
    .scr-toolbar { align-items: flex-start; }
    .scr-actions { width: 100%; }
    .scr-console-tools { order: 5; flex-basis: 100%; padding-bottom: 0.35rem; }
    .scr-log-line { flex-wrap: wrap; gap: 0 0.5rem; }
    .scr-log-line .m { flex-basis: 100%; }
    .scr-toast { position: fixed; right: 0.75rem; bottom: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
    .scr-menu, .scr-ref, .scr-toast { animation: none; }
    .scr-chev { transition: none; }
}
