/*
 * Universal modal header behavior.
 * Keep every modal title and its close control visible while the dialog body scrolls.
 */
:where(
  .worklog-dialog,
  .portal-dialog,
  .panel-modal,
  .inspection-history-modal,
  [role="dialog"],
  .modal,
  .popup
) {
  box-sizing: border-box;
  max-height: calc(100dvh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
}

:where(
  .modal-header,
  [class*="modal"] > .header,
  [class*="modal"] > header,
  .popup-header,
  .dialog-head,
  .portal-dialog-head,
  .panel-modal > header,
  .inspection-history-modal > header
) {
  position: sticky !important;
  top: 0;
  z-index: 1000 !important;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  margin-top: 0;
  padding: 12px 16px !important;
  border-bottom: 1px solid #e2e8f0 !important;
  background: #fff !important;
  box-shadow: 0 2px 4px rgb(0 0 0 / 5%);
}

:where(
  .modal-header,
  [class*="modal"] > .header,
  [class*="modal"] > header,
  .popup-header,
  .dialog-head,
  .portal-dialog-head,
  .panel-modal > header,
  .inspection-history-modal > header
) > :where(
  button[data-close],
  button[data-close-panel-modal],
  button[data-close-panel-import],
  button[data-close-inspection-modal],
  .modal-close-btn,
  .close-btn,
  [data-dismiss="modal"]
) {
  position: relative;
  z-index: 1001;
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 8px;
  border: 0;
  border-radius: 50%;
  background: #f1f5f9;
  color: #475569;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transition: background-color .2s ease, color .2s ease;
}

.modal-close-btn,
.close-btn,
[data-dismiss="modal"] {
  min-width: 40px;
  min-height: 40px;
  padding: 8px;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

:where(
  .modal-header,
  [class*="modal"] > .header,
  [class*="modal"] > header,
  .popup-header,
  .dialog-head,
  .portal-dialog-head,
  .panel-modal > header,
  .inspection-history-modal > header
) > :where(
  button[data-close],
  button[data-close-panel-modal],
  button[data-close-panel-import],
  button[data-close-inspection-modal],
  .modal-close-btn,
  .close-btn,
  [data-dismiss="modal"]
):hover {
  background: #e2e8f0;
}

:where(
  .modal-header,
  [class*="modal"] > .header,
  [class*="modal"] > header,
  .popup-header,
  .dialog-head,
  .portal-dialog-head,
  .panel-modal > header,
  .inspection-history-modal > header
) > :where(
  button[data-close],
  button[data-close-panel-modal],
  button[data-close-panel-import],
  button[data-close-inspection-modal],
  .modal-close-btn,
  .close-btn,
  [data-dismiss="modal"]
):active {
  background: #cbd5e1;
}

@media (max-width: 720px) {
  :where(
    .worklog-dialog,
    .portal-dialog,
    .panel-modal,
    .inspection-history-modal,
    [role="dialog"],
    .modal,
    .popup
  ) {
    max-height: calc(100dvh - 16px);
  }

  :where(
    .modal-header,
    [class*="modal"] > .header,
    [class*="modal"] > header,
    .popup-header,
    .dialog-head,
    .portal-dialog-head,
    .panel-modal > header,
    .inspection-history-modal > header
  ) > :where(
    button[data-close],
    button[data-close-panel-modal],
    button[data-close-panel-import],
    button[data-close-inspection-modal],
    .modal-close-btn,
    .close-btn,
    [data-dismiss="modal"]
  ) {
    flex-basis: 48px;
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
  }
}
