/* App dialogs open at the right edge. Brief decisions and anchored popovers keep their own layout. */
:root[data-theme] dialog:where(:not(.ask-dialog):not(.editor-workspace):not([data-dialog-layout=confirm])) {
  --dialog-padding: 24px;
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: min(var(--dialog-width,var(--editor-dock-width,540px)),100vw);
  min-width: 0;
  max-width: 100vw;
  height: 100dvh;
  min-height: 0;
  max-height: 100dvh;
  padding: 0 var(--dialog-padding) max(var(--dialog-padding),env(safe-area-inset-bottom));
  border: 0;
  border-left: 1px solid var(--line);
  border-radius:0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: -12px 0 40px #10272418;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 88px 24px;
}
:root[data-theme] dialog.stats-items-dialog { --dialog-width: 1000px; }

/* Direct-content dialogs scroll below a pinned, consistently sized header. */
:root[data-theme] dialog:where(:not(.ask-dialog):not(.editor-workspace)) > :is(header,.p-dialog-head) {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  flex: none;
  gap: 12px;
  margin: 0 calc(-1 * var(--dialog-padding,24px)) 20px;
  padding: 20px var(--dialog-padding,24px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
:root[data-theme] dialog:where(:not(.ask-dialog):not(.editor-workspace)) :is(.p-dialog-head,.pl-dialog-head,.co-dialog-header,.mail-context-head,.editor-head) h2,
:root[data-theme] dialog.co-dialog > header h2 {
  min-width: 0;
  margin: 0;
  font: 700 22px/1.3 var(--font-heading);
  letter-spacing: -.3px;
  overflow-wrap: anywhere;
}
:root[data-theme] dialog:where(:not(.ask-dialog)) > :is(header,.p-dialog-head) > h2 { flex: 1; }
:root[data-theme] dialog > :is(header,.p-dialog-head) > :is(.icon-btn,.btn),
:root[data-theme] .people-editor .editor-head > .icon-btn { flex: none; min-width: 40px; min-height: 40px; margin: 0 0 0 auto; }
:root[data-theme] dialog > :is(header,.p-dialog-head) > .btn { font-size: 13px; }
:root[data-theme] dialog :is(.pl-dialog-head,.mail-context-head) { align-items: flex-start; }

/* These forms already have dedicated scroll containers and fixed action areas. */
:root[data-theme] dialog:is(.pl-dialog,.people-editor,.mail-context-drawer) {
  padding: 0;
  overflow: hidden;
}
:root[data-theme] dialog:is(.pl-dialog,.mail-context-drawer) > header { margin: 0; }
:root[data-theme] .pl-dialog-body { flex: 1; min-height: 0; padding: 24px; overscroll-behavior: contain; }
:root[data-theme] .pl-dialog-footer { flex: none; padding: 16px 24px max(16px,env(safe-area-inset-bottom)); }
:root[data-theme] .pl-dialog [data-pl-error]:not(:empty) { flex: none; max-height: 30dvh; overflow: auto; }
:root[data-theme] .people-editor .editor-head { flex: none; padding: 20px 24px; border-bottom: 1px solid var(--line); }
:root[data-theme] .people-editor .editor-head p { margin: 6px 0 0; font-size: 13px; }
:root[data-theme] .people-editor .editor-body { padding: 24px; }
:root[data-theme] .people-editor .editor-scroll { overscroll-behavior: contain; }
:root[data-theme] .people-editor .editor-foot { flex: none; padding: 16px 24px max(16px,env(safe-area-inset-bottom)); }

/* The generic item form also covers milestones, which do not use the expandable editor. */
:root[data-theme] #editor:not(.editor-workspace) { width: min(var(--editor-dock-width,540px),100vw); padding: 0; overflow: hidden; }
#editor:not(.editor-workspace) > form { display: flex; flex-direction: column; height: 100%; min-height: 0; margin: 0; }
#editor:not(.editor-workspace) .editor-head,
#editor:not(.editor-workspace) .editor-foot { flex: none; }
#editor:not(.editor-workspace) .editor-body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }

/* Keep confirmation prompts centred and short; detailed planning reviews use the drawer. */
:root[data-theme] dialog.pl-dialog[data-dialog-layout=confirm] {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(480px,calc(100vw - 32px));
  height: fit-content;
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius:var(--radius-dialog,12px);
  box-shadow: var(--theme-dialog-shadow);
}
:root[data-theme] .ask-form > h2 { font-size: 20px; }
:root :is(#editor,#entry-editor).editor-workspace:not([data-editor-mode=page]) .editor-head h2 { font: 700 22px/1.3 var(--font-heading); letter-spacing: -.3px; }
html:has(dialog[open]:not(.editor-workspace)) { overflow: hidden; }

@media(max-width:700px) {
  :root[data-theme] dialog:where(:not(.ask-dialog):not(.editor-workspace):not([data-dialog-layout=confirm])),
  :root[data-theme] #editor:not(.editor-workspace) { --dialog-padding: 18px; width: 100vw; border-left: 0; }
  :root[data-theme] dialog:where(:not(.ask-dialog):not(.editor-workspace)) :is(.p-dialog-head,.pl-dialog-head,.co-dialog-header,.mail-context-head,.editor-head) h2,
  :root[data-theme] dialog.co-dialog > header h2,
  :root :is(#editor,#entry-editor).editor-workspace:not([data-editor-mode=page]) .editor-head h2 { font-size: 20px; }
  :root[data-theme] .pl-dialog-body,
  :root[data-theme] .people-editor .editor-body { padding: 18px; }
  :root[data-theme] .people-editor .editor-head { padding: 18px; }
  :root[data-theme] :is(.pl-dialog-footer,.people-editor .editor-foot) { padding-inline: 18px; }
}
