/* The editor owns the viewport; each content surface owns its scrolling. */
html[data-editor-workspace], html[data-editor-workspace] body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}
html[data-editor-workspace] #calculator {
  position: fixed;
  inset: var(--editor-topbar-height, var(--app-topbar-offset)) 0 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0;
  padding: 0;
  gap: 0;
  overflow: hidden;
  min-height: 0;
}
html[data-editor-workspace] #calculator-return,
html[data-editor-workspace] #calculator-preview-heading,
html[data-editor-workspace] #model-authoring-actions { display: none; }
html[data-editor-workspace] #calculator-workspace-header {
  position: absolute;
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  box-shadow: none;
}
/* Keep live announcements without reserving a row for successful saves. */
html[data-editor-workspace] :is(#central-model-status, #central-domain-module-status):not(.error),
html[data-editor-workspace] .model-file-hint {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
html[data-editor-workspace] :is(#central-model-status, #central-domain-module-status).error {
  position: fixed;
  z-index: 90;
  bottom: 12px;
  left: 12px;
  max-width: min(560px, calc(100vw - 24px));
  margin: 0;
  padding: 10px 14px;
  border: 1px solid #e8c2b7;
  border-radius: 8px;
  background: #fff3ee;
}
.editor-workspace-toolbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  min-width: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.editor-workspace-tabs { display:flex; flex:1 1 auto; min-width:0; align-items:stretch; }
#editor-workspace-tabs > button {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 18px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: .82rem;
}
#editor-workspace-tabs > button[aria-selected="true"] {
  border-bottom-color: var(--green);
  background: white;
  color: var(--ink);
}
#editor-workspace-tabs svg { width: 14px; height: 14px; fill: currentColor; }
html[data-editor-workspace] :is(#editor-getting-started, #app-loading) {
  flex: 1 1 0;
  min-height: 0;
  margin: 0;
  overflow: auto;
}
html[data-editor-workspace] #editor-getting-started { margin: 16px auto 0; padding: 24px; }
html[data-editor-workspace] #model-code-panel {
  flex: 1 1 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}
