@import url("./download-dialog.css");
@import url("./template-environment.css");

/* Immersive workspace. Assets keep ownership of the document inside the iframe. */
body[data-visual-editor][data-editor-open="true"] { display: flex; flex-direction: column; min-height: 100dvh; }
body[data-visual-editor] .global-topbar { flex: 0 0 auto; }
body[data-visual-editor] .global-context { display: grid; grid-template-columns: minmax(max-content, 1fr) minmax(0, auto) minmax(max-content, 1fr); padding-block: 6px; }
body[data-visual-editor] .global-context .editor-preview-tools { justify-self: start; }
body[data-visual-editor] .global-context .visual-asset-title { min-width: 0; max-width: none; margin: 0; color: var(--muted); font: 500 12px/1.4 var(--sans); text-align: center; overflow-wrap: anywhere; }
.visual-preview-actions { display: flex; align-items: center; justify-self: end; gap: 10px; }
.visual-view-switch { display: flex; align-items: center; gap: 4px; margin-left: auto; padding: 0; flex: 0 0 auto; }
.visual-view-switch button { min-height: 36px; padding: 0 12px; border: 0; border-radius: var(--radius-control); color: var(--muted); background: transparent; font: 12px var(--sans); white-space: nowrap; cursor: pointer; }
.visual-view-switch button:enabled:hover, .visual-view-switch button[aria-pressed="true"] { color: var(--text); background: var(--surface); }
.visual-view-switch button:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.visual-view-switch button[aria-pressed="true"] { box-shadow: inset 0 -2px 0 var(--accent), var(--control-inset-shadow); }
.visual-view-switch__light { width: 5px; height: 5px; margin: 0 8px; border-radius: 50%; background: #fff; box-shadow: 0 0 3px #fff, 0 0 8px rgb(255 255 255 / 90%), 0 0 16px rgb(255 255 255 / 60%); animation: visual-light-flicker 60s linear infinite; animation-delay: 60s; }
.visual-view-switch:has(> button[data-preview-state="asset"][aria-pressed="true"]) .visual-view-switch__light { background: var(--line); box-shadow: none; animation: none; }
@keyframes visual-light-flicker { 0%, .35%, .8%, 100% { opacity: 1; } .15%, .6% { opacity: .2; } }
.visual-primary { display: inline-flex; justify-content: center; align-items: center; gap: 9px; min-height: 38px; padding: 0 15px; border: 1px solid transparent; border-radius: var(--radius-control); background: var(--accent); color: var(--text-on-action); font-size: 12px; font-weight: 500; cursor: pointer; box-shadow: var(--control-raised-shadow); }
.visual-primary:hover { background: var(--accent-soft); }
.visual-primary:enabled:active,
.visual-dock:enabled:active,
.visual-tools .editor-dimension-lock:enabled:active,
.visual-tools .editor-image-clear:enabled:active,
.visual-tools .editor-image-upload:not(:disabled) + label:active { box-shadow: var(--control-inset-shadow); }
.visual-primary:disabled,
.visual-dock:disabled,
.visual-tools .editor-dimension-lock:disabled,
.visual-tools .editor-image-clear:disabled { box-shadow: none; }
.visual-primary img { width: 15px; height: 15px; filter: var(--action-on-primary-icon-filter); }
.visual-icon { display: grid; place-items: center; width: 28px; height: 30px; flex-shrink: 0; padding: 0; border: 0; border-radius: var(--radius-control); background: transparent; color: var(--muted); font-size: 19px; cursor: pointer; }
.visual-icon:hover { background: var(--panel-active); color: var(--strong); }
.visual-tools__close, .visual-tools__close:hover { color: #ef7777; }
.theme-light .visual-tools__close, .theme-light .visual-tools__close:hover { color: #b52b35; }
.visual-tools__close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: square; }
body[data-visual-editor] .detail-main { flex: 1; width: 100%; min-height: 0; margin: 0; padding: 0; }
body[data-visual-editor] .workbench { position: relative; height: 100%; border: 0; border-radius: var(--radius-control); overflow: hidden; }
body[data-visual-editor] .workbench__layout { display: block; width: 100%; height: 100%; padding: 0; }
body[data-visual-editor] .detail-preview { display: block; height: 100%; min-height: 0; border: 0; border-radius: var(--radius-control); }
body[data-visual-editor] .detail-preview__canvas { display: block; height: 100%; min-height: 0; padding: 0; overflow: hidden; background: transparent; }
body[data-visual-editor] .detail-preview__device { position: relative; inset: auto; width: 100%; height: 100%; min-height: 0; max-height: none; aspect-ratio: auto; border: 0; box-shadow: none; transform: none; border-radius: var(--radius-control); }
body[data-visual-editor] .detail-preview iframe { display: block; position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; border: 0; border-radius: var(--radius-control); }
body[data-visual-editor] .visual-tools { position: fixed; z-index: 50; top: 0; left: 0; width: 324px; max-height: var(--floating-panel-max-height, calc(100dvh - 24px)); height: auto; display: flex; flex-direction: column; gap: 0; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--surface-translucent); box-shadow: 0 18px 50px #0004, 0 2px 8px #0003; backdrop-filter: blur(20px); }
.visual-tools__header { display: flex; flex-shrink: 0; align-items: center; min-height: 48px; padding: 5px 10px 5px 14px; gap: 2px; border-bottom: 1px solid var(--line-soft); }
.visual-tools__drag { flex: 1; display: flex; align-items: center; gap: 10px; padding: 4px 0; border: 0; background: transparent; color: var(--text); text-align: left; font-size: 12px; font-weight: 500; touch-action: none; cursor: grab; border-radius: var(--radius-control); }
.visual-tools__drag > [aria-hidden] { font-size: 22px; color: var(--muted-low); }
.visual-tools[data-dragging] .visual-tools__drag { cursor: grabbing; }
.visual-tools[data-dragging] { user-select: none; }
.visual-tools__body { overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; min-height: 0; padding: 0 14px; }
.visual-tools .editor-preset-list { display: grid; grid-template-columns: 1fr 28px minmax(90px,1.3fr) 28px; padding: 13px 0 10px; margin: 0; border: 0; gap: 4px; }
.visual-tools .editor-preset-list__label { font-size: 10px; color: var(--muted-low); font-weight: 400; text-transform: none; }
.visual-tools .editor-preset-select { height: 29px; min-height: 29px; font-size: 11px; }
.visual-tools .editor-preset-step { min-height: 29px; height: 29px; border: 0; background: transparent; font-size: 17px; box-shadow: none; border-radius: var(--radius-control); }
.visual-tools .editor-preset-list__label-group .editor-help { display: none; }
.visual-tools .editor-control-deck { padding: 0; border: 0; background: transparent; border-radius: var(--radius-control); }
.visual-tools .editor-control-deck__navigation { margin: 0 -5px; border: 0; padding: 0; }
.visual-tools .editor-control-deck__tabs { display: flex; gap: 0; padding: 0; border-bottom: 1px solid var(--line); background: transparent; }
.visual-tools .editor-control-deck__tab { flex: 1 0 auto; min-height: 36px; padding: 0 7px; border: 0; border-bottom: 2px solid transparent; border-radius: var(--radius-control); background: transparent; font-size: 10px; font-weight: 400; letter-spacing: 0; }
.visual-tools .editor-control-deck__tab[aria-selected="true"] { color: var(--text-strong); background: var(--accent-soft-wash); border-color: var(--accent); }
.visual-tools .editor-control-deck__workspace { height: auto; min-height: 0; max-height: none; overflow: visible; padding: 15px 0 6px; border: 0; background: transparent; border-radius: var(--radius-control); }
.visual-tools .editor-control-panel { min-height: 0; padding: 0; }
.visual-tools .editor-control-panel__header { display: none; }
.visual-tools .editor-control-panel__fields { display: grid; gap: 14px; padding: 0; border: 0; background: transparent; border-radius: var(--radius-control); }
.visual-tools .editor-field { display: grid; grid-template-columns: minmax(90px, 1fr) minmax(65px, 1.05fr) 50px; gap: 8px; min-height: 30px; }
.visual-tools .editor-field__label { font-size: 11px; font-weight: 400; }
.visual-tools .editor-field__label-group { gap: 3px; }
.visual-tools .editor-field__output { font-size: 10px; color: var(--muted); }
.visual-tools .editor-help__button { width: 14px; height: 14px; opacity: .45; }
.visual-tools .editor-help__button svg { width: 12px; height: 12px; }
.visual-tools .editor-field--segmented { grid-template-columns: 1fr; gap: 7px; }
.visual-tools .editor-field--segmented .editor-field__label-group { grid-column: 1; grid-row: 1; }
.visual-tools .editor-segmented { grid-column: 1 / -1; grid-row: 2; display: grid; padding: 0; gap: 4px; border: 0; background: transparent; border-radius: var(--radius-control); }
.visual-tools .editor-segmented__option > .editor-option__copy { min-height: 33px; border: 1px solid var(--line); border-radius: var(--radius-control); font-size: 11px; background: transparent; }
.visual-tools .editor-segmented__option input:checked + .editor-option__copy { border-color: var(--accent); background: var(--accent-soft-wash); color: var(--text-strong); }
.visual-tools .editor-option__preview { display: none; }
.visual-tools .editor-control-panel .editor-segmented__option--visual > .editor-option__copy { min-height: 33px; }
.visual-tools .editor-field select, .visual-tools .editor-field input[type="text"], .visual-tools .editor-field input[type="url"] { width: 100%; min-width: 0; min-height: 32px; padding: 5px 8px; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--control); color: var(--text); font-size: 11px; }
.visual-tools .editor-field--url, .visual-tools .editor-field--text, .visual-tools .editor-field--image { grid-template-columns: 1fr; gap: 7px; }
.visual-tools .editor-field--url input, .visual-tools .editor-field--text input, .visual-tools .editor-field--image select { grid-column: 1 / -1; grid-row: auto; }
.visual-tools .editor-field--image .editor-field__label-group { grid-row: auto; }
.visual-tools .editor-media-preview { width: 100%; height: 118px; border-radius: var(--radius-control); object-fit: cover; background: var(--control); }
.visual-tools .editor-media-error { color: var(--text); font-size: 11px; }
.visual-tools .editor-repeat { margin: 0; padding: 12px 0 0; border: 0; border-top: 1px solid var(--line-soft); background: transparent; border-radius: var(--radius-control); }
.visual-tools .editor-repeat__fields { gap: 12px; padding-top: 10px; }
.visual-tools .visual-tools__footer { display: flex; flex-wrap: wrap; flex-shrink: 0; align-items: center; gap: 4px; padding: 12px; margin: 0; border: 0; border-top: 1px solid var(--line); background: transparent; border-radius: var(--radius-control); }
.visual-tools__footer > button { flex: 0 0 auto; min-height: 36px; min-width: 29px; padding: 0 7px; border: 0; border-radius: var(--radius-control); background: transparent; font-size: 11px; box-shadow: none; }
.visual-tools__footer > [data-editor-history="reset"] { flex: 1; min-width: min-content; }
.visual-tools__footer > button:active:not(:disabled) { box-shadow: none; }
.visual-tools__footer > button[data-editor-history="undo"], .visual-tools__footer > button[data-editor-history="redo"] { font-size: 20px; }
.visual-tools__footer > button:disabled { opacity: .3; cursor: default; }
.visual-tools__footer > .visual-primary { min-height: 38px; padding-inline: 12px; background: var(--accent); color: var(--text-on-action); box-shadow: var(--control-raised-shadow); }
.visual-tools__footer > .visual-primary:hover { background: var(--accent-soft); }
.visual-tools__footer > .visual-primary:enabled:active { box-shadow: var(--control-inset-shadow); }
.visual-tools__footer > .visual-primary:disabled { box-shadow: none; }
.visual-tools__footer > [data-editor-download] { flex-basis: 100%; }
.visual-preview-status { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
.visual-preview-status:is([data-state="failed"], [data-state="error"]) { display: block; position: static; width: auto; height: auto; clip-path: none; padding: 8px 14px; font-size: 11px; overflow-wrap: anywhere; }
.visual-preview-notice { width: min(1440px, 100%); margin: 0 auto; }
body[data-visual-editor][data-editor-open="false"] .workbench { height: auto; min-height: 0; }
.visual-overview { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }
@media (max-width: 1100px) {
  body[data-visual-editor] .global-context .visual-asset-navigation { grid-column: 1 / -1; grid-row: 1; }
  body[data-visual-editor] .global-context .editor-preview-tools { grid-column: 1; grid-row: 2; }
  .visual-preview-actions { grid-column: 3; grid-row: 2; }
}
@media (max-width: 760px) {
  body[data-visual-editor] .global-context { display: flex; flex-wrap: wrap; row-gap: 0; padding-block: 4px; }
  body[data-visual-editor] .global-context .visual-asset-navigation { order: -1; flex-basis: 100%; }
  .visual-preview-actions { margin-left: auto; }
  body[data-visual-editor] .workbench__layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--preview-gap, 8px); }
  body[data-visual-editor] .global-context .editor-preview-tools { flex-basis: 100%; }
  body[data-visual-editor] .editor-preview-tools .editor-viewport { flex: 1; min-width: 0; }
  .visual-tools__header { min-height: 42px; }
  .visual-tools__drag { cursor: default; touch-action: auto; font-size: 11px; }
  .visual-tools__drag > [aria-hidden] { display: none; }
  .visual-tools .visual-tools__footer { padding: 9px 12px; }
}
@media (prefers-reduced-motion: reduce) { .visual-tools, .visual-view-switch button { transition: none; } .visual-view-switch__light { animation: none; } }
.visual-tools .editor-control-panel__fields > .editor-field { background: transparent; }
.visual-tools .editor-image-actions { position: relative; display: flex; gap: 6px; }
.visual-tools .editor-image-upload { position: absolute; width: 1px; height: 1px; opacity: 0; }
.visual-tools .editor-image-upload-label, .visual-tools .editor-image-clear { display: inline-flex; align-items: center; justify-content: center; min-height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--control); color: var(--text); cursor: pointer; font: 11px var(--sans); box-shadow: var(--control-raised-shadow); }
.visual-tools .editor-image-upload:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.visual-tools .editor-image-upload:disabled + label { opacity: .5; cursor: progress; box-shadow: none; }

