/* Shared workspace popup dimensions and scrolling. Authentication dialogs keep their own layout. */
:root { --bn-popup-inset: 12px; --bn-popup-radius: 16px; }
/* Commercial document comfort: keep the document central on desktop. */
#app_view .facturier-pdf-viewer-toolbar { flex-wrap: wrap; }
#app_view .facturier-pdf-viewer-toolbar [aria-pressed="true"] { background: #eaf3df; border-color: #79a821; }
#app_view .facturier-review-details > summary { cursor: pointer; padding: 14px; font-weight: 700; }

/* Keep the sticky invoice preview within the summary row, above the full-width details. */
#app_view .facturier-invoice-review-main {
  display: grid;
  gap: inherit;
  grid-column: 1 / -1;
  grid-template-columns: inherit;
  min-width: 0;
  align-items: start;
}
@media (min-width: 901px) {
  #app_view .facturier-modal:not(.pa-bulk-progress-modal):not(.facturier-access-request-modal) {
    width: calc(100vw - 24px) !important; max-width: none !important;
    height: calc(100dvh - 24px) !important; max-height: calc(100dvh - 24px) !important;
    display: flex; flex-direction: column;
  }
  #app_view :is(.facturier-modal-head, .facturier-invoice-compose-head, .facturier-modal-footer, .facturier-invoice-compose-footer) { flex-shrink: 0; min-height: 0; padding: 12px 18px; }
  #app_view .facturier-modal:not(.pa-bulk-progress-modal):not(.facturier-access-request-modal) > .facturier-modal-body {
    flex: 1; height: auto; max-height: none; min-height: 0; overflow: auto; display: block; padding: 12px; container-type: size;
  }
  #app_view :is(.facturier-invoice-compose-body) { flex: 1; min-height: 0; max-height: none; overflow: auto; }
  #app_view :is(.facturier-document-review, .facturier-invoice-review) {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); grid-template-rows: auto; height: auto; align-items: start;
  }
  #app_view :is(.facturier-invoice-preview-panel, .facturier-document-preview-panel) {
    position: sticky; top: 0; height: calc(100cqh - 24px); min-height: 0; max-height: none; grid-template-rows: auto minmax(0, 1fr);
  }
  #app_view :is(.facturier-invoice-preview-frame, .facturier-document-preview-frame) { min-height: 0; }
  #app_view :is(.facturier-invoice-side-panel, .facturier-document-side-panel) { min-height: 0; max-height: none; overflow: visible; padding: 10px; gap: 8px; }
  #app_view .facturier-detail-actions { position: sticky; top: 0; z-index: 2; background: white; padding: 8px 0; }
  #app_view :is(.facturier-invoice-compose, .facturier-document-compose) { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  #app_view :is(.facturier-invoice-compose-lines, .facturier-document-compose-lines, .facturier-invoice-compose-review, .facturier-document-compose-review) { grid-column: 1 / -1; position: static; }
  #app_view :is(.facturier-invoice-compose-review, .facturier-document-compose-review) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #app_view .facturier-invoice-compose-table th:nth-child(3) { width: 110px; }
  #app_view [data-line-field="qty"] { min-width: 0; width: 100%; box-sizing: border-box; }
  #app_view .facturier-document-creation-flow { display: flex; flex-wrap: wrap; gap: 8px; }
  #app_view .facturier-document-creation-flow > * { flex: 1 1 160px; }
}

#app_view :is(.facturier-invoice-preview-frame, .facturier-document-preview-frame) > .facturier-pdf-document {
  height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden;
}
#app_view :is(.facturier-invoice-preview-frame, .facturier-document-preview-frame) .facturier-clean-pdf-viewer { height: auto; min-height: 0; }
#app_view .facturier-pdf-canvas-wrap { box-sizing: border-box; }

