/* Keep both the edit toolbar and page navigation outside the binder frame,
   including when both side panels are closed or the toolbar wraps on phones. */
html body.binder-edit-mode #spread:not(.cover-mode) {
  --bulk-page-ratio: calc(var(--binder-cols,3) * .72 / var(--binder-rows,3));
  max-width: min(100%,calc((100cqh - var(--bulk-stage-reserve,200px)) * var(--bulk-page-ratio) * 1.9),1180px) !important;
  max-height: calc(100cqh - var(--bulk-stage-reserve,200px)) !important;
  flex: 0 0 auto !important;
}

@media (max-width: 700px) {
  html body.binder-edit-mode #spread:not(.cover-mode) {
    --bulk-stage-reserve: 260px;
    max-width: min(100%,calc((100cqh - var(--bulk-stage-reserve)) * var(--bulk-page-ratio) * .95)) !important;
  }
  html body.binder-edit-mode #spread.has-inside-cover > .page-wrap:first-child { min-height: 0 !important; }
  html body.binder-edit-mode .inside-cover-container { min-height: 0 !important; }
  html body.binder-edit-mode .bulk-edit-actions .compact { min-height: 40px; }
}

/* Classic uses the normal binder dimensions. The toolbar shares the existing
   navigation space; only the binder's position can move slightly to fit it. */
.bulk-actions-toggle { display: none; }
html body.site.binder-edit-mode .binder-stage {
  justify-content: center !important;
  padding-top: 6px !important;
}
html body.site.binder-edit-mode .binder-stage #spread:not(.cover-mode):not(.locked-single-page) {
  max-width: min(100%,calc((100cqh - 20px) * 1.45),1600px) !important;
  max-height: none !important;
  top: var(--bulk-binder-offset,0px);
}
html body.site .binder-stage > #bulkEditBar {
  position: absolute;
  bottom: calc(var(--page-nav-height,48px) + var(--bulk-nav-bottom,12px) + 2px);
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 20px),860px);
  min-height: 44px;
  box-sizing: border-box;
  margin: 0;
  padding: 1px 6px;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  z-index: 21;
  animation: none;
}
html body.site #bulkEditBar .bulk-selection-tools { gap: 6px; }
html body.site #bulkEditBar .bulk-selection-summary {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 0;
  line-height: 1.2;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
html body.site #bulkEditBar .bulk-selection-count { font-weight: 600; }
html body.site #bulkEditBar .bulk-selection-value { color: var(--text); }
html body.site #bulkEditBar .bulk-selection-meta { color: var(--muted); }
html body.site #bulkEditBar .bulk-select-short { display: none; }
html body.site #bulkEditBar .bulk-edit-actions {
  width: auto;
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
}
html body.site #bulkEditBar .compact {
  min-height: 40px;
  padding: 6px 8px;
  font-size: 11px;
  white-space: nowrap;
}
html body.site #bulkEditBar .bulk-actions-toggle { display: none; }

/* Compact stages keep the same one-row toolbar and expose the existing action
   buttons in a temporary menu, rather than taking space from the cards. */
@container (max-width: 900px) {
  html body.site #bulkEditBar .bulk-actions-toggle { display: inline-flex; }
  html body.site #bulkEditBar .bulk-edit-actions {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    width: min(240px,100%);
    max-height: calc(100cqh - 30px);
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow);
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
  }
  html body.site #bulkEditBar.actions-open .bulk-edit-actions { display: flex; }
  html body.site #bulkEditBar .bulk-edit-actions .compact {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
  }
}
@media (max-width: 700px) {
  .binder-stage { --bulk-nav-bottom: max(10px,env(safe-area-inset-bottom)); }
  html body.site.binder-edit-mode .binder-stage #spread:not(.cover-mode):not(.locked-single-page) {
    max-width: min(100%,calc((100cqh - 20px) * .72)) !important;
  }
  html body.site #bulkEditBar .bulk-selection-count { font-size: 11px; }
  html body.site #bulkEditBar .bulk-select-full { display: none; }
  html body.site #bulkEditBar .bulk-select-short { display: inline; }
  html body.site #bulkEditBar #bulkSelectAllBtn { min-width: 40px; }
}

/* Landscape phones inherit an old tablet minimum of 600px. On very short
   screens the normal and edit views both need to fit the navigation and bar. */
@media (max-height: 500px) {
  .binder-stage #spread:not(.cover-mode) { min-width: 0 !important; }
  .binder-stage:not(:has(#spread.cover-mode)):not(:has(.public-profile-panel:not(.hidden))) {
    padding-bottom: calc(var(--page-nav-height,48px) + 72px) !important;
  }
}