/* Expanded contracts keep their existing advanced controls available in the panel. */
body[data-asset-experience] .visual-advanced { border-top: 1px solid var(--line); padding: 12px 0; }
body[data-asset-experience] .visual-advanced > summary { color: var(--muted); cursor: pointer; font-size: 11px; }
body[data-asset-experience] .visual-advanced[open] > summary { margin-bottom: 12px; }
body[data-asset-experience] .visual-tools textarea { width: 100%; min-height: 76px; resize: vertical; border: 1px solid var(--line); background: var(--control); color: var(--text); padding: 8px; font: 12px/1.5 var(--sans); box-shadow: var(--control-inset-shadow); border-radius: var(--radius-control); }
body[data-asset-experience] .visual-tools .editor-field--textarea { grid-template-columns: 1fr; gap: 7px; }
body[data-asset-experience] .visual-tools .editor-action-list { padding: 10px 0; }

/* Saved-work actions live in the panel; startup failures retain a preview notice. */
body[data-visual-editor] .detail-preview { position: relative; }
[data-draft-recovery] {
  position: absolute;
  z-index: 3;
  inset: auto auto 12px 12px;
  max-width: calc(100% - 24px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line-soft);
  background: var(--surface-translucent);
  color: var(--text);
  border-radius: var(--radius-control);
}
[data-draft-recovery] .visual-preview-status:is([data-state="failed"], [data-state="error"], [data-editor-draft-state]:not([hidden])) {
  position: static;
  width: auto;
  height: auto;
  clip-path: none;
  overflow: visible;
}
[data-draft-recovery] details { max-width: 100%; }
[data-draft-recovery] details[open] { flex-basis: 100%; }
[data-draft-recovery] button { min-height: 32px; padding: 4px 8px; }