html[data-editor-workspace] .editor-content {
  height: 100%;
  min-height: 0;
  grid-template-columns: 210px minmax(0, 1fr);
  align-items: stretch;
  gap: 0;
  margin: 0;
}
html[data-editor-workspace] .module-panel {
  min-height: 0;
  padding: 12px 10px;
  border-right: 1px solid var(--line);
  border-radius: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
html[data-editor-workspace] #new-domain-module {
  min-height: 30px;
  margin: 4px 0;
  padding: 4px 9px;
  font-size: .74rem;
}
html[data-editor-workspace] .module-options { margin-top: 8px; gap: 4px; }
html[data-editor-workspace] .module-choice {
  align-items: center;
  gap: 7px;
  padding: 6px 7px;
  border-radius: 5px;
  font-size: .74rem;
  line-height: 1.25;
}
html[data-editor-workspace] .module-choice input { flex: 0 0 auto; margin: 0; }
html[data-editor-workspace] .module-choice span { min-width: 0; gap: 1px; overflow-wrap: anywhere; }
html[data-editor-workspace] .module-choice small { font-size: .65rem; }
html[data-editor-workspace] .code-content,
html[data-editor-workspace] :is(#code-view, #visual-view, #calculation-editor-section, #presentation-section) {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
html[data-editor-workspace] :is(#code-view, #visual-view, #structure-view) { flex: 1 1 0; }
html[data-editor-workspace] #structure-view { min-height: 0; margin: 0; }
html[data-editor-workspace] .code-toolbar { flex: 0 0 auto; padding: 4px 8px; }
html[data-editor-workspace] .code-toolbar:has(.view-toggle[hidden]):has(#unlock-generated-code[hidden]) { display: none; }
html[data-editor-workspace] .view-toggle { padding: 3px; gap: 3px; border-radius: 5px; }
html[data-editor-workspace] .view-toggle button { min-height: 28px; padding: 4px 10px; border-radius: 3px; font-size: .72rem; }
html[data-editor-workspace] .editor-file-toolbar {
  flex-wrap: nowrap;
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0;
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  gap: 0;
  background: #edf1e8;
}
html[data-editor-workspace] .editor-files { flex-wrap: nowrap; gap: 0; align-self: stretch; overflow-x: auto; }
html[data-editor-workspace] .editor-file-tab {
  flex: 0 0 auto;
  max-width: 100%;
  border: 0;
  border-right: 1px solid var(--line);
  border-top: 2px solid transparent;
  border-radius: 0;
  box-shadow: none;
}
html[data-editor-workspace] .editor-file-tab.active { border-top-color: var(--green); background: white; }
html[data-editor-workspace] .editor-file-tab > button {
  min-width: 0;
  min-height: 34px;
  max-width: 240px;
  padding: 6px 10px;
  border-radius: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .75rem;
}
html[data-editor-workspace] .editor-file-actions { gap: 0; padding: 0 4px 0 0; }
html[data-editor-workspace] :is(.editor-file-actions, .editor-history-actions) button { width: 28px; height: 30px; min-height: 30px; padding: 5px; border-radius: 3px; }
html[data-editor-workspace] .editor-history-actions { flex: 0 0 auto; padding-inline: 4px; }
html[data-editor-workspace] #model-code-document {
  display: grid;
  flex: 1 1 0;
  min-height: 0;
  grid-template-rows: minmax(0, var(--editor-model-share, 60fr)) 8px minmax(0, var(--editor-presentation-share, 40fr));
  margin: 0;
  border: 0;
  border-radius: 0;
  background: white;
}
html[data-editor-workspace] #model-code-document:has(#presentation-section[hidden]) { grid-template-rows: minmax(0, 1fr); }
html[data-editor-workspace] #model-code-document:has(#presentation-section[hidden]) .editor-model-splitter { display: none; }
html[data-editor-workspace] :is(.editor-shell, .editor-shell .editor-monaco) { min-height: 0; }
html[data-editor-workspace] .editor-shell {
  flex: 1 1 0;
  height: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: white;
}
html[data-editor-workspace] .editor-shell.native-touch-editor textarea {
  color: var(--ink);
  font-size: 12px;
  padding: 10px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html[data-editor-workspace] #presentation-section { border: 0; }
html[data-editor-workspace] .model-code-document .code-editor-toolbar {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 4px 10px;
  background: #f6f8f3;
  border-bottom: 1px solid var(--line);
  gap: 4px;
}
html[data-editor-workspace] .code-editor-heading { flex-basis: auto; gap: 4px; }
html[data-editor-workspace] .model-code-document .code-editor-toolbar h3 { color: var(--ink); font-size: .73rem; }
html[data-editor-workspace] .code-editor-heading p { display: none; }
html[data-editor-workspace] .model-code-document .code-editor-actions button {
  min-height: 26px;
  padding: 3px 7px;
  border-color: var(--line);
  background: white;
  color: var(--ink);
  font-size: .7rem;
}
.editor-model-splitter {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  background: #e6ebdf;
  cursor: row-resize;
  touch-action: none;
}
.editor-model-splitter::before { content: ''; width: 44px; height: 3px; border-radius: 3px; background: #9aab8f; }
.editor-model-splitter:hover::before, .editor-model-splitter:focus-visible::before { background: var(--green); }
.is-resizing-editor { user-select: none; cursor: row-resize; }
.is-resizing-editor .editor-monaco { pointer-events: none; }
html[data-editor-workspace] .model-files-editor { display: flex; flex-direction: column; flex: 0 0 auto; min-height: 0; margin: 0; }
html[data-editor-workspace] .model-files-editor[data-file-open="true"] { flex: 1 1 0; }
html[data-editor-workspace] .model-file-tabs { flex: 0 0 auto; flex-wrap: nowrap; gap: 0; margin: 0; overflow: auto; border-bottom: 1px solid var(--line); background: #edf1e8; }
html[data-editor-workspace] .model-file-tabs button { flex: 0 0 auto; min-height: 30px; padding: 5px 12px; border: 0; border-top: 2px solid transparent; border-right: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--muted); font-size: .72rem; white-space: nowrap; }
html[data-editor-workspace] .model-file-tabs button[aria-selected="true"] { border-top-color: var(--green); background: white; color: var(--ink); box-shadow: none; }
html[data-editor-workspace] .model-file-tab { border-top: 2px solid transparent; border-right: 1px solid var(--line); }
html[data-editor-workspace] .model-file-tab.model-file-selected { border-top-color: var(--green); background: white; box-shadow: none; }
html[data-editor-workspace] .model-file-tab > [role="tab"] { border: 0; background: transparent; }
html[data-editor-workspace] #model-files-editor .model-file-delete { width: 28px; padding: 5px; border: 0; }
html[data-editor-workspace] #model-files-editor .model-file-add { width: 32px; padding: 0; border: 0; font-size: 1.2rem; }
html[data-editor-workspace] #model-files-editor .model-file-rename { flex: 0 0 auto; width: 150px; min-height: 26px; height: 26px; padding: 3px 7px; border-radius: 3px; font-size: .72rem; }
html[data-editor-workspace] .model-file-panel { display: flex; flex-direction: column; flex: 1 1 0; min-height: 0; }
html[data-editor-workspace] .model-file-status { flex: 0 0 auto; margin: 0; padding: 4px 8px; font-size: .7rem; }
html[data-editor-workspace] .blockly-container { flex: 1 1 0; height: 100%; min-height: 0; margin: 0; }
html[data-editor-workspace] .miniapp-host {
  --preview-canvas-padding: 12px;
  --miniapp-top-spacing: var(--preview-canvas-padding);
  flex: 1 1 0;
  min-height: 0;
  margin: 0;
  /* Top space belongs to the content so it scrolls away above sticky headers. */
  padding: 0 var(--preview-canvas-padding) var(--preview-canvas-padding);
  background: var(--miniapp-page-background, var(--paper));
  color-scheme: var(--miniapp-page-color-scheme, light);
  border: 0;
  border-radius: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
#editor-modules-toggle { display: none; }
@media (max-width: 700px) {
  html[data-editor-workspace] .editor-content { grid-template-columns: minmax(0, 1fr); }
  html[data-editor-workspace] #editor-modules-toggle {
    display: inline-flex;
    flex: 0 0 32px;
    align-items: center;
    justify-content: center;
    width: 32px;
    min-height: 32px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--green-pale);
    color: var(--green-dark);
    font-size: .85rem;
    font-weight: 700;
  }
  html[data-editor-workspace] #editor-modules-toggle[aria-expanded="true"] { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
  html[data-editor-workspace] #module-panel[popover] {
    position: fixed;
    inset: var(--editor-module-menu-top) auto auto var(--editor-module-menu-left);
    width: min(320px, calc(100vw - 24px));
    max-height: calc(100dvh - var(--editor-module-menu-top) - 12px);
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: var(--surface-soft);
    box-shadow: 0 8px 24px #17201b33;
  }
  html[data-editor-workspace] .module-choice { gap: 4px; padding: 5px 4px; font-size: .68rem; }
  html[data-editor-workspace] .module-choice small { display: none; }
  html[data-editor-workspace] .code-editor-toolbar { flex-wrap: nowrap; }
  html[data-editor-workspace] .code-editor-heading h3 { font-size: .65rem; }
  html[data-editor-workspace] .calculation-editor-section .code-editor-heading { flex-wrap: nowrap; min-width: 0; }
  html[data-editor-workspace] .code-editor-actions button { font-size: .6rem; padding: 3px 4px; }
  #editor-workspace-tabs > button { min-width:0; padding-inline:8px; font-size:.76rem; }
}

html[data-editor-workspace] .editor-files { flex: 0 1 auto; min-width: 0; }
html[data-editor-workspace] .editor-completion-help {
  flex: 1 1 0; min-width: 28px; width: 0; min-height: 30px; padding: 4px 6px;
  border: 0; background: transparent; color: var(--muted); font-size: .7rem;
  text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
html[data-editor-workspace] .editor-completion-toggle { color: var(--green); background: transparent; }
html[data-editor-workspace] .editor-completion-toggle[aria-pressed="true"] { background: #d7eadf; box-shadow: inset 0 0 0 1px #478561; }
html[data-editor-workspace] .editor-completion-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.editor-completion-detail { max-width: min(320px, 90vw); padding: 10px 14px; border: 1px solid var(--line); border-radius: 6px; font-size: .8rem; color: var(--text); background: white; }

.miniapp-host { display:block; min-width:0; width:100%; }
.miniapp-host[hidden] { display:none; }

/* Editor settings stay in the portal; only the preview consumes app tokens. */
.miniapp-theme-picker { position:relative; flex:0 0 auto; margin-left:auto; font-size:13px; z-index:85; }
.miniapp-theme-picker > summary { display:grid; place-items:center; width:36px; height:36px; min-height:36px; padding:6px; border:1px solid var(--line); border-radius:8px; color:var(--green-dark); background:var(--green-pale); cursor:pointer; list-style:none; }
.miniapp-theme-picker > summary::-webkit-details-marker { display:none; }
.miniapp-theme-picker > summary svg { display:block; width:22px; height:22px; fill:none; stroke:currentColor; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }
.miniapp-theme-picker[open] > summary { border-color:var(--green); box-shadow:inset 0 0 0 1px var(--green); }
.miniapp-theme-picker > fieldset { position:absolute; top:100%; right:0; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; width:min(480px,calc(100vw - 32px)); max-height:60dvh; overflow:auto; padding:12px; border:1px solid var(--line); border-radius:8px; background:var(--panel); box-shadow:0 8px 24px #17201b33; }
.miniapp-theme-picker legend { padding:0 4px; font-size:13px; }
.miniapp-theme-picker label { display:flex; align-items:center; gap:6px; min-width:0; padding:8px; border:2px solid transparent; border-radius:6px; cursor:pointer; }
.miniapp-theme-picker label:has(input:checked) { border-color:var(--green); background:var(--green-pale); }
.miniapp-theme-picker label:focus-within { outline:2px solid var(--green); outline-offset:2px; }
.miniapp-theme-picker input { margin:0; width:16px; height:16px; }
.miniapp-theme-picker [data-palette] { display:flex; flex:0 0 27px; height:24px; overflow:hidden; border:1px solid var(--line); border-radius:4px; }
.miniapp-theme-picker i { flex:1; }
.miniapp-theme-picker strong,.miniapp-theme-picker small { display:block; line-height:1.3; overflow-wrap:anywhere; }
.miniapp-theme-picker small { color:var(--muted); }
.model-code-document .code-editor-actions .editor-ai-action { display:inline-flex; flex:0 0 32px; width:32px; height:32px; min-height:32px; padding:6px; border-color:var(--line); color:var(--green-dark); background:var(--green-pale); }
.model-code-document .code-editor-actions .editor-ai-action .ai-prompt-icon { display:block; width:18px; height:18px; }
.model-code-document .code-editor-actions .editor-ai-action:hover:not(:disabled) { border-color:var(--green); color:var(--green-dark); background:var(--green-pale); }
@media (any-pointer:coarse) {
 .miniapp-theme-picker > summary,.miniapp-theme-picker label { min-height:44px; }
 .miniapp-theme-picker > summary { width:44px; height:44px; }
 .model-code-document .code-editor-actions .editor-ai-action { flex-basis:44px; width:44px; height:44px; min-height:44px; }
}
