/* Editor chrome only: no authored canvas, snapshot, preview typography,
   document dimensions, pointer handlers or drop-zone overrides. */
@media (max-width: 1279px) {
  [data-site-editor-root] {
    --editor-mobile-bar-height: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  [data-site-editor-root] [data-editor-mobile-toolbar] {
    height: var(--editor-mobile-bar-height);
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
  }

  /* Success and error messages must leave the phone's editing controls free. */
  body:has([data-site-editor-root]) [data-sonner-toaster][data-y-position="bottom"][data-x-position="right"] {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
    right: max(12px, env(safe-area-inset-right, 0px)) !important;
    left: auto !important;
    width: min(356px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))) !important;
  }

  [data-site-editor-root] [data-editor-mobile-toolbar]:has([data-editor-mobile-tools-trigger]) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  [data-site-editor-root] [data-editor-mobile-toolbar] > button {
    min-height: 44px;
    font-size: 12px;
    line-height: 1.2;
    touch-action: manipulation;
  }

  [data-site-editor-root] .editor-mobile-tools-trigger {
    display: flex;
    height: 100%;
    min-height: 44px;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 0 4px;
    border-radius: 6px;
    color: var(--editor-experience-muted, #496479);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    touch-action: manipulation;
  }

  [data-site-editor-root] .editor-mobile-tools-trigger > svg {
    width: 18px;
    height: 18px;
  }

  [data-site-editor-root] [data-editor-mobile-toolbar] button:focus-visible {
    outline: 2px solid var(--editor-experience-accent, #0284c7);
    outline-offset: -3px;
  }

  [data-site-editor-root] :is([data-editor-blocks-panel], [data-editor-inspector-panel]),
  [data-site-editor-root] button[aria-label="Close editor panel"] {
    bottom: var(--editor-mobile-bar-height);
  }

  [data-site-editor-root] :is([data-editor-blocks-panel], [data-editor-inspector-panel]) {
    min-height: 0;
    max-height: calc(100dvh - 57px - var(--editor-mobile-bar-height));
  }

  [data-site-editor-root] [data-editor-canvas-viewport]:not([data-editor-website-preview="true"]) {
    padding-bottom: calc(var(--editor-mobile-bar-height) + 2rem);
  }

  [data-site-editor-root] :is([data-editor-inspector-scroll], [data-editor-library-scroll]) {
    min-height: 0;
    overscroll-behavior: contain;
    scroll-padding-block: 16px;
    -webkit-overflow-scrolling: touch;
  }

  [data-site-editor-root] [data-editor-blocks-panel] button[aria-label="Close Add Content"],
  [data-site-editor-root] [data-editor-inspector-panel] button[aria-label="Close Inspector"] {
    min-width: 44px;
    min-height: 44px;
    height: 44px;
    flex-shrink: 0;
  }

  [data-site-editor-root] [data-editor-main-toolbar] :is(
    [data-editor-page-picker-trigger], [data-editor-canvas-size-trigger],
    button[aria-label="Undo"], button[aria-label="Redo"],
    [data-editor-version-history-button], button[aria-label="Save Draft"],
    button[aria-label^="Publish Site"]
  ) {
    min-width: 44px;
    min-height: 44px;
    height: 44px;
    touch-action: manipulation;
  }

  [data-site-editor-root] [data-editor-main-toolbar] [data-editor-page-picker-trigger] {
    flex-shrink: 1;
  }

  [data-site-editor-root] [data-editor-website-preview-toolbar] {
    height: 56px;
    min-height: 56px;
  }

  [data-site-editor-root] [data-editor-website-preview-toolbar] :is(button, select) {
    min-width: 44px;
    min-height: 44px;
    height: 44px;
    touch-action: manipulation;
  }

  [data-site-editor-root] [data-editor-website-preview-toolbar] select {
    font-size: 16px;
  }

  [data-site-editor-root] :is([data-editor-blocks-panel], [data-editor-inspector-panel], [data-editor-shortcuts]):focus-visible {
    outline: 2px solid var(--editor-experience-accent, #0284c7);
    outline-offset: -3px;
  }

  [data-site-editor-root] [data-editor-shortcuts] {
    z-index: 95;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 81px - var(--editor-mobile-bar-height));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  [data-site-editor-root] [data-editor-shortcuts] button[aria-label="Close keyboard shortcuts"] {
    min-width: 44px;
    min-height: 44px;
  }

  /* Adjacent :not is deliberate: these are the controls, not their children.
     Explicit preview exclusions protect library artwork and authored widgets. */
  [data-site-editor-root] :is([data-editor-inspector-scroll], [data-editor-library-scroll])
    :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]), textarea, [data-slot="select-trigger"]):not(:where([data-editor-canvas] *, [data-published-site] *, [data-public-site-page] *, [data-history-snapshot] *, .template-preview-canvas *, .editor-template-preview *, [data-editor-palette-preview] *)) {
    font-size: 16px;
    line-height: 1.4;
    scroll-margin-block: 16px;
  }

  [data-site-editor-root] [data-editor-blocks-panel] input[aria-label^="Search"] {
    min-height: 44px;
  }

  [data-site-editor-root] :is([data-editor-library-tabs], [data-editor-inspector-tabs]) > [role="tab"] {
    min-height: 44px;
    font-size: 12px;
  }

  [data-editor-actions-menu], [data-editor-selection-setting-popover], [data-editor-element-quick-popover] {
    max-width: calc(100vw - 24px);
    max-height: min(var(--radix-dropdown-menu-content-available-height, 80dvh), calc(100dvh - 24px));
    overscroll-behavior: contain;
    scroll-padding-block: 8px;
  }

  [data-editor-actions-menu] [data-editor-menu-action] {
    min-height: 44px;
    padding-block: 10px;
    font-size: 12px;
    line-height: 1.4;
  }

  :is([data-editor-media-dialog], [data-editor-library-placement-dialog],
    [data-editor-block-picker], [data-editor-confirmation], [data-editor-structure-studio],
    [data-editor-element-conversion-picker], [data-editor-publish-review]) {
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  [data-editor-confirmation] {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  :is([data-editor-confirmation], [data-editor-publish-review]) button {
    min-height: 44px;
  }
}

@media (max-width: 767px) {
  [data-site-editor-root] [data-editor-canvas-size-trigger] [data-editor-compact-scope],
  [data-site-editor-root] [data-editor-canvas-size-trigger] > svg:last-child,
  [data-site-editor-root] [data-editor-main-toolbar] button[aria-label="Save Draft"] > span,
  [data-site-editor-root] [data-editor-main-toolbar] button[aria-label^="Publish Site"] > span {
    display: none;
  }

  [data-site-editor-root] [data-editor-canvas-size-trigger] {
    gap: 4px;
    padding-inline: 7px;
  }

  /* Give settings their own row rather than clipping them between identity and
     Actions. The existing adaptive fitter and Inspector remain their owners. */
  [data-site-editor-root] [data-editor-toolbar-dock]
    [data-editor-canvas-toolbar][data-editor-toolbar-placement="docked"]:has(> [data-editor-toolbar-identity]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
  }

  [data-site-editor-root] [data-editor-toolbar-dock] [data-editor-toolbar-identity] {
    grid-column: 1;
    grid-row: 1;
    max-width: none;
    min-width: 0;
  }

  [data-site-editor-root] [data-editor-toolbar-dock] [data-editor-toolbar-identity] [data-editor-selection-name] {
    min-width: 0;
    font-size: 12px;
  }

  [data-site-editor-root] [data-editor-toolbar-dock] [data-editor-toolbar-tools] {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    padding: 4px 8px;
    border-top: 1px solid var(--border);
  }

  [data-site-editor-root] [data-editor-toolbar-dock] [data-editor-toolbar-tools]:empty {
    display: none;
  }

  [data-site-editor-root] [data-editor-toolbar-dock] [data-editor-canvas-toolbar] > [data-editor-actions-trigger] {
    grid-column: 2;
    grid-row: 1;
    min-width: 68px;
    min-height: 44px;
    font-size: 12px;
  }

  [data-site-editor-root] [data-editor-toolbar-dock] :is(
    [data-editor-element-quick-control], [data-editor-element-quick-settings],
    [data-editor-selection-setting], [data-editor-canvas-toolbar-action]
  ) {
    min-height: 44px;
    font-size: 12px;
  }
}

[data-editor-mobile-tools-menu] {
  --editor-mobile-menu-ink: #173348;
  --editor-mobile-menu-muted: #526c7d;
  --editor-mobile-menu-surface: #ffffff;
  --editor-mobile-menu-line: #d4e1e9;
  --editor-mobile-menu-highlight: #e4f4fc;
  z-index: 270;
  width: 18rem;
  max-width: calc(100vw - 24px);
  max-height: min(var(--radix-dropdown-menu-content-available-height, 80dvh), calc(100dvh - 24px - env(safe-area-inset-bottom, 0px)));
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 8px;
  padding: 6px;
  border-color: var(--editor-mobile-menu-line);
  border-radius: 12px;
  background: var(--editor-mobile-menu-surface);
  color: var(--editor-mobile-menu-ink);
}

[data-editor-mobile-tools-menu].dark {
  --editor-mobile-menu-ink: #edf8ff;
  --editor-mobile-menu-muted: #a9c1d3;
  --editor-mobile-menu-surface: #0c1b2a;
  --editor-mobile-menu-line: #2b465b;
  --editor-mobile-menu-highlight: #173950;
}

[data-editor-mobile-tools-menu] [data-slot="dropdown-menu-label"] {
  padding: 8px 10px;
  color: var(--editor-mobile-menu-muted);
  font-size: 12px;
}

[data-editor-mobile-tools-menu] [data-editor-mobile-command] {
  min-height: 44px;
  padding: 10px;
  color: var(--editor-mobile-menu-ink);
  font-size: 14px;
  line-height: 1.35;
}

[data-editor-mobile-tools-menu] [data-editor-mobile-command][data-highlighted] {
  background: var(--editor-mobile-menu-highlight);
  color: var(--editor-mobile-menu-ink);
}

[data-editor-mobile-tools-menu] [data-editor-mobile-command][data-disabled] {
  opacity: 0.5;
}

[data-editor-mobile-tools-menu] .editor-mobile-tools-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

[data-editor-mobile-tools-menu] .editor-mobile-tools-note {
  color: var(--editor-mobile-menu-muted);
  font-size: 12px;
  line-height: 1.4;
}

@media (prefers-reduced-motion: reduce) {
  [data-editor-mobile-tools-menu] {
    animation: none;
    transition: none;
  }
}

@media (forced-colors: active) {
  [data-editor-mobile-tools-menu] {
    border-color: ButtonText;
    background: Canvas;
    color: CanvasText;
  }

  [data-editor-mobile-tools-menu] [data-editor-mobile-command] {
    color: CanvasText;
  }

  [data-editor-mobile-tools-menu] [data-editor-mobile-command][data-highlighted] {
    background: Highlight;
    color: HighlightText;
  }
}