/* The flow row and displayed device bounds are separate from the composition. */
body[data-visual-editor] .detail-main { flex: 0 0 auto; }
body[data-visual-editor] .workbench { height: auto; padding: var(--preview-gap, 16px); overflow: visible; background: transparent; container-type: normal; }
body[data-visual-editor] .workbench__layout { height: auto; }
body[data-visual-editor] .detail-preview { height: auto; }
body[data-visual-editor] .detail-preview__canvas {
  display: grid; place-items: center; width: min(1440px, 100%);
  height: var(--preview-area-height, 70dvh); margin: 0 auto;
}
body[data-visual-editor] .detail-preview__canvas .detail-preview__device {
  position: relative; inset: auto; width: var(--preview-displayed-width, 100%);
  height: var(--preview-displayed-height, 100%); transform: none;
}
body[data-visual-editor] .detail-preview iframe {
  width: var(--preview-width, 100%); height: var(--preview-height, 100%);
  transform: scale(var(--preview-scale, 1)); transform-origin: top left;
}

body[data-visual-editor] .detail-preview__canvas[data-template-environment] { padding: 0; background: transparent; }
body[data-visual-editor] .detail-preview__device[data-preview-state="asset"] {
  z-index: 1; background: transparent; box-shadow: none;
}
/* Match the isolated document scheme: WebKit otherwise paints a white iframe canvas. */
body[data-visual-editor] .detail-preview__device[data-preview-state="asset"] iframe {
  background: transparent; color-scheme: light;
}
body[data-visual-editor] [data-draft-recovery] {
  position: relative; inset: auto; max-width: 1440px; margin: 0 auto;
}
.visual-tools [data-draft-recovery] { max-width: 100%; padding: 12px 0; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; font-size: 11px; border-radius: var(--radius-control); }
.visual-tools [data-draft-recovery] details[open] { display: grid; gap: 6px; }
[data-draft-recovery] details[hidden] { display: none; }
.visual-tools [data-draft-recovery] summary { cursor: pointer; }
.visual-tools [data-draft-recovery] button { font-size: 11px; text-align: left; }
body[data-visual-editor] [data-draft-recovery][data-attention="false"]:not(:has([data-state="error"])) { padding: 0; border: 0; }
body[data-visual-editor] [data-draft-recovery][data-attention="false"]:not(:has([data-state="error"])) > details { display: none; }
[data-draft-recovery] .visual-preview-status { margin: 0; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
body[data-visual-editor][data-editor-open="true"][data-preview-page-scroll] {
  height: auto; min-height: 100dvh; overflow: auto;
}

.visual-tools .editor-field--range { grid-template-columns: minmax(90px, 1fr) minmax(0, 1.5fr); row-gap: 2px; padding-inline-end: 4px; }
.visual-tools .editor-field--range .editor-field__output { grid-column: 2; grid-row: 2; white-space: normal; overflow-wrap: anywhere; text-align: right; }

.visual-tools .editor-field--range input[type="range"] { grid-column: 2; grid-row: 1; min-width: 0; box-sizing: border-box; }
.visual-tools .editor-field--range input[type="range"]:focus-visible { outline: none; }
:root:not([data-focus-input="pointer"]) .visual-tools .editor-field--range input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--text-strong); outline-offset: 3px; }
:root:not([data-focus-input="pointer"]) .visual-tools .editor-field--range input[type="range"]:focus-visible::-moz-range-thumb { outline: 2px solid var(--text-strong); outline-offset: 3px; }

