/* 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; }
}
/* ADER help is a short form, not a full-screen document workspace. */
#app_view #registration_issue_modal.registration-issue-modal-backdrop {
  inset: 0;
  box-sizing: border-box !important;
  width: auto !important;
  max-width: 100vw !important;
  padding: 16px !important;
  align-items: center !important;
  justify-content: center !important;
}
#app_view #registration_issue_modal > form.registration-issue-modal {
  box-sizing: border-box !important;
  width: min(760px, 100%) !important;
  max-width: 100% !important;
  min-width: 0 !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: calc(100dvh - 32px) !important;
  padding: 24px !important;
  border-radius: 12px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  overscroll-behavior: contain;
  align-content: start;
}
#app_view #registration_issue_modal .registration-issue-modal :is(label, input, select, textarea) {
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
}
#app_view #registration_issue_modal .registration-issue-modal > header > div { min-width: 0; }
#app_view #registration_issue_modal .registration-issue-modal > header > button { flex-shrink: 0; }
#app_view #registration_issue_modal .registration-issue-modal :is(p, h2) { overflow-wrap: anywhere; }
@media (max-width: 600px) {
  #app_view #registration_issue_modal.registration-issue-modal-backdrop { padding: 12px !important; }
  #app_view #registration_issue_modal > form.registration-issue-modal {
    padding: 16px !important;
    max-height: calc(100dvh - 24px) !important;
  }
}

/* Guided creation of commercial documents in the Bureau numérique. */
#app_view [data-document-guide-step="1"] [data-document-guide-panel]:not([data-document-guide-panel="1"]),
#app_view [data-document-guide-step="2"] [data-document-guide-panel]:not([data-document-guide-panel="2"]),
#app_view [data-document-guide-step="3"] [data-document-guide-panel]:not([data-document-guide-panel="3"]) {
  display: none !important;
}
#app_view .facturier-document-guide-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 8px 16px;
  list-style: none;
  background: #f6f9fa;
  flex-shrink: 0;
}
#app_view .facturier-document-guide-steps li {
  padding: 5px 10px;
  border-radius: 18px;
  font-size: .85rem;
  color: #254b5c;
}
#app_view .facturier-document-guide-steps [aria-current="step"] {
  background: #174352;
  color: white;
  font-weight: 650;
}
#app_view .facturier-document-guide-summary {
  grid-column: 1 / -1;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Keep guided document controls and batch review clear of their separators. */
#app_view .bn-classic-batch-actions {
  margin-inline: clamp(12px, 2vw, 24px);
}
#app_view .facturier-document-sort > span {
  margin-inline-start: .25em;
}
.bn-cycle-dialog .bn-cycle-row + h3 {
  margin: 14px 0 5px;
}
.bn-cycle-dialog .bn-cycle-row {
  overflow-wrap: anywhere;
}
#app_view [data-document-guide-step] [data-facturier-quick-item="document"] {
  padding-inline: .7rem !important;
}
@media (min-width: 901px) {
  #app_view [data-document-guide-step] .facturier-document-compose-lines th:first-child {
    width: 19%;
  }
  #app_view [data-document-guide-step] .facturier-document-compose-lines th:nth-child(2) {
    width: 22%;
  }
  #app_view [data-document-guide-step] .facturier-document-compose-lines th:nth-child(7) {
    width: 13%;
  }
}
@media (max-width: 760px) {
  #app_view .facturier-invoice-compose-modal[data-document-guide-step="2"] .facturier-invoice-compose-footer [data-facturier-document-step="1"] {
    grid-column: 1 / -1;
  }
  #app_view .facturier-invoice-compose-modal[data-document-guide-step] .facturier-invoice-compose-table tbody td:is([data-label="PU HT"], [data-label="TVA"]) {
    grid-column: 1 / -1 !important;
  }
  #app_view .facturier-invoice-compose-modal[data-document-guide-step="3"] .facturier-invoice-compose-footer [data-facturier-save-entity-form] {
    grid-column: 1 / -1;
  }
  #app_view [data-document-guide-step="3"] .facturier-document-compose-review .facturier-invoice-compose-totals {
    grid-row: 2;
  }
}