/* Follow-up views and standalone PDF windows share the document workspace. */
#app_view :is(.pa-tracking-detail-preview, .facturier-pdf-preview) > .facturier-pdf-document {
  height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden;
}
#app_view :is(.pa-tracking-detail-preview, .facturier-pdf-preview) .facturier-clean-pdf-viewer { height: auto; min-height: 0; }
@media (min-width: 901px) {
  #app_view .facturier-modal-backdrop { padding: 12px; }
  #app_view .pa-tracking-detail-grid {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); align-items: start;
  }
  #app_view .pa-tracking-detail-preview {
    position: sticky; top: 0; height: calc(100cqh - 24px); min-height: 0;
    display: grid; grid-template-rows: auto minmax(0, 1fr);
  }
  #app_view .pa-tracking-detail-side { min-width: 0; }
  #app_view .pa-detail-action-card { position: sticky; top: 0; z-index: 2; }
  #app_view .facturier-pdf-shell {
    flex: 1; min-height: 0; overflow: auto; container-type: size;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); grid-template-rows: auto 1fr; align-items: start;
  }
  #app_view .facturier-pdf-preview {
    grid-column: 2; grid-row: 1 / 3; position: sticky; top: 0; height: calc(100cqh - 28px); min-height: 0;
  }
  #app_view .facturier-pdf-tools { grid-column: 1; grid-row: 2; }
  #app_view .facturier-pdf-details { overflow: visible; }
}
@media (max-width: 900px) {
  #app_view .pa-tracking-detail-preview {
    height: 70dvh; min-height: 0 !important;
    display: grid; grid-template-rows: auto minmax(0, 1fr);
  }
  #app_view .facturier-pdf-modal { display: flex; flex-direction: column; height: 100dvh; }
  #app_view .facturier-pdf-shell { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
  #app_view .facturier-pdf-preview { order: -1; flex: 0 0 65dvh; width: 100%; }
  #app_view :is(.facturier-pdf-details, .facturier-pdf-tools) { width: 100%; box-sizing: border-box; }
}

/* Other business tools use the same usable surface, including body-mounted dialogs. */
@media (min-width: 901px) {
  :is(.pa-connection-modal-backdrop, .infos-article-modal-backdrop, .pa-refusal-modal-backdrop, .office-email-modal) { padding: var(--bn-popup-inset); box-sizing: border-box; }
  :is(.pa-connection-modal, .fec-modal-card, .infos-article-modal, .infos-magazine-reader-modal, .infos-deadlines-modal, .pa-refusal-modal, .office-email-dialog, .registration-issue-modal, #transmission_recovery_root > .facturier-modal) {
    width: calc(100vw - 24px) !important; max-width: none !important;
    height: calc(100dvh - 24px) !important; max-height: calc(100dvh - 24px) !important;
    box-sizing: border-box; border-radius: var(--bn-popup-radius); min-height: 0;
  }
  :is(.pa-connection-modal, .fec-modal-card, .infos-article-modal, .infos-magazine-reader-modal, .infos-deadlines-modal) { display: flex !important; flex-direction: column; overflow: hidden; }
  :is(.pa-connection-modal, .fec-modal-card, .infos-article-modal, .infos-magazine-reader-modal, .infos-deadlines-modal) > :is(header, footer, .infos-deadlines-intro) { flex-shrink: 0; }
  :is(.fec-modal-body, .infos-deadlines-body, .infos-article-frame-wrap, .infos-magazine-reader-frame-wrap), .pa-connection-modal > form {
    flex: 1; min-height: 0 !important; max-height: none !important; overflow: auto;
  }
  :is(.infos-article-frame, .infos-magazine-reader-frame) { height: 100% !important; min-height: 0 !important; }
  :is(.pa-refusal-modal, .office-email-dialog, .registration-issue-modal) { overflow-y: auto; align-content: start; }
  :is(.pa-refusal-modal, .office-email-dialog, .registration-issue-modal) > :is(header, .pa-refusal-head, .office-email-head) { position: sticky; top: 0; z-index: 2; background: white; }
  :is(.pa-refusal-actions, .office-email-actions, .registration-issue-modal > footer) { position: sticky; bottom: 0; background: white; padding-block: 12px; z-index: 2; }
}

@media (max-width: 900px) {
  :is(.pa-connection-modal-backdrop, .infos-article-modal-backdrop, .pa-refusal-modal-backdrop, .office-email-modal, .registration-issue-modal-backdrop) { padding: 0 !important; }
  :is(.pa-connection-modal, .fec-modal-card, .infos-article-modal, .infos-magazine-reader-modal, .infos-deadlines-modal, .pa-refusal-modal, .office-email-dialog, .registration-issue-modal) {
    box-sizing: border-box; width: 100vw !important; max-width: 100vw !important;
    max-height: 100dvh !important; margin: 0; border-radius: 0 !important;
  }
  .pa-connection-modal { display: flex; flex-direction: column; overflow: hidden; }
  .pa-connection-modal > header { flex-shrink: 0; }
  .pa-connection-modal > form { flex: 1; min-height: 0; overflow: auto; }
}

/* Open global navigation above business toolbars, below modal dialogs. */
@media (min-width: 761px) {
  #app_view .workspace-banner:has(.nav-menu.is-open) { z-index: 360; }
}