.visual-tools__footer > [hidden] { display: none; }

body[data-visual-editor] .workbench:has(+ .related-strip) { padding-bottom: 0; }

.component-tabs{display:flex;gap:24px;padding:12px 18px;border-bottom:1px solid var(--border,#dadbd6);flex-shrink:0;overflow:auto}
.component-tabs[hidden]{display:none}
.component-tabs button{border:0;background:none;cursor:pointer;font-family:inherit;color:inherit;text-decoration:none;font-size:12px;white-space:nowrap;padding:4px 0;border-bottom:2px solid transparent; border-radius: var(--radius-control); }
.component-tabs button[aria-selected="true"]{border-bottom-color:currentColor;box-shadow:var(--control-inset-shadow)}
.component-tabs button:focus-visible{outline:2px solid currentColor;outline-offset:3px}

/* Opt-in dimension editing aid; existing sliders keep their layout. */
.visual-tools .editor-dimension-value { grid-column: 2; grid-row: 2; justify-self: end; white-space: nowrap; }
.visual-tools .editor-dimension-number { width: 72px; min-height: 32px; min-width: 0; padding: 3px; border: 1px solid var(--line); background: var(--control); color: var(--text); font: inherit; box-shadow: var(--control-inset-shadow); border-radius: var(--radius-control); }
.visual-tools .editor-dimension-lock { grid-column: 1 / -1; min-height: 36px; border: 1px solid var(--line); background: var(--control); color: var(--text); font: inherit; cursor: pointer; box-shadow: var(--control-raised-shadow); border-radius: var(--radius-control); }
.visual-tools .editor-dimension-lock[aria-pressed="true"]:enabled { border-color: var(--text-strong); font-weight: 600; box-shadow: var(--control-inset-shadow); }

/* Keep every threshold independently available in a single palette row. */
.visual-tools .editor-color-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }
.visual-tools .editor-color-row legend { margin-bottom: 10px; }
.visual-tools .editor-color-row .editor-field { display: flex; flex-direction: column; min-width: 0; gap: 6px; }
.visual-tools .editor-color-row .editor-field__heading { display: block; }
.visual-tools .editor-color-row .editor-field__label { font-size: 11px; }
.visual-tools .editor-color-row .editor-field__output { display: block; font-size: 9px; }
.visual-tools .editor-color-row input[type="color"] { width: 100%; min-width: 0; min-height: 44px; }

.visual-tools .editor-field__hint { margin: 6px 0 0; font-size: 11px; line-height: 1.45; color: var(--muted); }

/* Preview dimensions remain readable without drawing a border over the asset. */
.visual-preview-metrics { display: flex; align-items: center; min-height: 32px; max-width: 1440px; margin: 0 auto; color: var(--muted); font: 11px/1.5 var(--sans); font-variant-numeric: tabular-nums; }
body[data-editor-open="true"] .visual-preview-metrics { display: none; }
body[data-visual-editor] .detail-preview__canvas > .template-environment { inset: calc((100% - var(--preview-displayed-height, 100%)) / 2) auto auto calc((100% - var(--preview-displayed-width, 100%)) / 2); width: var(--preview-displayed-width, 100%); height: var(--preview-displayed-height, 100%); }
.visual-tools__heading { display: grid; gap: 3px; }
.visual-tools__heading small { color: var(--muted); font-size: 10px; font-weight: 400; }
.visual-tools__drag:disabled { opacity: 1; }

/* Same chevrons as the related carousel, with full touch targets by the name. */
.visual-asset-navigation {
  display: flex; align-items: center; justify-content: center; gap: 4px; min-width: 0;
  touch-action: pan-y pinch-zoom; user-select: none;
}
.visual-asset-navigation__arrow {
  display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px;
  color: var(--text); text-decoration: none;
}
.visual-asset-navigation__arrow:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* The initial document is the current workspace, not a small legacy iframe.
   Keep the page surface while its iframe has no prepared document. The normal
   black Asset-only host returns with the live preview, including its entrance. */
body[data-visual-editor] .detail-preview__canvas:is([data-preview-initializing], :has(iframe:not([data-asset-viewport-ready="true"]))) {
  background: var(--bg);
}
body[data-visual-editor] .detail-preview__canvas:is([data-preview-initializing], :has(iframe:not([data-asset-viewport-ready="true"]))) > .template-environment {
  display: none;
}
body[data-visual-editor] iframe[data-template-frame]:not([data-asset-viewport-ready="true"]) { opacity: 0; }
/* The viewport sets inline opacity once sized, before the editor can accept input. */
body[data-visual-editor] [data-preview-initializing] iframe[data-template-frame] { opacity: 0 !important; }
.visual-preview-loading {
  position: absolute; inset: 50% 0 auto; margin: 0; text-align: center;
  color: var(--muted); font: 12px/1.5 var(--sans); pointer-events: none;
}
.detail-preview__canvas:not([data-preview-initializing]):has(iframe[data-asset-viewport-ready="true"]) > .visual-preview-loading { display: none; }

/* The accepted icon rail and drawer are editor chrome, never asset styles. */
body[data-visual-editor] .workbench__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 0;
  align-items: start;
  background: transparent;
}
body[data-visual-editor] .visual-tools {
  --rail-padding: 10px;
  position: relative;
  inset: auto;
  width: 64px;
  height: auto;
  max-height: none;
  margin-top: calc(var(--preview-readout-height, 32px) + var(--bar-offset-y, 0px));
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  color: var(--text);
  z-index: 50;
}
.editor-icon-tools { --rail-contour: color-mix(in srgb, currentColor 9%, transparent); outline: 1px solid var(--rail-contour); outline-offset: -1px; display: flex; flex-direction: column; align-items: center; gap: 12px; height: var(--bar-height, 80dvh); padding: var(--rail-padding); background: var(--panel); border-radius: 6px; }
.editor-icon-tools > [hidden] { display: none; }
.editor-icon-spacer { flex: 1; width: 100%; min-height: 0; }
.editor-icon-float, .editor-icon-move { width: 44px; height: 28px; min-height: 24px; flex: 0 0 28px; padding: 0; border: 1px solid var(--rail-contour); border-radius: 6px; background: var(--panel); color: var(--text); font: 11px var(--sans); cursor: pointer; }
.editor-icon-move { height: 24px; flex-basis: 24px; font-size: 20px; cursor: grab; touch-action: none; user-select: none; }
.editor-icon-move:active { cursor: grabbing; }
.editor-icon-float:focus-visible, .editor-icon-move:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
body[data-visual-editor][data-editor-docked="false"] .visual-tools { position: fixed; inset: 0 auto auto 0; margin: 0; min-height: 0; }
body[data-visual-editor][data-editor-docked="false"] .workbench__layout { grid-template-columns: minmax(0, 1fr); }
body[data-editor-docked="false"] .editor-icon-tools { height: auto; max-height: var(--bar-height); background: var(--chrome-translucent); border-radius: 6px; box-shadow: 0 8px 28px var(--shadow-medium); backdrop-filter: blur(20px); cursor: grab; }
body[data-editor-docked="false"] .editor-icon-spacer { flex: none; border-top: 1px solid var(--rail-contour); touch-action: none; }
.visual-tools[data-dragging] .editor-icon-tools { cursor: grabbing; }
body[data-editor-docked="false"] .editor-icon-rail { min-height: 0; max-height: none; }
.visual-tools[data-drawer-side="right"] .editor-drawer { right: auto; left: 64px; }
.editor-icon-download { width: 44px; height: 44px; min-height: 44px; flex: 0 0 44px; padding: 10px; border-color: var(--rail-contour); border-radius: 6px; }
.editor-icon-download img { width: 22px; height: 22px; }
.editor-icon-save { display: grid; place-items: center; position: relative; width: 44px; height: 44px; flex: 0 0 44px; padding: 10px; border: 1px solid var(--rail-contour); border-radius: 6px; background: var(--panel); color: var(--text); cursor: pointer; }
.editor-icon-save svg { width: 22px; height: 22px; }
.editor-icon-save[aria-pressed="true"] svg { fill: currentColor; }
.editor-icon-save span { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.editor-icon-save:disabled { opacity: .5; cursor: default; }
.editor-icon-download:focus-visible, .editor-icon-save:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.editor-icon-rail {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: max(48px, calc(var(--bar-height, 80dvh) - 180px - var(--rail-padding) - var(--rail-padding)));
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 2px;
}
.editor-icon-rail > [role="tablist"] { display: flex; flex: none; flex-direction: column; gap: inherit; }
.editor-preview-background { padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.editor-background-toggle::before { content: ""; width: 21px; height: 21px; border: 1px solid var(--muted); border-radius: 50%; background: linear-gradient(135deg, #000 65%, #fff 65%); forced-color-adjust: none; }
.editor-background-toggle[aria-pressed="true"]::before { background: linear-gradient(135deg, #fff 65%, #000 65%); }
.editor-icon-rail__tab, .editor-background-toggle, .preview-rotation__toggle {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid var(--rail-contour);
  border-radius: 6px;
  background: linear-gradient(135deg, var(--control), var(--panel));
  color: var(--text);
  cursor: pointer;
}
.editor-icon-rail__tab:hover, .editor-background-toggle:hover, .preview-rotation__toggle:hover { background: var(--panel-active); }
.editor-icon-rail__tab[aria-selected="true"], .preview-rotation__toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-wash), 0 0 14px var(--accent-soft-wash);
  background: linear-gradient(135deg, var(--action-active-surface), var(--panel));
}
.editor-icon-rail__tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.editor-icon-rail__tab:focus-visible, .editor-background-toggle:focus-visible, .preview-rotation__toggle:focus-visible, .editor-drawer button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.editor-drawer {
  position: absolute;
  top: 0;
  right: 64px;
  display: flex;
  flex-direction: column;
  width: min(420px, calc(100vw - 104px));
  max-width: var(--drawer-inline-space, none);
  max-height: var(--drawer-max-height, calc(100dvh - var(--editor-top, 120px) - 24px));
  height: min(640px, var(--drawer-max-height, calc(100dvh - var(--editor-top, 120px) - 24px)));
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(120deg, var(--surface-translucent), var(--chrome-translucent));
  box-shadow: 0 18px 60px var(--shadow-medium), inset 0 1px 0 var(--accent-soft-wash);
  backdrop-filter: blur(24px);
  container-type: inline-size;
  color: var(--text);
}
.editor-drawer[hidden], .editor-icon-rail__tab[hidden], .editor-drawer [hidden] { display: none !important; }
.editor-drawer .visual-tools__header { align-items: start; padding: 26px 24px 20px 28px; gap: 12px; border: 0; }
.editor-drawer__heading { flex: 1; min-width: 0; }
.editor-drawer__heading h2 { margin: 0; font: 600 22px/1.25 var(--sans); color: var(--text-strong); }
.editor-drawer__heading p { margin: 8px 0 0; font: 13px/1.5 var(--sans); color: var(--muted); }
.editor-drawer .visual-tools__close { width: 28px; height: 28px; margin-top: -4px; color: var(--muted); }
.editor-drawer .visual-tools__close:hover { color: var(--text-strong); background: var(--panel-active); }
.editor-drawer .visual-tools__body { flex: 1; padding: 0 28px 24px; scrollbar-gutter: stable; }
.editor-drawer .editor-groups { display: block; padding: 0; border: 0; background: none; }
.editor-drawer .editor-control-panel { padding: 22px 0 0; border-top: 1px solid var(--line); background: transparent; }
.editor-drawer .editor-control-panel__fields { gap: 24px; }
.editor-drawer .editor-field { gap: 12px; min-height: 36px; grid-template-columns: minmax(88px, 1fr) minmax(0, 1.5fr) auto; align-items: center; }
.editor-drawer .editor-field__label { font-size: 13px; line-height: 1.4; color: var(--text); }
.editor-drawer .editor-field__output { color: var(--text); font-size: 12px; }
.editor-drawer .editor-help__button { width: 24px; height: 24px; opacity: .8; }
.editor-drawer .editor-field--range { grid-template-columns: minmax(80px, .85fr) minmax(50px, 1.5fr) minmax(50px, auto); padding: 0; }
.editor-drawer .editor-field--range .editor-field__output { grid-column: 3; grid-row: 1; padding: 7px 8px; min-width: 52px; text-align: center; border: 1px solid var(--line); border-radius: 5px; background: linear-gradient(125deg, var(--control), var(--panel)); }
.editor-drawer .editor-field--range input[type="range"] { height: 36px; }
.editor-drawer input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: linear-gradient(to right, var(--accent) var(--range-progress, 0%), var(--line-strong) var(--range-progress, 0%)); box-shadow: none; }
.editor-drawer input[type="range"]::-webkit-slider-thumb { width: 15px; height: 15px; margin-top: -5.5px; background: var(--tweakit-color-text-on-dark); border: 1px solid var(--line); box-shadow: 0 1px 4px #0003; }
.editor-drawer input[type="range"]::-moz-range-track { height: 4px; background: var(--line-strong); box-shadow: none; }
.editor-drawer input[type="range"]::-moz-range-progress { background: var(--accent); height: 4px; }
.editor-drawer input[type="range"]::-moz-range-thumb { width: 15px; height: 15px; background: var(--tweakit-color-text-on-dark); border: 1px solid var(--line); box-shadow: none; }
.editor-drawer .editor-field--segmented, .editor-drawer .editor-field--text, .editor-drawer .editor-field--textarea, .editor-drawer .editor-field--image, .editor-drawer .editor-field--url { grid-template-columns: minmax(0, 1fr); }
.editor-drawer .editor-segmented { gap: 0; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: linear-gradient(125deg, var(--control), var(--panel)); }
.editor-drawer .editor-segmented__option { min-width: 0; }
.editor-drawer .editor-segmented__option > .editor-option__copy { min-height: 36px; font-size: 12px; padding: 6px; border-color: transparent; }
.editor-drawer .editor-segmented__option input:checked + .editor-option__copy { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-wash); color: var(--text-strong); }
.editor-drawer .editor-field select, .editor-drawer .editor-field input[type="text"], .editor-drawer .editor-field input[type="url"] { min-height: 36px; font-size: 12px; }
.editor-drawer .editor-switch { justify-self: end; }
.editor-drawer .editor-switch input:checked + .editor-switch__track { background: var(--accent); }
.editor-drawer .editor-switch input:checked + .editor-switch__track::after { background: var(--text-on-action); }
.editor-drawer .editor-repeat { padding-top: 18px; }
.editor-drawer .editor-repeat__fields { gap: 20px; }
.editor-drawer .editor-dimension-value { grid-column: 3; grid-row: 1; }
.editor-drawer .editor-dimension-number { width: 60px; }
.editor-drawer .editor-field--range:has(.editor-dimension-value) .editor-field__output { padding: 0; border: 0; background: none; min-width: 0; }
.editor-drawer .editor-field--color { grid-template-columns: minmax(88px, 1fr) 36px auto; }
.editor-drawer .editor-field--color input[type="color"] { grid-column: 2; grid-row: 1; width: 36px; padding: 2px; }
.editor-drawer .editor-field--color .editor-field__output { grid-column: 3; grid-row: 1; justify-self: start; }
.editor-drawer .editor-color-row .editor-field { display: flex; }
.editor-drawer .editor-color-row input[type="color"] { width: 100%; }
.editor-drawer .visual-tools__footer { padding: 12px 20px; gap: 4px; border-top: 1px solid var(--line); }
.editor-drawer .visual-tools__footer > button { color: var(--text); font-size: 11px; }
.editor-drawer .image-collection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.editor-drawer .editor-menu-row__fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 760px) {
  body[data-visual-editor] .workbench__layout { grid-template-columns: minmax(0, 1fr) 56px; }
  body[data-visual-editor] .visual-tools { width: 56px; --rail-padding: 6px; }
  .editor-drawer { right: 56px; width: min(420px, calc(100vw - 80px)); }
  .visual-tools[data-drawer-side="right"] .editor-drawer { left: 56px; }
  .editor-icon-rail { gap: 10px; }
}
@container (max-width: 340px) {
  .editor-drawer .visual-tools__header { padding: 18px 16px 16px; }
  .editor-drawer .visual-tools__body { padding: 0 16px 18px; }
  .editor-drawer .editor-field--range { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .editor-drawer .editor-field--range .editor-field__label-group { grid-column: 1; grid-row: 1; }
  .editor-drawer .editor-field--range input[type="range"] { grid-column: 1 / -1; grid-row: 2; }
  .editor-drawer .editor-field--range .editor-field__output, .editor-drawer .editor-dimension-value { grid-column: 2; grid-row: 1; }
  .editor-drawer .editor-field--color { grid-template-columns: minmax(0, 1fr) 36px; }
  .editor-drawer .editor-field--color .editor-field__output { grid-column: 1 / -1; grid-row: 2; }
  .editor-drawer .editor-segmented { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .editor-drawer .image-collection-grid, .editor-drawer .editor-menu-row__fields { grid-template-columns: minmax(0, 1fr); }
  .editor-drawer .visual-tools__footer { padding: 8px; }
}
@container (max-width: 240px) {
  .editor-drawer .editor-preset-list { grid-template-columns: 28px minmax(0, 1fr) 28px; }
  .editor-drawer .editor-preset-list__label-group { grid-column: 1 / -1; }
  .editor-drawer .editor-field--range { grid-template-columns: minmax(0, 1fr); }
  .editor-drawer .editor-field--range :is(.editor-field__output, .editor-dimension-value) { grid-column: 1; grid-row: 2; justify-self: start; }
  .editor-drawer .editor-field--range input[type="range"] { grid-column: 1; grid-row: 3; }
}
@media (max-height: 520px) {
  .editor-icon-tools { gap: 2px; }
  .editor-icon-float { height: 24px; flex-basis: 24px; }
  .editor-icon-rail { max-height: max(48px, calc(var(--bar-height, 80dvh) - 152px - var(--rail-padding) - var(--rail-padding))); gap: 8px; }
  .editor-drawer .visual-tools__header { padding-top: 12px; padding-bottom: 12px; }
  .editor-drawer .visual-tools__body { padding-bottom: 12px; }
  .editor-drawer .visual-tools__footer { padding-block: 6px; }
}

/* A scaled Desktop preview can be shorter than usable touch controls. Compact gaps,
   not targets; let the bar extend below a very short preview without resizing it.
   Reserve Float (24), Save/Download (88), four gaps (8), one padded tab (48). */
.visual-tools[data-compact-bar] .editor-icon-tools { gap: 2px; min-height: calc(168px + var(--rail-padding) + var(--rail-padding)); }
.visual-tools[data-compact-bar] .editor-icon-float { height: 24px; min-height: 24px; flex-basis: 24px; }
.visual-tools[data-compact-bar] :is(.editor-icon-rail__tab, .editor-icon-save, .editor-icon-download) { height: 44px; min-height: 44px; flex-basis: 44px; padding: 10px; }
.visual-tools[data-compact-bar] .editor-icon-rail { gap: 2px; min-height: 48px; max-height: max(48px, calc(var(--bar-height) - 120px - var(--rail-padding) - var(--rail-padding))); }

/* Explicit Fit opens the existing editor across the browser content area. */
body[data-visual-editor][data-editor-expanded] { height: 100dvh; min-height: 0; overflow: hidden; }
body[data-editor-expanded] .global-topbar,
body[data-editor-expanded] .detail-main > :not([data-editor-workspace]),
body[data-editor-expanded] .visual-preview-metrics,
body[data-editor-expanded] [data-back-to-top] { display: none; }
body[data-visual-editor][data-editor-expanded] .workbench { position: fixed; inset: 0; z-index: 100; width: 100%; height: 100dvh; padding: 0; border-radius: 0; }
body[data-visual-editor][data-editor-expanded] .detail-preview__canvas { width: 100%; max-width: none; }
body[data-editor-expanded][data-editor-docked="true"] .editor-drawer { height: 100dvh; max-height: 100dvh; }
body[data-editor-expanded] .visual-preview-notice { position: absolute; top: 56px; left: 12px; right: 12px; z-index: 4; }
.editor-collapse-preview { position: absolute; top: 12px; left: 12px; z-index: 60; display: grid; place-items: center; width: 36px; height: 36px; padding: 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); box-shadow: var(--control-raised-shadow); cursor: pointer; }
.editor-collapse-preview[hidden] { display: none; }
.editor-collapse-preview svg { width: 20px; height: 20px; }
.editor-collapse-preview:hover { color: var(--accent); background: var(--panel-active); }
.editor-collapse-preview:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 760px) {
  body[data-editor-expanded][data-editor-docked="true"] .editor-drawer { top: 56px; height: calc(100dvh - 68px); max-height: calc(100dvh - 68px); }
}

/* Standard drawers retain source headings for their independent control sets. */
.editor-colour-section, .editor-layout-section { min-width: 0; margin: 0; padding: 0; border: 0; }
.editor-colour-section > legend, .editor-layout-section > legend { margin-bottom: 12px; }
.editor-colour-section[hidden], .editor-layout-section[hidden] { display: none; }

.preview-rotation__toggle { font: 650 14px var(--sans); }
.preview-rotation__toggle:disabled { opacity: .5; cursor: default; }
.preview-rotation__hint {
  position: absolute; right: calc(100% + 6px); transform: translateY(-50%); z-index: 1;
  width: min(205px, calc(50vw - 40px)); display: flex; align-items: start; gap: 8px; padding: 10px;
  border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: var(--panel);
  box-shadow: var(--control-raised-shadow); font: 13px/1.4 var(--sans);
}
.preview-rotation__hint::before {
  content: ''; position: absolute; right: -5px; top: calc(50% - 4px); width: 8px; height: 8px;
  transform: rotate(45deg); background: var(--panel); border-top: 1px solid var(--line); border-right: 1px solid var(--line);
}
[data-drawer-side="right"] .preview-rotation__hint { right: auto; left: calc(100% + 6px); }
[data-drawer-side="right"] .preview-rotation__hint::before { right: auto; left: -5px; transform: rotate(225deg); }
.preview-rotation__hint button { background: transparent; border: 0; color: inherit; cursor: pointer; min-width: 24px; min-height: 24px; }
.preview-rotation__surface {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2;
  width: var(--preview-displayed-width, 100%); height: var(--preview-displayed-height, 100%);
  cursor: grab; touch-action: none; user-select: none;
}
.preview-rotation__surface[data-dragging] { cursor: grabbing; }
.preview-rotation__surface:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.preview-rotation__hint[hidden], .preview-rotation__surface[hidden] { display: none; }
