/* Local RisuBard mobile Grimoire layout fix. Desktop layout is unchanged.
   The role selector keeps this stronger than lazily loaded Svelte scoped CSS. */
@media (max-width: 900px) {
  .bard-analysis-dialog[role="dialog"] {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .bard-analysis-dialog[role="dialog"] > .risu-modal-header {
    flex: 0 0 auto;
    min-width: 0;
  }
  /* The dialog owns scrolling. Do not shrink/clip the single-column body. */
  .bard-analysis-dialog[role="dialog"] > .bard-analysis-body {
    flex: 0 0 auto;
    overflow: visible;
    min-width: 0;
    min-height: 0;
  }
  .bard-analysis-dialog[role="dialog"] .bard-analysis-body > * { flex-shrink: 0; }
  .bard-analysis-dialog[role="dialog"] .analysis-workbench {
    flex: none;
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    overflow: visible;
    align-items: start;
  }
  .bard-analysis-dialog[role="dialog"] .settings-pane {
    grid-template-rows: auto auto;
    overflow: visible;
  }
  .bard-analysis-dialog[role="dialog"] .analysis-settings,
  .bard-analysis-dialog[role="dialog"] .planning-layout,
  .bard-analysis-dialog[role="dialog"] .run-layout {
    min-width: 0;
    overflow: visible;
  }
  .bard-analysis-dialog[role="dialog"] .analysis-header-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .bard-analysis-dialog[role="dialog"] .analysis-header-actions button {
    max-width: 100%;
    white-space: normal;
  }
  .bard-analysis-dialog[role="dialog"] .analysis-dialog-title { flex-wrap: wrap; }
  .bard-analysis-dialog[role="dialog"] .settings-grid label,
  .bard-analysis-dialog[role="dialog"] .settings-grid input { min-width: 0; }
  .bard-analysis-dialog[role="dialog"] .target-preview {
    height: min(60dvh, 32rem);
    min-height: 20rem;
  }
}
@media (max-width: 700px) {
  .bard-analysis-dialog[role="dialog"] .analysis-header-actions button span { display: inline; }
  .bard-analysis-dialog[role="dialog"] .target-controls label { min-width: 0; flex: 1 1 100%; }
  .bard-analysis-dialog[role="dialog"] .target-columns,
  .bard-analysis-dialog[role="dialog"] .target-grid {
    grid-template-columns: 2rem minmax(0, 1fr) 3.25rem 3.25rem;
    gap: .25rem;
  }
}

/* The analysis dialog blocks background input via body{pointer-events:none}.
   Keep only registered plugin controls and the v3 sandbox reachable above it.
   Never lift them over an active application confirmation dialog. */
body:has(.bard-analysis-dialog[role="dialog"][data-state="open"]):not(:has([role="alertdialog"][data-state="open"], dialog.risu-modal-overlay[open])) [data-chat-pane]:has([data-plugin-fab]) {
  /* The chat pane's z-index:0 otherwise traps fixed plugin buttons below portals. */
  z-index: auto;
}
body:has(.bard-analysis-dialog[role="dialog"][data-state="open"]):not(:has([role="alertdialog"][data-state="open"], dialog.risu-modal-overlay[open])) [data-plugin-fab] {
  pointer-events: auto;
  z-index: 55;
}
body:has(.bard-analysis-dialog[role="dialog"][data-state="open"]):not(:has([role="alertdialog"][data-state="open"], dialog.risu-modal-overlay[open])) > iframe[srcdoc][sandbox~="allow-scripts"][sandbox~="allow-modals"][sandbox~="allow-downloads"][allow="screen-wake-lock"] {
  pointer-events: auto;
}
body:has(.bard-analysis-dialog[role="dialog"][data-state="open"]):not(:has([role="alertdialog"][data-state="open"], dialog.risu-modal-overlay[open])) > .kocoemon-status-toast {
  /* KoCoEMon's z-index:49 is inline. It must clear the analysis layer (50). */
  z-index: 55 !important;
  pointer-events: none;
}
/* Permission/confirmation prompts must stay above a fullscreen plugin (1000). */
body:has(.bard-analysis-dialog[role="dialog"][data-state="open"]) [data-alert-dialog-overlay][data-state="open"],
body:has(.bard-analysis-dialog[role="dialog"][data-state="open"]) [data-alert-dialog-content][data-state="open"] {
  z-index: 1100;
}
